forked from SvetlanaAQA/LumaProjectPython_2024_spring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
129 lines (95 loc) · 3.29 KB
/
conftest.py
File metadata and controls
129 lines (95 loc) · 3.29 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import os
from time import time
import allure
import allure_commons
import pytest
from faker import Faker
from selene import browser, support
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
cwd_report = os.path.join(os.path.dirname(os.path.abspath(__file__)), "allure-results")
allure_dir = getattr(config.option, "allure_report_dir", None)
if not allure_dir:
setattr(config.option, "allure_report_dir", cwd_report)
@pytest.fixture(scope="function")
def driver():
options = Options()
options.add_argument("--window-size=1920,1080")
# options.add_argument('--headless=new')
options.add_argument("--lang=en")
if os.environ.get("CI_RUN"):
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(options=options)
yield driver
driver.quit()
@pytest.fixture(autouse=True)
def browser_management(request):
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument("--window-size=1920,1080")
# options.add_argument('--headless=new')
options.add_argument("--lang=en")
if os.environ.get("CI_RUN"):
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
browser.config.driver_options = options
browser.config.timeout = 25
# browser.config.log_outer_html_on_failure = True !!! DISABLES STEPS !!!
browser.config.reports_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "driver-report")
if os.environ.get('CI_RUN'):
browser.config.save_screenshot_on_failure = False
browser.config.save_page_source_on_failure = False
browser.config._wait_decorator = support._logging.wait_with(
context=allure_commons._allure.StepContext
)
failed_before = request.session.testsfailed
yield
if request.session.testsfailed != failed_before:
allure.attach(
browser.driver.get_screenshot_as_png(),
name="screenshot",
attachment_type=allure.attachment_type.PNG
)
browser.quit()
@pytest.fixture
def first_name():
return Faker().first_name()
@pytest.fixture
def last_name():
return Faker().last_name()
@pytest.fixture
def user_email():
lst = Faker().email().split("@")
return "".join([lst[0], str(int(time())), "@", lst[1]])
@pytest.fixture
def password():
return Faker().password()
@pytest.fixture
def state():
return Faker().state()
@pytest.fixture
def postcode():
return Faker().postcode()
@pytest.fixture
def phone_number():
return Faker().phone_number()
@pytest.fixture
def street_address():
return Faker().street_address()
@pytest.fixture
def city():
return Faker().city()
@pytest.fixture
def user(user_email, first_name, last_name, street_address, city, postcode, phone_number):
return {'user_email': user_email,
"first_name": first_name,
'last_name': last_name,
'street_address': street_address,
'city': city,
'postcode': postcode,
'phone_number': phone_number}