-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
95 lines (79 loc) · 3.99 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import logging
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from constants import login_constants, patient_list_constant
from pages.baseClass import AdminUser
from pages.login_page import LoginPage
from pages.patient_page.patient_case_tab_page import CaseTabPage
from pages.patient_page.patient_list_page import PatientsListPage
from test_data.patients_data import PatientData
from test_data.users_data import UsersData
def pytest_runtest_setup(item):
"""prepare test"""
log = logging.getLogger(item.name)
item.cls.logger = log
def pytest_addoption(parser):
"""
--browser_name - ключ который мы пишем в команде перед наименованием браузера. Пример: py.test --browser_name firefox
default="chrome" - означает что по умолчанию будет ранится хроме если мы не указали наименование браузера
"""
parser.addoption(
"--browser_name", action="store", default="chrome"
)
@pytest.fixture(scope="function")
def setup(request):
"""
Теперь если мы можем запускать комманду с наимнованием нужного нам браузера для рана:
py.test --browser_name firefox
py.test --browser_name chrome
"""
browser_name = request.config.getoption("browser_name")
if browser_name == "chrome":
driver = webdriver.Chrome(executable_path="/home/ihor/PycharmProjects/Silibrain/driver/chromedriver")
elif browser_name == "firefox":
driver = webdriver.Firefox(executable_path="/home/ihor/PycharmProjects/Silibrain/driver/geckodriver")
else:
raise ValueError(f"Unknown browser {browser_name}")
# Open start page
driver.get(login_constants.STAGE_BASE_URL)
driver.implicitly_wait(time_to_wait=10)
login_page_obj = LoginPage(driver)
driver.maximize_window()
# click ingressa button
ingresa_button = driver.find_element(by=By.XPATH, value=login_constants.INGRESSA_BUTTON_LOGIN_PAGE)
ingresa_button.click()
"""это означает что теперь наш драйвер может быть юзабельным на уровне класса"""
request.cls.driver = driver
yield login_page_obj
driver.close()
@pytest.fixture(scope="function")
def login_as_admin(setup):
admin_user_obj = AdminUser(email=UsersData.ADMIN_LOGIN, password=UsersData.ADMIN_PASSWORD)
# enter valid login and password
setup.fill_login_fields(email=UsersData.ADMIN_LOGIN, password=UsersData.ADMIN_PASSWORD)
# Verify the email is displayed on the page
setup.verify_success_login(email=UsersData.ADMIN_LOGIN.lower())
return admin_user_obj
"""Here valid test data for tests_patient creation"""
@pytest.fixture(params=PatientData.VALID_PATIENT_CREATION_DATA)
def get_patient_data(request):
return request.param
@pytest.fixture(scope="function")
def create_patient(setup, login_as_admin, get_patient_data):
patient_page_obj = PatientsListPage(setup.driver)
patient_page_obj.open_patient_list_page()
patient_page_obj.open_patient_overlay()
patient_page_obj.create_valid_patient_with_unique_firstname(get_patient_data["first_name"],
get_patient_data["last_name"],
get_patient_data["email"],
get_patient_data["phone"],
patient_list_constant.PAYMENT_COEX_OPTION_XPATH)
patient_page_obj.open_created_patient_displayed_on_list(get_patient_data["first_name"])
yield patient_page_obj
@pytest.fixture(scope="function")
def create_case_as_admin(setup, create_patient):
case_page_obj = CaseTabPage(setup.driver)
case_page_obj.click_case_tab()
case_page_obj.create_case_with_default_date()
case_page_obj.open_newly_created_case()