-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
46 lines (35 loc) · 1.21 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
import pytest
import json
import os.path
from fixture.application import Application
fixture = None
target = None
def load_config(file):
global target
if target is None:
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
with open(config_file) as f:
target = json.load(f)
return target
@pytest.fixture(scope="session")
def config(request):
return load_config(request.config.getoption("--target"))
@pytest.fixture
def app(request, config):
global fixture
browser = request.config.getoption("--browser")
if fixture is None or not fixture.is_valid():
fixture = Application(browser=browser, base_url=config["web"]["baseUrl"])
user_info = config["webadmin"]
fixture.session.ensure_login(username=user_info["username"], password=user_info["password"])
return fixture
@pytest.fixture(scope="session", autouse=True)
def stop(request):
def fin():
fixture.session.ensure_logout()
fixture.destroy()
request.addfinalizer(fin)
return fixture
def pytest_addoption(parser):
parser.addoption("--browser", action="store", default="firefox")
parser.addoption("--target", action="store", default="target.json")