class GooglePage(BasePage): URL = 'www.google.pl' def __init__(self, context): super().__init__(context) self.search_field = Element(By.ID, "lst-ib", context) self.search_suggestion = Element( By.XPATH, ".//ul[@role='listbox']/li//div[string(.)='{argument}']", context) self.sign_in = Element(By.XPATH, ".//a[@id='gb 70']", context) self.password_field = Element(By.XPATH, ".//input[@name='password']", context) self.email_field = Element(By.XPATH, "", context) self.login_next_button = Element(By.XPATH, ".//*[text()='Next']", context) self.logged_user_icon = Element(By.XPATH, ".//span[@id='gb_7a']", context) self.logged_user_email_info = Element( By.XPATH, ".//*[contains(@class,'gb_xb')]", context) def fill_search_field(self, search_phrase): self.search_field.value = search_phrase def select_search_suggestion(self, suggestion): self.search_suggestion.set_parameters(suggestion).click() def login_as(self, email, password): self.email_field.value = email self.password_field.value = password self.login_next_button.click() def is_logged_user(self, name): self.logged_user_icon.click() return self.logged_user_email_info.text == name
class AccountPage(BasePage): URL = "www.phptravels.net/account/" def __init__(self, context): super().__init__(context) self.date = Element( By.XPATH, "//span[@class='h4']", context) self.home_page_header= Element( By.XPATH, "//div[@class='header-logo go-right']//a//img", context) def is_element_found(self): assert_that(self.date.text, equal_to(date.today().strftime("%-d %B %Y"))) def press_home_page_header(self): self.home_page_header.click()
class LoginPage(BasePage): URL = 'www.phptravels.net/login' def __init__(self, context): super().__init__(context) self.username_field = Element(By.XPATH, ".//input[@name='username']", context) self.password_field = Element(By.XPATH, ".//input[@name='password']", context) self.login_button = Element(By.XPATH, "//button[@type='submit']", context) def login_as(self, username=None, password=None): self.username_field.value = DataGenerator.generate_random_string( ) if username is None else username self.password_field.value = DataGenerator.generate_random_string( ) if password is None else password self.login_button.click()
class HomePage(BasePage): URL = 'www.phptravels.net/home' def __init__(self, context): super().__init__(context) self.my_account_button = Element( By.XPATH, "/html[1]/body[1]/div[2]/header[1]/div[1]/div[1]/div[1]/div[2]/div[1]/ul[1]/li[3]/div[1]/a[1]", context) self.login_button = Element( By.XPATH, "//a[@class='dropdown-item active tr']", context) self.currency_dropdown = Dropdown( By.ID, "dropdownCurrency", context) self.currency_choice = Dropdown( By.XPATH, '//div[@class="dropdown-menu-inner"]/a[2]', context) self.flight_tab = Element( By.LINK_TEXT, "Flights", context) def go_to_login_page(self): self.my_account_button.click() self.login_button.click() def select_from_dropdown(self): self.currency_dropdown.click() self.currency_choice.click() time.sleep(5) assert_that(self.currency_dropdown.text, equal_to("GBP")) def press_flight_tab(self): self.flight_tab.click() #def enter_flight_data(self): #self.
def perform_action_on_row_with_text(self, row_text: list, action_name): action_for_row_with_text = Element( By.XPATH, self._get_selector_with_text(row_text) + "//a[contains(@href,'{}')]".format(action_name), self.context) action_for_row_with_text.click()
def select_row_with_text(self, row_text: list): row_with_text = Element(By.XPATH, self._get_selector_with_text(row_text), self.context) row_with_text.click()