-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathtest_driver_log.py
72 lines (59 loc) · 1.99 KB
/
test_driver_log.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
# 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 os
import re
import pytest
pytestmark = pytest.mark.nondestructive
LOG_REGEX = re.compile('<a class="text" href=".*" target="_blank">Driver Log</a>')
@pytest.mark.xfail(reason="Remote driver currently doesn't support logs")
def test_driver_log(testdir):
testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_driver_log(webtext):
assert False
"""
)
path = testdir.tmpdir.join("report.html")
testdir.runpytestqa("--html", path)
with open(str(path)) as f:
html = f.read()
assert LOG_REGEX.search(html) is not None
log_path = testdir.tmpdir.dirpath("basetemp", "test_driver_log0", "driver.log")
assert os.path.exists(str(log_path))
@pytest.mark.xfail(reason="Remote driver currently doesn't support logs")
def test_driver_log_fixture(testdir):
file_test = testdir.makepyfile(
"""
import pytest
@pytest.fixture
def driver_log():
return 'foo.log'
@pytest.mark.nondestructive
def test_pass(webtext):
assert webtext == u'Success!'
"""
)
testdir.quick_qa(file_test, passed=1)
assert os.path.exists(str(testdir.tmpdir.join("foo.log")))
def test_no_driver_log(testdir):
testdir.makepyfile(
"""
import pytest
@pytest.fixture
def driver_log():
return None
@pytest.mark.nondestructive
def test_no_driver_log(webtext):
assert False
"""
)
path = testdir.tmpdir.join("report.html")
testdir.runpytestqa("--html", path)
with open(str(path)) as f:
html = f.read()
assert LOG_REGEX.search(html) is None
log_path = testdir.tmpdir.dirpath("basetemp", "test_no_driver_log0", "driver.log")
assert not os.path.exists(str(log_path))