Advertisement
Guest User

Untitled

a guest
May 14th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. class BaseLocators:
  2.     HEADER = (By.Xpath, "//div[@title='header']")
  3.  
  4.  
  5. class AuthLocators(BaseLocators):
  6.     LOGIN_BTN = (By.ID, "login")
  7.  
  8.  
  9.  
  10.  
  11. class BasePage:
  12.  
  13.     def __init__(self, driver):
  14.          self.driver = driver
  15.  
  16.     def wait(self, timeout=None):
  17.         if timeout is None:
  18.             timeout = 5
  19.         return WebDriverWait(self.driver, timeout=timeout) 
  20.  
  21.     def find(self, locator):
  22.         self.wait().until(EC.presence_of_element_located(locator))
  23.         return self.driver.find_element(*locator)
  24.  
  25.     def click(self, locator, timeout=None):
  26.         for i in range(3):
  27.             try:
  28.                 element = self.find(locator, timeout=timeout)
  29.                 element = self.wait(timeout).until(EC.element_to_be_clickable(locator))
  30.                 element.click()
  31.                 return
  32.             except StaleElementReferenceException:
  33.                 if i == CLICK_RETRY - 1:
  34.                     raise
  35.  
  36.  
  37. class AuthPage(BasePage):
  38.  
  39.     locators = AuthLocators()
  40.  
  41.  
  42.     def click_login(self):
  43.          self.click(self.locators.LOGIN_BTN)
  44.  
  45.  
  46.  
  47.  
  48.  
  49. @pytest.fixture()
  50. def auth_page(driver):
  51.      return AuthPage(driver)
  52.  
  53.  
  54. def test_login(auth_page):
  55.      auth_page.click_login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement