-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f543bd
commit 7748114
Showing
14 changed files
with
247 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,3 @@ jobs: | |
- name: Analysing the code with pylint | ||
run: | | ||
pylint $(git ls-files '*.py') | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pytest | ||
import allure | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.options import Options as Options_chrome | ||
from selenium.webdriver.firefox.options import Options as Options_ff | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def driver(browser_options, host_options): | ||
if browser_options == 'ff' and host_options == 'server': | ||
with allure.step(f'Rune Firefox and {host_options}'): | ||
options = Options_ff() | ||
options.add_argument("--headless") | ||
|
||
driver_browser = webdriver.Firefox(options=options) | ||
driver_browser.maximize_window() | ||
|
||
elif browser_options == 'ff': | ||
with allure.step('Rune Firefox'): | ||
driver_browser = webdriver.Firefox() | ||
# driver_browser.maximize_window() | ||
|
||
elif host_options == 'server': | ||
with allure.step(f'Rune Chrome with {host_options}'): | ||
options = Options_chrome() | ||
options.add_argument("--headless") | ||
options.add_argument("start-maximized") | ||
driver_browser = webdriver.Chrome(options=options) | ||
driver_browser.maximize_window() | ||
else: | ||
with allure.step('Rune Chrome'): | ||
driver_browser = webdriver.Chrome() | ||
driver_browser.maximize_window() | ||
driver_browser.implicitly_wait(10) | ||
yield driver_browser | ||
driver_browser.quit() | ||
|
||
|
||
# @pytest.fixture(scope='function') | ||
# def driver(browser_options, host_options): | ||
# if host_options == 'server': | ||
# options = Options_chrome() | ||
# options.add_argument("--headless") | ||
# options.add_argument("start-maximized") | ||
# driver_browser = webdriver.Chrome(options=options) | ||
# | ||
# else: | ||
# driver_browser = webdriver.Chrome() | ||
# driver_browser.maximize_window() | ||
# | ||
# driver_browser.implicitly_wait(10) | ||
# yield driver_browser | ||
# driver_browser.quit() | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
'--browser', | ||
action='store', | ||
default='chrome', | ||
help='Укажите значение браузера, поумолчанию Chrome' | ||
) | ||
parser.addoption( | ||
'--host', | ||
action='store', | ||
default='ui', | ||
help='Укажите варивнт запуска браузера, по умолчанию UI' | ||
) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def browser_options(request): | ||
return request.config.getoption('--browser') | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def host_options(request): | ||
return request.config.getoption('--host') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import math | ||
from selenium.common import NoSuchElementException | ||
from selenium.webdriver.chrome.webdriver import WebDriver | ||
from selenium.common.exceptions import NoAlertPresentException, TimeoutException | ||
from selenium.webdriver.support.wait import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as ec | ||
from pages.locators import base_page_locators as loc | ||
|
||
|
||
class BasePage: | ||
|
||
def __init__(self, driver: WebDriver): | ||
self.driver = driver | ||
|
||
def open_site(self, link): | ||
self.driver.get(link) | ||
|
||
def find_element(self, *args): | ||
element, value = args[0] | ||
return self.driver.find_element(element, value) | ||
|
||
def find_elements(self, *args): | ||
element, value = args[0] | ||
return self.driver.find_elements(element, value) | ||
|
||
def is_element_present(self, *args): | ||
element, value = args[0] | ||
try: | ||
self.driver.find_element(element, value) | ||
except NoSuchElementException: | ||
return False | ||
return True | ||
|
||
def solve_quiz_and_get_code(self): | ||
alert = self.driver.switch_to.alert | ||
x_num = alert.text.split(" ")[2] | ||
answer = str(math.log(abs((12 * math.sin(float(x_num)))))) | ||
alert.send_keys(answer) | ||
alert.accept() | ||
try: | ||
alert = self.driver.switch_to.alert | ||
alert.accept() | ||
except NoAlertPresentException: | ||
print("No second alert presented") | ||
|
||
def is_not_element_present(self, *args, timeout=4): | ||
element, value = args[0] | ||
try: | ||
WebDriverWait(self.driver, timeout).until( | ||
ec.presence_of_element_located((element, value)) | ||
) | ||
except TimeoutException: | ||
return True | ||
return False | ||
|
||
def is_disappeared(self, *args, timeout=4): | ||
element, value = args[0] | ||
try: | ||
WebDriverWait(self.driver, timeout, 1, TimeoutException).\ | ||
until_not(ec.presence_of_element_located((element, value))) | ||
except TimeoutException: | ||
return False | ||
return True | ||
|
||
def go_to_login_page(self): | ||
self.find_element(loc.login_link).click() | ||
|
||
def should_be_login_link(self): | ||
return self.is_element_present(loc.login_link) | ||
|
||
def go_to_cart(self): | ||
self.find_element(loc.cart_button).click() | ||
|
||
def should_be_authorized_user(self): | ||
assert self.is_element_present(loc.user_icon), "User icon is not presented," \ | ||
" probably unauthorised user" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pages.base_page import BasePage | ||
from pages.locators import basket_page_locators as loc | ||
|
||
|
||
class BasketPage(BasePage): | ||
|
||
def __init__(self, driver): | ||
super().__init__(driver) | ||
self.driver = driver | ||
|
||
def message_the_cart_is_empty_is_displayed(self): | ||
return self.find_element(loc.message_the_cart_is_empty).is_displayed() | ||
|
||
def the_product_is_not_in_the_cart(self): | ||
return self.is_not_element_present(loc.product_in_the_cart) | ||
|
||
def the_product_in_the_cart(self): | ||
return self.find_element(loc.product_in_the_cart).is_displayed() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from selenium.webdriver.common.by import By | ||
|
||
|
||
cart_button = (By.CSS_SELECTOR, '.btn-group a') | ||
login_link = (By.CSS_SELECTOR, "#login_link") | ||
login_link_invalid = (By.CSS_SELECTOR, "#login_link_inc") | ||
user_icon = (By.CSS_SELECTOR, ".icon-user") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from selenium.webdriver.common.by import By | ||
|
||
message_the_cart_is_empty = (By.CSS_SELECTOR, '#content_inner') | ||
product_in_the_cart = (By.CSS_SELECTOR, '.basket-items') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from selenium.webdriver.common.by import By | ||
|
||
|
||
login_link = (By.CSS_SELECTOR, "#login_link") | ||
login_link_invalid = (By.CSS_SELECTOR, "#login_link_invalid") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pages.base_page import BasePage | ||
from pages.locators import main_page_locators as loc | ||
|
||
|
||
class MainPage(BasePage): | ||
|
||
def __init__(self, driver): | ||
super().__init__(driver) | ||
self.driver = driver | ||
|
||
def login_link_is_displayed(self): | ||
return self.find_element(loc.login_link).is_displayed() | ||
|
||
def should_be_login_link(self): | ||
return self.find_element(loc.login_link) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import allure | ||
from pages.main_page import MainPage | ||
from pages.basket_page import BasketPage | ||
import pytest | ||
from selenium import webdriver | ||
import json | ||
import os | ||
|
||
LINK = 'http://selenium1py.pythonanywhere.com/' | ||
|
||
# @pytest.fixture(scope='function') | ||
# def driver(): | ||
# driver = webdriver.Chrome() | ||
# # driver.set_window_size(660, 880) | ||
# driver.maximize_window() | ||
# driver.implicitly_wait(10) | ||
# yield driver | ||
# driver.quit() | ||
|
||
|
||
|
||
@allure.feature('Home page') | ||
@allure.story('Login link is displayed') | ||
def test_guest_should_see_login_link(driver): | ||
with allure.step('Open web site'): | ||
main_page = MainPage(driver) | ||
main_page.open_site(LINK) | ||
with allure.step('Login link is displayed'): | ||
assert main_page.should_be_login_link() | ||
|
||
|
||
@allure.feature('Home page') | ||
@allure.story('No product in the cart') | ||
def test_guest_cant_see_product_in_basket_opened_from_main_pages(driver): | ||
with allure.step('Open web site'): | ||
main_page = MainPage(driver) | ||
main_page.open_site(LINK) | ||
with allure.step('Open the shopping cart'): | ||
main_page.go_to_cart() | ||
cart_page = BasketPage(driver) | ||
with allure.step('Check product is not in the cart'): | ||
assert cart_page.the_product_is_not_in_the_cart() | ||
assert cart_page.message_the_cart_is_empty_is_displayed() |