forked from bwalkowi/pytest-selenium-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
59 lines (42 loc) · 1.64 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
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import pytest
pytest_plugins = 'pytester'
def base_url(httpserver):
return httpserver.url
@pytest.fixture
def httpserver_base_url(httpserver):
return '--base-url={0}'.format(base_url(httpserver))
@pytest.fixture(autouse=True)
def testdir(request, httpserver_base_url):
item = request.node
if 'testdir' not in item.funcargnames:
return
testdir = request.getfuncargvalue('testdir')
testdir.makepyfile(conftest="""
import pytest
@pytest.fixture
def webtext(base_url, selenium):
selenium.get(base_url)
return selenium.find_element_by_tag_name('h1').text
""")
def runpytestqa(*args, **kwargs):
return testdir.runpytest(httpserver_base_url, '--driver', 'Firefox',
*args, **kwargs)
testdir.runpytestqa = runpytestqa
def inline_runqa(*args, **kwargs):
return testdir.inline_run(httpserver_base_url, '--driver', 'Firefox',
*args, **kwargs)
testdir.inline_runqa = inline_runqa
def quick_qa(*args, **kwargs):
reprec = inline_runqa(*args)
outcomes = reprec.listoutcomes()
names = ('passed', 'skipped', 'failed')
for name, val in zip(names, outcomes):
wantlen = kwargs.get(name)
if wantlen is not None:
assert len(val) == wantlen, name
testdir.quick_qa = quick_qa
return testdir