class DisappearingElementsPage(ExamplePage): button_list = DisplayElement('div.example>ul', By.CSS_SELECTOR) buttons = DisplayElement('/li', By.XPATH, parent=button_list) def button(self, button_num): return DisplayElement('/li[{0}]'.format(button_num), By.XPATH, parent=self.button_list)
class LoginPage(ContainerElement): def __init__(self): self.email_username = InputElement('login-username', by=By.ID) self.password = InputElement('login-password', by=By.ID) self.remember_me_checkbox = CheckboxElement('login-remember', by=By.ID) self.login_btn = DisplayElement('login-button', by=By.ID) self.alert = DisplayElement('p.alert', by=By.CSS_SELECTOR) ContainerElement.__init__(self, locator='div.login', by=By.CSS_SELECTOR) def wait_for_load(self): self.email_username.exists(timeout=3) self.email_username.is_visible(timeout=1) def set_email_username(self, email_addr: str = '*****@*****.**'): self.email_username.set(email_addr) def set_password(self, pwd: str = 'foopassword'): self.password.set(pwd) def login_attempt(self, user_or_email: str = '*****@*****.**', password: str = 'fu1dfuuu', remember: bool = False): if self.remember_me_checkbox.get() is not remember: self.remember_me_checkbox.element('following-sibling::span', By.XPATH).click() self.set_email_username(user_or_email) self.set_password(password) self.login_btn.click()
class JavaScriptAlertsPage(ExamplePage): # region ---------- Page Objects Here ---------- js_alert_button = DisplayElement('//button[.="Click for JS Alert"]', By.XPATH) js_confirm_button = DisplayElement('//button[.="Click for JS Confirm"]', By.XPATH) js_prompt_button = DisplayElement('//button[.="Click for JS Prompt"]', By.XPATH) result = DisplayElement('result', By.ID)
def __init__(self): self.signup_link = DisplayElement("a[data-ga-action='sign-up']", by=By.CSS_SELECTOR) self.login_link = DisplayElement( "a[href='https://www.spotify.com/pl/account/overview/']", by=By.CSS_SELECTOR) ContainerElement.__init__(self, locator='body.page-homepage', by=By.CSS_SELECTOR)
def __init__(self): self.email_username = InputElement('login-username', by=By.ID) self.password = InputElement('login-password', by=By.ID) self.remember_me_checkbox = CheckboxElement('login-remember', by=By.ID) self.login_btn = DisplayElement('login-button', by=By.ID) self.alert = DisplayElement('p.alert', by=By.CSS_SELECTOR) ContainerElement.__init__(self, locator='div.login', by=By.CSS_SELECTOR)
class HomePage(Page): """Home page action methods come here. I.e. Python.org""" # region ---------- Page Objects Here ---------- header = DisplayElement('//div[@id="content"]/h1', By.XPATH) sub_header = DisplayElement('//div[@id="content"]/h2', By.XPATH) # endregion @staticmethod def click_link(link_text): """Triggers the search""" element = DisplayElement(link_text, By.LINK_TEXT).get_element() element.click()
class NestedFramesPage(ExamplePage): top_frame = TopFrame() left_frame = top_frame.left_frame middle_frame = top_frame.middle_frame right_frame = FrameElement('frame-right', by=By.NAME) top_frame.add_children(right_frame) bottom_frame = FrameElement('frame-bottom', by=By.NAME) left_body = DisplayElement('body', By.TAG_NAME, left_frame) middle_body = DisplayElement('//body', By.XPATH, middle_frame) right_body = DisplayElement('body', By.TAG_NAME, right_frame) bottom_body = DisplayElement('body', By.TAG_NAME, bottom_frame)
def __init__(self): self.email = InputElement('register-email', by=By.ID) self.confirm_email = InputElement('register-confirm-email', by=By.ID) self.password = InputElement('register-password', by=By.ID) '''*** Labels *** ''' self.confirm_email_label = DisplayElement( ".has-error[for='register-confirm-email']", by=By.CSS_SELECTOR) ContainerElement.__init__(self, locator='body.page-signup', by=By.CSS_SELECTOR)
class MainPage(ContainerElement): def __init__(self): self.signup_link = DisplayElement("a[data-ga-action='sign-up']", by=By.CSS_SELECTOR) self.login_link = DisplayElement( "a[href='https://www.spotify.com/pl/account/overview/']", by=By.CSS_SELECTOR) ContainerElement.__init__(self, locator='body.page-homepage', by=By.CSS_SELECTOR) def wait_for_load(self): self.signup_link.exists(timeout=3) self.signup_link.is_visible(timeout=1) def login(self): self.login_link.click() def signup(self): self.signup_link.click()
class ExamplePage(Page): header = DisplayElement('#content>div>h3', By.CSS_SELECTOR)
class BrokenImagesPage(ExamplePage): image_container = DisplayElement('div.example', By.CSS_SELECTOR) image_1 = DisplayElement('/img[1]', By.XPATH, parent=image_container) image_2 = DisplayElement('/img[2]', By.XPATH, parent=image_container) image_3 = DisplayElement('/img[3]', By.XPATH, parent=image_container)
def body_cell(self, row=1, column=1): return DisplayElement('/tbody/tr[{row}]/td[{column}]'.format(row=row, column=column), By.XPATH, self)
def body_row(self, row=1): return DisplayElement('/tbody/tr[{row}]'.format(row=row), By.XPATH, self)
def header_cell(self, row=1, column=1): return DisplayElement('/thead/tr[{row}]/th[{column}]'.format(row=row, column=column), By.XPATH, self)
def click_link(link_text): """Triggers the search""" element = DisplayElement(link_text, By.LINK_TEXT).get_element() element.click()
class DragAndDropPage(ExamplePage): column_a_box = DisplayElement('column-a', By.ID) column_b_box = DisplayElement('column-b', By.ID)
def button(self, button_num): return DisplayElement('/li[{0}]'.format(button_num), By.XPATH, parent=self.button_list)