-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
75 lines (65 loc) · 2.06 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
import logging
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from pages.application import Application
from models.auth import AuthData
logger = logging.getLogger("moodle")
@pytest.fixture(scope="session")
def app(request):
base_url = request.config.getoption("--base-url")
headless_mode = request.config.getoption("--headless").lower()
logger.info(f"Start moodle {base_url} with headless={headless_mode} mode")
if headless_mode == "true":
chrome_options = Options()
chrome_options.headless = True
fixture = Application(
webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options),
base_url,
)
elif headless_mode == "false":
fixture = Application(
webdriver.Chrome(ChromeDriverManager().install()),
base_url,
)
else:
raise pytest.UsageError("--headless should be true or false")
yield fixture
fixture.quit()
@pytest.fixture
def auth(app, request):
username = request.config.getoption("--username")
password = request.config.getoption("--password")
app.open_auth_page()
auth_data = AuthData(login=username, password=password)
app.login.auth(auth_data)
assert app.login.is_auth(), "You are not auth"
yield
app.login.sign_out()
def pytest_addoption(parser):
parser.addoption(
"--headless",
action="store",
default="true",
help="enter 'true' if you want run tests in headless mode of browser,\n"
"enter 'false' - if not",
),
parser.addoption(
"--base-url",
action="store",
default="https://qacoursemoodle.innopolis.university",
help="enter base_url",
),
parser.addoption(
"--username",
action="store",
default="nadi",
help="enter username",
),
parser.addoption(
"--password",
action="store",
default="Nadi123456!",
help="enter password",
),