Best Python code snippet using toolium_python
inner_item.py
Source:inner_item.py
1from packages.drivers import go_to_url, get_web_element2boolean_false_field_description = ("nincs","nem")3boolean_true_field_description = ("van","igen")4def parse_address(record):5 region = get_web_element("//meta[@itemprop='addressRegion']")6 record["address"] = {"region" : region.get_attribute("content").replace(" ", "") if region is not None else None}7 locality = get_web_element("//span[@itemprop='addressLocality']")8 record["address"]["locality"] = locality.text if locality is not None else None9 if record["address"]["region"] == "Budapest":10 record["address"]["region"] = "Pest"11 record["address"]["district"] = record["address"]["locality"]12 record["address"]["locality"] = "Budapest"13def parse_floor(record):14 floor = get_web_element("//div[contains(@class, 'floor')]/span[2]")15 try:16 record["floor"] = {"level": int(floor.text.replace(" ", "")) if floor is not None else None}17 except ValueError:18 record["floor"] = {"level": floor.text.replace(" ", "")}19 lift = get_web_element("//div[contains(@class, 'elevator')]/span[2]")20 lift = lift.text.replace(" ", "") if lift is not None else None21 record["floor"]["has_lift"] = lift22 if lift is not None:23 if lift.lower() in boolean_false_field_description:24 record["floor"]["has_lift"] = False 25 elif lift.lower() in boolean_true_field_description:26 record["floor"]["has_lift"] = True27def parse_category(record):28 category = get_web_element("//meta[@itemprop='category']/following-sibling::span[2]")29 record["category"] = category.text if category is not None else None30def parse_condition(record):31 condition = get_web_element("//div[contains(@class, 'realestate_condition')]/span[2]")32 record["condition"] = condition.text if condition is not None else None33def parse_material(record):34 material = get_web_element("//div[contains(@class, 'building_type')]/span[2]")35 record["material"] = material.text if material is not None else None36def parse_balcony(record):37 balcony = get_web_element("//div[contains(@class, 'balcony')]/span[2]")38 balcony = balcony.text.replace(" ", "") if balcony is not None else None39 record["has_balcony"] = balcony40 if balcony is not None:41 if balcony.lower() in boolean_false_field_description:42 record["has_balcony"] = False43 elif balcony.lower() in boolean_true_field_description:44 record["has_balcony"] = True45def parse_furniture(record):46 furniture = get_web_element("//div[contains(@class, 'has_furniture')]/span[2]")47 furniture = furniture.text.replace(" ", "") if furniture is not None else None48 record["has_furniture"] = furniture49 if furniture is not None:50 if furniture.lower() in boolean_false_field_description:51 record["has_furniture"] = False52 elif furniture.lower() in boolean_true_field_description:53 record["has_furniture"] = True54def parse_parking(record):55 parking = get_web_element("//div[contains(@class, 'parking_type')]/span[2]")56 record["parking"] = parking.text.replace(" ", "") if parking is not None else None57def parse_size(record):58 inner_height = get_web_element("//div[contains(@class, 'inner_height')]/span[2]")59 inner_height = inner_height.text if inner_height is not None else None60 rooms = get_web_element("//div[contains(@class, 'rooms')]/span[2]")61 rooms = int(rooms.text.replace("szoba", "").replace("+", "").replace(" ", "")) if rooms is not None else None62 area = get_web_element("//div[contains(@class, 'size')]/span[2]")63 area_value = int(area.text.split(" ")[0].replace(" ", "")) if area is not None else None64 area_measurement = area.text.split(" ")[1].replace(" ", "") if area is not None else None65 record["size"] = {66 "area": {67 "value": area_value,68 "measurement": area_measurement,69 },70 "inner_height": inner_height,71 "rooms": rooms72 }73def parse_additional_data(record, url):74 print(f"Parsing item at url: {url} ...")75 go_to_url(url)76 parse_address(record)...
createrecord_pom.py
Source:createrecord_pom.py
...14 sets first name15 :param firstname: string16 :return: void17 """18 self.get_web_element(createnewrecord_locator.FIRST_NAME,self.driver).clear()19 self.get_web_element(createnewrecord_locator.FIRST_NAME,self.driver). \20 send_keys(firstname)21 def set_lastname(self, lastname):22 """23 sets last name24 :param lastname:string25 :return: void26 """27 self.get_web_element(createnewrecord_locator.LAST_NAME,self.driver).clear()28 self.get_web_element(createnewrecord_locator.LAST_NAME,self.driver). \29 send_keys(lastname)30 def set_city(self, city):31 """32 sets text city33 :param city: string34 :return: void35 """36 self.get_web_element(createnewrecord_locator.CITY,self.driver).clear()37 self.get_web_element(createnewrecord_locator.CITY,self.driver). \38 send_keys(city)39 def click_savebutton(self):40 """41 clicks on save button42 :return: void43 """44 self.get_web_element(createnewrecord_locator.SAVE_BUTTON,self.driver). \45 click()46 def click_savetimespent(self):47 """48 clicks on button49 """50 self.get_web_element(createnewrecord_locator.SAVE_TIME_SPENTBUTTON,self.driver). \51 click()52 def goto_newrecord_page(self):53 """54 Navigate to new record craetion page55 :return: void56 """57 self.get_web_element(createnewrecord_locator.CREATE_NEWRECORD_BUTTON,self.driver). \58 click()59 def is_savebutton_enabled(self):60 """61 checks for existance62 :return: boolean63 """64 return self.get_web_element(createnewrecord_locator.SAVE_BUTTON,self.driver). \...
mixins.py
Source:mixins.py
1class _BaseElementMixin(object):2 def get_web_element(self):3 return getattr(self, 'web_element')4class Disableable(_BaseElementMixin):5 def is_enabled(self):6 return self.get_web_element().is_enabled()7class Clickable(_BaseElementMixin):8 def click(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!