-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
75 lines (54 loc) · 2.23 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 pytest
from tests.pages.InventoryPage import InventoryPage
from tests.pages.LoginPage import LoginPage
from tests.pages.MenuPage import MenuPage
SUPPORTED_BROWSERS_LIST = [
"chrome",
"firefox",
"safari",
"headless-chrome",
"headless-firefox",
"headless-safari",
]
def pytest_addoption(parser):
parser.addoption(
"--use-browser",
action="store",
default="headless-firefox",
help="Define the browser to be executed. Current supported versions: " + ", ".join(SUPPORTED_BROWSERS_LIST)
)
@pytest.fixture(scope="function")
def use_browser_option(request):
"""Fixture to handle the use of argument --use-browser to select"""
force_browser = request.node.get_closest_marker("FORCE_BROWSER")
selected_browser = request.config.getoption("--use-browser")
if force_browser is None:
return selected_browser
elif selected_browser.lower() == "remote":
pytest.skip(reason="Test to be run on specific browser locally")
return force_browser.args[0]
@pytest.fixture(scope="function")
def start_by_login_page(use_browser_option):
"""Fixture that starts the WebDriver by accessing the Login page"""
login_page = LoginPage(driver=use_browser_option)
yield login_page
login_page.close_driver()
@pytest.fixture(scope="function")
def start_already_logged(use_browser_option):
"""Fixture that starts the WebDriver with an user already logged"""
login_page = LoginPage(driver=use_browser_option)
login_page.access_page()
login_page.type_successfull_credentials()
login_page.click_on_login()
inventory_page = InventoryPage(driver = login_page.driver)
yield inventory_page
inventory_page.close_driver()
@pytest.fixture(scope="function")
def start_with_one_product_added(start_already_logged):
"""Fixture that starts the WebDriver with an user logged and at least one product added"""
inventory_page = InventoryPage(driver = start_already_logged.driver)
selected_item, _, _ = inventory_page.choose_an_item_randomsly()
inventory_page.add_item_to_cart(selected_item)
menu_page = MenuPage(driver = inventory_page.driver)
menu_page.click_on_cart_icon()
return menu_page