-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add POM and main page tests #19
base: main
Are you sure you want to change the base?
Changes from 6 commits
7c61dee
7be1f72
2c4e6f5
a279189
c67fae0
551a75a
4b075a0
8c68421
6f535ec
61f9eb6
bbe545c
bdf3035
f2f1eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
venv | ||
venv | ||
|
||
.idea/ | ||
__pycache__/ | ||
data/__pycache__/ | ||
locators/__pycache__/ | ||
|
||
database_connection.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ disable= | |
C0116, | ||
C0115, | ||
E0401, | ||
W0621 | ||
W0621, | ||
R0903 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
MAIN_PAGE = "https://www.it-roast.com/#" | ||
LINKEDIN_PAGE = "https://www.linkedin.com/company/train-lab-interns/mycompany/" | ||
REG_PAGE = "https://www.it-roast.com/auth" | ||
GITHUB_PAGE = "https://github.com/Train-lab-intern" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from selenium.webdriver.common.by import By | ||
|
||
|
||
class MainPageLocators: | ||
LOGO = (By.CSS_SELECTOR, 'img[alt="Logo"]') | ||
LINKEDIN_LINK = (By.CSS_SELECTOR, "[alt='linkedin']") | ||
GITHUB_LINK = (By.CSS_SELECTOR, "[alt='github']") | ||
ABOUT_US_BUTTON = (By.XPATH, '//*[@id="basic-navbar-nav"]/div[1]/a[1]/button') | ||
TASKS_BUTTON = (By.XPATH, '//*[@id="basic-navbar-nav"]/div[1]/a[2]/button') | ||
REG_BUTTON = (By.CSS_SELECTOR, "[href='/auth']") | ||
TOOLTIP_O_NAS = (By.XPATH, '//*[@id="basic-navbar-nav"]/div[1]/a[1]') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver import ActionChains | ||
from selenium.webdriver.support.wait import WebDriverWait | ||
|
||
|
||
class BasePage: | ||
|
||
def __init__(self, driver, link=None): | ||
self.driver = driver | ||
self.link = link | ||
|
||
def open(self): | ||
self.driver.get(self.link) | ||
|
||
def hover_over_element(self, locator): | ||
element = self.driver.find_element(*locator) | ||
action = ActionChains(self.driver) | ||
action.move_to_element(element) | ||
action.perform() | ||
|
||
def is_element_clickable_after_hover(self, locator, timeout=5): | ||
self.hover_over_element(locator) | ||
return WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(locator)) | ||
|
||
def find_element_and_click(self, locator): | ||
self.driver.find_element(*locator).click() | ||
|
||
def assert_current_url(self, expected_url): | ||
current_url = self.driver.current_url | ||
assert current_url == expected_url, f"URL does not match. Actual page is: {current_url}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pages.base_page import BasePage | ||
from locators.main_page_locators import MainPageLocators | ||
from data.urls import MAIN_PAGE, LINKEDIN_PAGE, GITHUB_PAGE | ||
|
||
|
||
|
||
class MainPage(BasePage): | ||
|
||
def open_main_page(self): | ||
self.driver.get(MAIN_PAGE) | ||
|
||
def logo_visibility(self): | ||
logo = self.driver.find_element(*MainPageLocators.LOGO) | ||
assert logo.is_displayed() | ||
|
||
def check_linkedin_redirection(self): | ||
self.find_element_and_click(MainPageLocators.LINKEDIN_LINK) | ||
self.assert_current_url(LINKEDIN_PAGE) | ||
|
||
def check_github_redirection(self): | ||
self.find_element_and_click(MainPageLocators.GITHUB_LINK) | ||
self.assert_current_url(GITHUB_PAGE) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import pytest | ||
from pages.main_page import MainPage | ||
from locators.main_page_locators import MainPageLocators | ||
|
||
|
||
# Header tests | ||
def test_is_logo_visible(driver): | ||
page = MainPage(driver) | ||
page.open_main_page() | ||
page.logo_visibility() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Так как это проверка, лучше назвать метод |
||
|
||
|
||
def test_about_us_clickable(driver): | ||
page = MainPage(driver) | ||
page.open_main_page() | ||
page.hover_over_element(MainPageLocators.ABOUT_US_BUTTON) | ||
page.is_element_clickable_after_hover(MainPageLocators.ABOUT_US_BUTTON) | ||
|
||
|
||
def test_tasks_button_visible(driver): | ||
page = MainPage(driver) | ||
page.open_main_page() | ||
page.hover_over_element(MainPageLocators.TASKS_BUTTON) | ||
page.is_element_clickable_after_hover(MainPageLocators.ABOUT_US_BUTTON) | ||
|
||
|
||
def test_enter_clickable(driver): | ||
page = MainPage(driver) | ||
page.open_main_page() | ||
page.hover_over_element(MainPageLocators.REG_BUTTON) | ||
page.is_element_clickable_after_hover(MainPageLocators.REG_BUTTON) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В этих тестах одинаковый код с разными аргументами. Круче всего было бы сделать вместо трех тестов один с разными данными, используя There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Исправила это и другие моменты |
||
|
||
|
||
# Footer tests | ||
@pytest.mark.xfail | ||
def test_linkedin_redirection(driver): | ||
page = MainPage(driver) | ||
page.open_main_page() | ||
page.check_linkedin_redirection() | ||
|
||
|
||
def test_github_redirection(driver): | ||
page = MainPage(driver) | ||
page.open_main_page() | ||
page.check_github_redirection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А для чего у нас в
BasePage
существует методopen
, если здесь мы отдельным методом реализуем открытие страницы?