Skip to content

Commit 3126dff

Browse files
PhilippSeleniumPhilipp Selenium
andauthored
Feature/edge chromium (#245)
Add Edge options fixture to choose between legacy and chromium mode. Co-authored-by: Philipp Selenium <[email protected]>
1 parent 13e8348 commit 3126dff

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

pytest_selenium/drivers/edge.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
from distutils.version import LooseVersion
5+
6+
import pytest
57
from selenium import __version__ as SELENIUM_VERSION
8+
from selenium.webdriver.edge.options import Options
69

710

8-
def driver_kwargs(capabilities, driver_log, driver_path, **kwargs):
11+
def driver_kwargs(capabilities, driver_log, driver_path, edge_options, **kwargs):
912

1013
# Selenium 3.14.0 deprecated log_path in favour of service_log_path
1114
if LooseVersion(SELENIUM_VERSION) < LooseVersion("3.14.0"):
1215
kwargs = {"log_path": driver_log}
1316
else:
1417
kwargs = {"service_log_path": driver_log}
1518

19+
if LooseVersion(SELENIUM_VERSION) >= LooseVersion("4.0.0"):
20+
kwargs["options"] = edge_options
21+
1622
if capabilities:
1723
kwargs["capabilities"] = capabilities
1824
if driver_path is not None:
1925
kwargs["executable_path"] = driver_path
26+
2027
return kwargs
28+
29+
30+
@pytest.fixture
31+
def edge_options():
32+
return Options()

pytest_selenium/pytest_selenium.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ def session_capabilities(pytestconfig):
9696

9797
@pytest.fixture
9898
def capabilities(
99-
request, driver_class, chrome_options, firefox_options, session_capabilities
99+
request,
100+
driver_class,
101+
chrome_options,
102+
firefox_options,
103+
edge_options,
104+
session_capabilities,
100105
):
101106
"""Returns combined capabilities"""
102107
capabilities = copy.deepcopy(session_capabilities) # make a copy
@@ -111,6 +116,9 @@ def capabilities(
111116
elif browser == "FIREFOX":
112117
key = firefox_options.KEY
113118
options = firefox_options.to_capabilities()
119+
elif browser == "EDGE":
120+
key = edge_options.KEY
121+
options = edge_options.to_capabilities()
114122
if all([key, options]):
115123
capabilities[key] = _merge(capabilities.get(key, {}), options.get(key, {}))
116124
capabilities.update(get_capabilities_from_markers(request.node))
@@ -146,6 +154,7 @@ def driver_kwargs(
146154
driver_path,
147155
firefox_options,
148156
firefox_profile,
157+
edge_options,
149158
pytestconfig,
150159
):
151160
kwargs = {}
@@ -159,13 +168,15 @@ def driver_kwargs(
159168
driver_path=driver_path,
160169
firefox_options=firefox_options,
161170
firefox_profile=firefox_profile,
171+
edge_options=edge_options,
162172
host=pytestconfig.getoption("host"),
163173
port=pytestconfig.getoption("port"),
164174
service_log_path=None,
165175
request=request,
166176
test=".".join(split_class_and_test_names(request.node.nodeid)),
167177
)
168178
)
179+
169180
pytestconfig._driver_log = driver_log
170181
return kwargs
171182

testing/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def chrome_options(chrome_options):
5252
error::DeprecationWarning
5353
ignore:--firefox-\w+ has been deprecated:DeprecationWarning
5454
ignore:Support for PhantomJS:DeprecationWarning
55+
ignore:desired_capabilities has been deprecated
56+
ignore:service_log_path has been deprecated
5557
""",
5658
)
5759

testing/test_edge.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
import pytest
66
import sys
7+
from distutils.version import LooseVersion
8+
from selenium import __version__ as SELENIUM_VERSION
9+
710

811
pytestmark = pytest.mark.nondestructive
912

1013

1114
@pytest.mark.skipif(sys.platform != "win32", reason="Edge only runs on Windows")
1215
@pytest.mark.edge
13-
def test_launch(testdir, httpserver):
16+
def test_launch_legacy(testdir, httpserver):
1417
httpserver.serve_content(content="<h1>Success!</h1>")
1518
file_test = testdir.makepyfile(
1619
"""
@@ -21,3 +24,31 @@ def test_pass(webtext):
2124
"""
2225
)
2326
testdir.quick_qa("--driver", "Edge", file_test, passed=1)
27+
28+
29+
@pytest.mark.skipif(sys.platform != "win32", reason="Edge only runs on Windows")
30+
@pytest.mark.skipif(
31+
LooseVersion(SELENIUM_VERSION) < LooseVersion("4.0.0"),
32+
reason="Edge chromium only supported for selenium >= 4.0.0",
33+
)
34+
@pytest.mark.edge
35+
@pytest.mark.parametrize("use_chromium", [True, False], ids=["chromium", "legacy"])
36+
def test_launch(use_chromium, testdir, httpserver):
37+
httpserver.serve_content(content="<h1>Success!</h1>")
38+
file_test = testdir.makepyfile(
39+
"""
40+
import pytest
41+
42+
@pytest.mark.nondestructive
43+
def test_pass(webtext):
44+
assert webtext == u'Success!'
45+
46+
@pytest.fixture
47+
def edge_options(edge_options):
48+
edge_options.use_chromium = {}
49+
return edge_options
50+
""".format(
51+
use_chromium
52+
)
53+
)
54+
testdir.quick_qa("--driver", "Edge", file_test, passed=1)

0 commit comments

Comments
 (0)