-
Notifications
You must be signed in to change notification settings - Fork 23
/
conftest.py
63 lines (54 loc) · 1.88 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
import pytest
from pytest_factoryboy import register
from tests.factories import UserFactory
from selenium import webdriver
import pathlib
import os
register(UserFactory)
@pytest.fixture
def new_user1(db, user_factory):
user = user_factory.create()
return user
def get_path_to_driver(driver):
path = pathlib.Path(__file__).parent.absolute()
avail_options = list()
for file in os.listdir(path):
if driver == "firefox":
if "geckodriver" in file.lower():
avail_options.append(file)
else:
if "chromedriver" in file.lower():
avail_options.append(file)
if len(avail_options) == 1:
path = os.path.join(path, avail_options[0])
else:
found = False
for ao in avail_options:
print(f'ao')
if ao == "geckodriver" and driver == "firefox":
path = os.path.join(path, ao)
found = True
break
elif ao == "chromedriver" and driver != "firefox":
found = True
path = os.path.join(path, ao)
break
if not found:
path = os.path.join(path, avail_options[0])
print('path to {driver} driver ',path)
return path
#@pytest.fixture(params=["chrome", "firefox"], scope="class")
@pytest.fixture(params=["chrome"], scope="class")
def driver_init(request):
path = get_path_to_driver(request.param)
if request.param == "chrome":
options = webdriver.ChromeOptions()
#options.add_argument("--headless")
web_driver = webdriver.Chrome(executable_path=path, options=options)
if request.param == "firefox":
options = webdriver.FirefoxOptions()
#options.add_argument("--headless")
web_driver = webdriver.Firefox(executable_path=path, options=options)
request.cls.driver = web_driver
yield
web_driver.close()