How to use robot_alias method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

pubmed.py

Source:pubmed.py Github

copy

Full Screen

...22 # when calling this keyword. Without the "__name__"23 # token this method would map to either "Type In Search Box",24 # or "Type In Search Box Pubmed". Using "__name__" we can call25 # "Type in Pubmed Search Box foo".26 @robot_alias("type_in__name__search_box")27 def type_in_search_box(self, txt):28 self.input_text("search input", txt)29 # We always return something from a page object, 30 # even if it's the same page object instance we are31 # currently on.32 return self33 @robot_alias("click__name__search_button")34 def click_search_button(self):35 self.click_button("search button")36 # When navigating to another type of page, return37 # the appropriate page object.38 return PubmedDocsumPage()39 @robot_alias("search__name__for")40 def search_for(self, term):41 self.type_in_search_box(term)42 return self.click_search_button()43class PubmedDocsumPage(Page):44 """Models a Pubmed search result page. For example:45 http://www.ncbi.nlm.nih.gov/pubmed?term=cat """46 uri = "/pubmed/?term={term}"47 # This is a "selector template". We are parameterizing the 48 # nth result in this xpath. We call this from click_result, below.49 selectors = {50 "nth result link": "xpath=(//div[@class='rslt'])[{n}]/p/a",51 }52 @robot_alias("click_result_on__name__")53 def click_result(self, i):54 # For selector templates, we need to resolve the selector to the55 # locator first, before finding or acting on the element.56 locator = self.resolve_selector("nth result link", n=int(i))57 self.click_link(locator)58 return PubmedArticlePage()59class PubmedArticlePage(Page):60 uri = "/pubmed/{article_id}"61 @robot_alias("__name__body_should_contain")62 def body_should_contain(self, str, ignore_case=True):63 ref_str = str.lower() if ignore_case else str64 ref_str = ref_str.encode("utf-8")65 body_txt = self.get_text("css=body").encode("utf-8").lower()66 asserts.assert_true(ref_str in body_txt, "body text does not contain %s" %ref_str)...

Full Screen

Full Screen

widget_no_uri_attr.py

Source:widget_no_uri_attr.py Github

copy

Full Screen

1import robot.utils.asserts as asserts2from robotpageobjects.page import Page, robot_alias3class SearchResultPage(Page):4 name = "Widget Search Result Page"5 @robot_alias("__name__should_have_results")6 def should_have_results(self, expected):7 len_results = len(self.find_elements("xpath=id('results')/li", required=False))8 asserts.assert_equals(len_results, int(expected), "Unexpected number of results found on %s, got %s, "9 "expected %s" %(10 self.name, len_results, expected))11 return self12class Page(Page):13 name = "Widget Page"14 @robot_alias("search__name__for")15 def search(self, term):16 self.input_text("q", "search term")17 self.click_element("go")...

Full Screen

Full Screen

widget_rel_uri_no_name_attr.py

Source:widget_rel_uri_no_name_attr.py Github

copy

Full Screen

1import robot.utils.asserts as asserts2from robotpageobjects.page import Page, robot_alias3class WidgetPage(Page):4 uri = "/site/index.html"5 @robot_alias("search__name__for")6 def search(self, term):7 self.input_text("q", "search term")8 self.click_element("go")9 return WidgetSearchResultPage()10class WidgetSearchResultPage(Page):11 @robot_alias("__name__should_have_results")12 def should_have_results(self, expected):13 len_results = len(self.find_elements("xpath=id('results')/li", required=False))14 asserts.assert_equals(len_results, int(expected), "Unexpected number of results found on %s, got %s, "15 "expected %s" %(16 self.name, len_results, expected))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-pageobjects automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful