-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathtest_report.py
172 lines (146 loc) · 5.4 KB
/
test_report.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# -*- encoding: utf-8 -*-
# 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 re
import pytest
pytestmark = [
pytest.mark.nondestructive,
pytest.mark.skip(
reason="Grid doesn't support logging, see https://github.com/SeleniumHQ/selenium/issues/10949"
),
]
URL_LINK = '<a class="url" href="{0}/" target="_blank">URL</a>'
SCREENSHOT_LINK_REGEX = '<a class="image" href=".*" target="_blank"><img src=".*"/></a>'
SCREENSHOT_REGEX = '<div class="image"><a class="image" href=".*" target="_blank">'
'<img src=".*"/></a></div>'
LOGS_REGEX = '<a class="text" href=".*" target="_blank">.* Log</a>'
HTML_REGEX = '<a class="text" href=".*" target="_blank">HTML</a>'
def run(testdir, *args):
testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_fail(webtext):
assert False
"""
)
path = testdir.tmpdir.join("report.html")
result = testdir.runpytestqa("--html", path, *args)
with open(str(path)) as f:
html = f.read()
return result, html
@pytest.mark.parametrize("when", ["always", "failure", "never"])
def test_capture_debug_env(testdir, monkeypatch, when):
monkeypatch.setenv("SELENIUM_CAPTURE_DEBUG", when)
testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_capture_debug(webtext):
assert {0}
""".format(
"True" if "always" else "False"
)
)
result, html = run(testdir)
if when in ["always", "failure"]:
assert URL_LINK.format("http://webserver") in html
assert re.search(SCREENSHOT_LINK_REGEX, html) is not None
assert re.search(SCREENSHOT_REGEX, html) is not None
# assert re.search(LOGS_REGEX, html) is not None
assert re.search(HTML_REGEX, html) is not None
else:
assert URL_LINK.format("http://webserver") not in html
assert re.search(SCREENSHOT_LINK_REGEX, html) is None
assert re.search(SCREENSHOT_REGEX, html) is None
# assert re.search(LOGS_REGEX, html) is None
assert re.search(HTML_REGEX, html) is None
@pytest.mark.parametrize("when", ["always", "failure", "never"])
def test_capture_debug_config(testdir, when):
testdir.makefile(
".ini",
pytest="""
[pytest]
selenium_capture_debug={0}
""".format(
when
),
)
testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_capture_debug(webtext):
assert {0}
""".format(
"True" if "always" else "False"
)
)
result, html = run(testdir)
if when in ["always", "failure"]:
assert URL_LINK.format("http://webserver") in html
assert re.search(SCREENSHOT_LINK_REGEX, html) is not None
assert re.search(SCREENSHOT_REGEX, html) is not None
# assert re.search(LOGS_REGEX, html) is not None
assert re.search(HTML_REGEX, html) is not None
else:
assert URL_LINK.format("http://webserver") not in html
assert re.search(SCREENSHOT_LINK_REGEX, html) is None
assert re.search(SCREENSHOT_REGEX, html) is None
# assert re.search(LOGS_REGEX, html) is None
assert re.search(HTML_REGEX, html) is None
@pytest.mark.parametrize("exclude", ["url", "screenshot", "html", "logs"])
def test_exclude_debug_env(testdir, monkeypatch, exclude):
monkeypatch.setenv("SELENIUM_EXCLUDE_DEBUG", exclude)
result, html = run(testdir)
assert result.ret
if exclude == "url":
assert URL_LINK.format("http://webserver") not in html
else:
assert URL_LINK.format("http://webserver") in html
if exclude == "screenshot":
assert re.search(SCREENSHOT_LINK_REGEX, html) is None
assert re.search(SCREENSHOT_REGEX, html) is None
else:
assert re.search(SCREENSHOT_LINK_REGEX, html) is not None
assert re.search(SCREENSHOT_REGEX, html) is not None
# if exclude == "logs":
# assert re.search(LOGS_REGEX, html) is None
# else:
# assert re.search(LOGS_REGEX, html) is not None
if exclude == "html":
assert re.search(HTML_REGEX, html) is None
else:
assert re.search(HTML_REGEX, html) is not None
@pytest.mark.parametrize("exclude", ["url", "screenshot", "html", "logs"])
def test_exclude_debug_config(testdir, exclude):
testdir.makefile(
".ini",
pytest="""
[pytest]
selenium_exclude_debug={0}
""".format(
exclude
),
)
result, html = run(testdir)
assert result.ret
if exclude == "url":
assert URL_LINK.format("http://webserver") not in html
else:
assert URL_LINK.format("http://webserver") in html
if exclude == "screenshot":
assert re.search(SCREENSHOT_LINK_REGEX, html) is None
assert re.search(SCREENSHOT_REGEX, html) is None
else:
assert re.search(SCREENSHOT_LINK_REGEX, html) is not None
assert re.search(SCREENSHOT_REGEX, html) is not None
# if exclude == "logs":
# assert re.search(LOGS_REGEX, html) is None
# else:
# assert re.search(LOGS_REGEX, html) is not None
if exclude == "html":
assert re.search(HTML_REGEX, html) is None
else:
assert re.search(HTML_REGEX, html) is not None