Best Python code snippet using robotframework-pageobjects_python
base.py
Source:base.py
...4950 else: 51 s = Selector(path)5253 value = self.resolve_selector(s, soup_entity)5455 if value:56 entity[prop] = value5758 entities.append(entity)59 # print("-")6061# print(entities)62 return entities6364 def follow_path(self, path=[], soup=None):65# print("following path: " , path)6667 # if spaces are present in the path then split them 68 t = []69 for s in path:70 splt = s.split()71 t += splt72 path = t7374 results = [soup]75 for s in path:76 for soup in results:77 temp = []78 # soup = results.pop()7980 soup_class = soup.__class__.__name__8182 # print(soup_class)8384 selector = Selector(s)8586 if soup_class == "ResultSet":87 for result in soup:88 r = self.resolve_selector(selector, result)89 # print("r: " , r)90 if r is not None:91 r_class = r.__class__.__name__9293 if r_class == "ResultSet":94 temp += r 95 else:96 temp.append(r)97 98 #elif soup_class == "BeautifulSoup":99 elif hasattr(soup, "find") or hasattr(soup, "find_all"):100 # print("+")101 soup = self.resolve_selector(selector, soup)102103 # if soup.__class__.__name__ == "ResultSet":104 # temp += soup105 # else:106 # temp.append(soup)107 temp.append(soup)108109 # else:110 # print("?")111112 results = temp113114 return results115116 def resolve_selector(self, selector, soup):117 s = selector.s()118 # print("resolving selector: " , s)119 if selector.is_id():120 # print("ID! ", s, " - ", selector.get_id())121 i = selector.get_id()122 return soup.find(id=i)123124 if selector.is_text():125 return soup.get_text()126127 if selector.is_tag():128 tagname = selector.get_tag_name()129# print("TAG! ", s, " - ", tagname)130 if selector.is_class():
...
CartPage.py
Source:CartPage.py
...30 def get_actual_item_details(self, locator):31 """This method gets actual item details displayed on cart page for given item locator.32 Returns item name, item description, item quantity, item price"""33 act_item_name = self.selib.get_text(34 self.webutil.resolve_selector(self.selectors['text_item_name'], locator))35 act_item_desc = self.selib.get_text(36 self.webutil.resolve_selector(self.selectors['text_item_desc'], locator))37 act_item_price = self.selib.get_text(38 self.webutil.resolve_selector(self.selectors['text_item_price'], locator))39 act_item_quantity = self.selib.get_text(40 self.webutil.resolve_selector(self.selectors['text_item_quantity'], locator))41 return act_item_name, act_item_desc, act_item_price, act_item_quantity42 @webutil.log_args43 def verify_item_in_cart(self, item, quantity='1', item_displayed=True):44 """45 This method verifies if given item is displayed on cart page.46 :param item: item details dictionary47 :param quantity: quantity to verify for item on cart page48 :param item_displayed: flag to check if item should be displayed on cart. True means should be displayed49 """50 if item_displayed:51 log.info('Verifying item %s should be displayed on cart page' % item['name'])52 locator = self.webutil.resolve_selector(self.selectors['button_item_remove'], item['locator'])53 # Checking if remove button for item with given name is available if not then failing the TC54 try:55 self.selib.element_should_be_visible(locator)56 except Exception as fault:57 log.info('Error occurred during remove button visibility check. Error: %s' % str(fault))58 asserts.fail(59 'Remove button is not displayed for %s item. i.e. item is not added in Cart')60 finally:61 log.info('Remove Button for item is available, hence proceeding ahead with further verification')62 # Get actual item details and log them63 act_item_name, act_item_desc, act_item_price, act_item_quantity = self.get_actual_item_details(64 item['locator'])65 exp_item_price = '$' + str(int(quantity) * item['price'])66 log.info('Item Name: Actual: %s, Expected: %s' % (act_item_name, item['name']))67 log.info('Item Description: Actual: %s, Expected: %s' % (act_item_desc, item['description']))68 log.info('Item Price: Actual: %s, Expected: %s' % (act_item_price, exp_item_price))69 log.info('Item Quantity: Actual: %s, Expected: %s' % (act_item_quantity, quantity))70 # Verify expected and actual item details are same71 assert_flag = act_item_desc == item['description'] and act_item_price == exp_item_price \72 and act_item_name == item['name'] and act_item_quantity == quantity73 asserts.assert_true(assert_flag, 'Actual & Expected Values do not match.')74 else:75 log.info('Verifying item should not be displayed on cart page')76 locator = self.webutil.resolve_selector(self.selectors['button_item_remove'], item['locator'])77 self.selib.element_should_not_be_visible(locator)78 @webutil.log_args79 def remove_item_from_cart(self, item):80 """This method removes item from cart"""81 # Get remove button selector82 locator = self.webutil.resolve_selector(self.selectors['button_item_remove'], item['locator'])83 self.selib.click_button(locator)84 # Verify item is not displayed on cart page...
scope.py
Source:scope.py
...18def normalize_scope(scope: Scope) -> Scope:19 if scope is whole_cache:20 return whole_cache21 else:22 return set(selector for selector in resolve_selector(scope))23def resolve_selector(selector: ScopeSelector) -> Iterable[ScopeSelector]:24 if isinstance(selector, (str, tuple)):25 yield selector26 elif isinstance(selector, (27 list,28 set,29 frozenset,30 OrderedSet,31 ListWrapper,32 SetWrapper33 )):34 for selector_part in selector:35 for resolved_selector in resolve_selector(selector_part):36 yield resolved_selector37 else:38 raise TypeError(39 "Scope selectors must be strings, tuples or collections, got %r "40 "instead."41 % selector...
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!!