class SimplePage(Page): heading = Locate('h1') paragraph = Locate('p') def open(self): fixture_url = get_fixture_url('test_page_fixture.html') self._go_to_url(fixture_url)
class TableWithReplacedElementsPage(Page): table = Locate('table', webelement_class=TableWithReplacedElements) table_with_reversed_headers = Locate( 'table', webelement_class=TableWithReversedHeaders) def open(self): fixture_url = get_fixture_url('test_table_webelements.html') self._go_to_url(fixture_url)
class BookWebElement(WebElement): title = Locate('.title', webelement_class=BookFieldWebElement) author = Locate('.author', webelement_class=BookFieldWebElement) isbn = Locate('.isbn', webelement_class=BookFieldWebElement) table_of_contents_header = Locate('.table-title') chapters = LocateMany('.chapter', webelement_class=ChapterWebElement) chapters_by_title = LocateMany('.chapter', webelement_class=ChapterWebElement, key=lambda chapter: chapter.title.text) availability = Locate('.availability') bestseller = LocateGlobal('.bestseller', webelement_class=BestsellerWebElement)
class BooksPage(Page): first_book = Locate('.book', webelement_class=BookWebElement) books = LocateMany('.book', webelement_class=BookWebElement) books_by_titles = LocateMany('.book', webelement_class=BookWebElement, key=lambda book: book.title.field_value.text) books_by_titles_with_string_key = LocateMany('.book', webelement_class=BookWebElement, key='title.field_value.text') bestseller = Locate('.bestseller', webelement_class=BestsellerWebElement) non_existing_books = LocateMany('.non-existing-book') non_existing_books_by_title = LocateMany('.non-existing-book', key=lambda book: book.title.field_value.text) def open(self): fixture_url = get_fixture_url('test_web_elements_fixture.html') self._go_to_url(fixture_url)
class DiffrentLocatorsPage(Page): located_by_id = Locate('with_id', By.ID) located_by_tag_name = Locate('p', By.TAG_NAME) located_by_name = Locate('with_name', By.NAME) located_by_link_text = Locate('link text', By.LINK_TEXT) located_by_class_name = Locate('with_class_name', By.CLASS_NAME) located_by_css_selector = Locate('.with_class_name.and_second_class_name') located_by_xpath = Locate('//body/ul/*[2]', By.XPATH) def open(self): fixture_url = get_fixture_url('test_diffrent_locators.html') self._go_to_url(fixture_url)
class ExistanceAndVisibilityPage(Page): make_not_visible_button = Locate('#make-not-visible-button') make_not_displayed_button = Locate('#make-not-displayed-button') remove_button = Locate('#remove-button') to_not_be_visible_element = Locate('#to-be-not-visible') to_not_be_displayed = Locate('#to-be-not-displayed') to_be_removed = Locate('#to-be-removed') def open(self): fixture_url = get_fixture_url( 'test_web_element_existance_and_visibility_fixture.html') self._go_to_url(fixture_url)
class FutureWebElement(WebElement): title = Locate('.title') date = Locate('.date')
class BestsellerWebElement(WebElement): prompt = Locate('.prompt') title = Locate('.title') books = LocateGlobalMany('.book') future_by_title = LocateGlobalMany('.release .item', webelement_class=FutureWebElement, key=lambda future: future.title.text)
class ChapterWebElement(WebElement): title = Locate('.title') first_page = Locate('.first-page')
class BookFieldWebElement(WebElement): field_name = Locate('.field-name') field_value = Locate('.field-value')
class TablePage(Page): table = Locate('table', webelement_class=TableWebElement) def open(self): fixture_url = get_fixture_url('test_table_webelements.html') self._go_to_url(fixture_url)