-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathtest_firefox.py
144 lines (124 loc) · 4.95 KB
/
test_firefox.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
# 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
pytestmark = [pytest.mark.nondestructive, pytest.mark.firefox]
def test_launch(testdir):
file_test = testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_pass(webtext):
assert webtext == u'Success!'
"""
)
testdir.quick_qa(file_test, passed=1)
def test_launch_case_insensitive(testdir):
file_test = testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_pass(webtext):
assert webtext == u'Success!'
"""
)
testdir.quick_qa(file_test, passed=1)
def test_profile(testdir):
"""Test that specified profile is used when starting Firefox.
The profile changes the colors in the browser, which are then reflected
when calling value_of_css_property.
"""
file_test = testdir.makepyfile(
"""
import pytest
from selenium.webdriver.common.by import By
@pytest.fixture
def firefox_options(firefox_options):
firefox_options.set_preference("browser.anchor_color", "#FF69B4")
firefox_options.set_preference("browser.display.foreground_color",
"#FF0000")
firefox_options.set_preference("browser.display.use_document_colors",
False)
return firefox_options
@pytest.mark.nondestructive
def test_profile(base_url, selenium):
selenium.get(base_url)
header = selenium.find_element(By.TAG_NAME, 'h1')
anchor = selenium.find_element(By.TAG_NAME, 'a')
header_color = header.value_of_css_property('color')
anchor_color = anchor.value_of_css_property('color')
assert header_color == 'rgb(255, 0, 0)'
assert anchor_color == 'rgb(255, 105, 180)'
"""
)
testdir.quick_qa(file_test, passed=1)
@pytest.mark.xfail(reason="https://github.com/SeleniumHQ/selenium/pull/5069")
def test_extension(testdir):
"""Test that a firefox extension can be added when starting Firefox."""
import os
path = os.path.join(os.path.split(os.path.dirname(__file__))[0], "testing")
extension = os.path.join(path, "empty.xpi")
file_test = testdir.makepyfile(
"""
import time
import pytest
from selenium.webdriver.common.by import By
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.support.ui import WebDriverWait
@pytest.fixture
def firefox_options(firefox_options):
profile = FirefoxProfile()
profile.add_extension('{0}')
firefox_options.profile = profile
return firefox_options
@pytest.mark.nondestructive
def test_extension(selenium):
selenium.get('about:support')
extensions = WebDriverWait(
selenium, timeout=10,
ignored_exceptions=StaleElementReferenceException).until(
lambda s: s.find_element(By.ID,
'extensions-tbody').text)
assert 'Test Extension (empty)' in extensions
""".format(
extension
)
)
testdir.quick_qa(file_test, passed=1)
def test_preferences_marker(testdir):
"""Test that preferences can be specified using the marker."""
file_test = testdir.makepyfile(
"""
import pytest
from selenium.webdriver.common.by import By
@pytest.mark.nondestructive
@pytest.mark.firefox_preferences({
'browser.anchor_color': '#FF69B4',
'browser.display.foreground_color': '#FF0000',
'browser.display.use_document_colors': False})
def test_preferences(base_url, selenium):
selenium.get(base_url)
header = selenium.find_element(By.TAG_NAME, 'h1')
anchor = selenium.find_element(By.TAG_NAME, 'a')
header_color = header.value_of_css_property('color')
anchor_color = anchor.value_of_css_property('color')
assert header_color == 'rgb(255, 0, 0)'
assert anchor_color == 'rgb(255, 105, 180)'
"""
)
testdir.quick_qa(file_test, passed=1)
def test_arguments_marker(testdir):
file_test = testdir.makepyfile(
"""
import pytest
pytestmark = pytest.mark.firefox_arguments('baz')
@pytest.mark.nondestructive
@pytest.mark.firefox_arguments('foo', 'bar')
def test_arguments(firefox_options):
actual = sorted(firefox_options.arguments)
expected = sorted(['baz', 'foo', 'bar'])
assert actual == expected
"""
)
testdir.quick_qa(file_test, passed=1)