Cleaned up locators, and switched to new pypom 2 api. (#41)

This commit is contained in:
Benjamin Forehand Jr 2018-06-27 12:27:37 -04:00 коммит произвёл GitHub
Родитель 1791c01bc0
Коммит 79523ce2f2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 41 добавлений и 22 удалений

Просмотреть файл

@ -30,7 +30,7 @@ flake8: clean ## Run flake8
.PHONY: formatting
formatting: clean ## Run python black and show diff
@pipenv run black --diff --check --line-length 80 ./
@pipenv run black --diff --check --line-length 79 ./
.PHONY: setup-redash
setup-redash: clean ## Setup redash instance

Просмотреть файл

@ -11,10 +11,18 @@ from selenium.webdriver.support import expected_conditions as expected
class HomePage(Page):
"""Page object model for home page."""
def wait_for_page_to_load(self):
_profile_username_dropdown_locator = (
By.CSS_SELECTOR,
".dropdown--profile__username",
)
_navbar_search_input_locator = (By.CLASS_NAME, "navbar__search__input")
_search_input_btn_locator = (By.CLASS_NAME, "input-group-btn .btn")
@property
def loaded(self):
self.wait.until(
lambda _: self.is_element_displayed(
By.CSS_SELECTOR, ".dropdown--profile__username"
*self._profile_username_dropdown_locator
)
)
return self
@ -29,28 +37,26 @@ class HomePage(Page):
"""Return the profile dropdown element."""
element = self.wait.until(
expected.visibility_of_element_located(
(By.CSS_SELECTOR, ".dropdown--profile__username")
self._profile_username_dropdown_locator
)
)
return element.text
def logout(self):
element = self.selenium.find_element_by_css_selector(
".dropdown .dropdown--profile__username"
def log_out(self):
element = self.selenium.find_element(
*self._profile_username_dropdown_locator
)
element.click()
logout = element.find_elements_by_tag_name("li")
logout[-1].click()
def search(self, term):
element = self.selenium.find_element_by_css_selector(
".navbar__search__input"
element = self.selenium.find_element(
*self._navbar_search_input_locator
)
element.click()
element.send_keys(term)
button = self.selenium.find_element_by_css_selector(
".input-group-btn .btn"
)
button = self.selenium.find_element(*self._search_input_btn_locator)
button.click()
from pages.queries import QueryPage

Просмотреть файл

@ -13,6 +13,11 @@ class LoginPage(Page):
URL_TEMPLATE = "/{org}/login/"
_alert_locator = (By.CSS_SELECTOR, ".alert-danger")
_input_email_locator = (By.ID, "inputEmail")
_input_password_locator = (By.ID, "inputPassword")
_login_buttton_locator = (By.CSS_SELECTOR, "button[type='submit']")
@property
def title(self):
"""Return the page title."""
@ -22,25 +27,23 @@ class LoginPage(Page):
def alert(self):
"""Return the alert element."""
element = self.wait.until(
expected.visibility_of_element_located(
(By.CSS_SELECTOR, ".alert-danger")
)
expected.visibility_of_element_located(self._alert_locator)
)
return element.text
def enter_email(self, email):
"""Enter the given user email."""
input_email = self.find_element(By.ID, "inputEmail")
input_email = self.find_element(*self._input_email_locator)
input_email.send_keys(email)
def enter_password(self, password):
"""Enter the given user password."""
input_password = self.find_element(By.ID, "inputPassword")
input_password = self.find_element(*self._input_password_locator)
input_password.send_keys(password)
def click_login(self):
"""Click the login button."""
btn = self.find_element(By.CSS_SELECTOR, "button[type='submit']")
btn = self.find_element(*self._login_buttton_locator)
btn.click()
def login(self, email="", password=""):

Просмотреть файл

@ -8,16 +8,23 @@ from selenium.webdriver.common.by import By
class QueryPage(Page):
_query_table_locator = (By.TAG_NAME, "table")
_table_row_locator = (By.TAG_NAME, "tr")
@property
def queries(self):
table = self.selenium.find_element(By.TAG_NAME, "table")
items = table.find_elements(By.TAG_NAME, "tr")
table = self.selenium.find_element(*self._query_table_locator)
items = table.find_elements(*self._table_row_locator)
return [self.QueryRow(self, item) for item in items]
class QueryRow(Region):
_query_link_locator = (By.CSS_SELECTOR, "td a")
@property
def link(self):
return self.selenium.find_element(By.CSS_SELECTOR, "td a")
return self.selenium.find_element(*self._query_link_locator)
def click(self):
self.link.click()
@ -25,6 +32,9 @@ class QueryPage(Page):
class QueryDetailPage(Page):
_query_description_locator = (By.CSS_SELECTOR, ".edit-in-place p")
@property
def description(self):
return self.find_element(By.CSS_SELECTOR, ".edit-in-place p").text
return self.find_element(*self._query_description_locator).text