Skip to content

Commit

Permalink
Feature/edge chromium (#245)
Browse files Browse the repository at this point in the history
Add Edge options fixture to choose between legacy and chromium mode.
Co-authored-by: Philipp Selenium <philipp.selenium@github.com>
  • Loading branch information
PhilippSelenium committed Jul 13, 2020
1 parent 13e8348 commit 3126dff
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
14 changes: 13 additions & 1 deletion pytest_selenium/drivers/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
# 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/.
from distutils.version import LooseVersion

import pytest
from selenium import __version__ as SELENIUM_VERSION
from selenium.webdriver.edge.options import Options


def driver_kwargs(capabilities, driver_log, driver_path, **kwargs):
def driver_kwargs(capabilities, driver_log, driver_path, edge_options, **kwargs):

# Selenium 3.14.0 deprecated log_path in favour of service_log_path
if LooseVersion(SELENIUM_VERSION) < LooseVersion("3.14.0"):
kwargs = {"log_path": driver_log}
else:
kwargs = {"service_log_path": driver_log}

if LooseVersion(SELENIUM_VERSION) >= LooseVersion("4.0.0"):
kwargs["options"] = edge_options

if capabilities:
kwargs["capabilities"] = capabilities
if driver_path is not None:
kwargs["executable_path"] = driver_path

return kwargs


@pytest.fixture
def edge_options():
return Options()
13 changes: 12 additions & 1 deletion pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ def session_capabilities(pytestconfig):

@pytest.fixture
def capabilities(
request, driver_class, chrome_options, firefox_options, session_capabilities
request,
driver_class,
chrome_options,
firefox_options,
edge_options,
session_capabilities,
):
"""Returns combined capabilities"""
capabilities = copy.deepcopy(session_capabilities) # make a copy
Expand All @@ -111,6 +116,9 @@ def capabilities(
elif browser == "FIREFOX":
key = firefox_options.KEY
options = firefox_options.to_capabilities()
elif browser == "EDGE":
key = edge_options.KEY
options = edge_options.to_capabilities()
if all([key, options]):
capabilities[key] = _merge(capabilities.get(key, {}), options.get(key, {}))
capabilities.update(get_capabilities_from_markers(request.node))
Expand Down Expand Up @@ -146,6 +154,7 @@ def driver_kwargs(
driver_path,
firefox_options,
firefox_profile,
edge_options,
pytestconfig,
):
kwargs = {}
Expand All @@ -159,13 +168,15 @@ def driver_kwargs(
driver_path=driver_path,
firefox_options=firefox_options,
firefox_profile=firefox_profile,
edge_options=edge_options,
host=pytestconfig.getoption("host"),
port=pytestconfig.getoption("port"),
service_log_path=None,
request=request,
test=".".join(split_class_and_test_names(request.node.nodeid)),
)
)

pytestconfig._driver_log = driver_log
return kwargs

Expand Down
2 changes: 2 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def chrome_options(chrome_options):
error::DeprecationWarning
ignore:--firefox-\w+ has been deprecated:DeprecationWarning
ignore:Support for PhantomJS:DeprecationWarning
ignore:desired_capabilities has been deprecated
ignore:service_log_path has been deprecated
""",
)

Expand Down
33 changes: 32 additions & 1 deletion testing/test_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import pytest
import sys
from distutils.version import LooseVersion
from selenium import __version__ as SELENIUM_VERSION


pytestmark = pytest.mark.nondestructive


@pytest.mark.skipif(sys.platform != "win32", reason="Edge only runs on Windows")
@pytest.mark.edge
def test_launch(testdir, httpserver):
def test_launch_legacy(testdir, httpserver):
httpserver.serve_content(content="<h1>Success!</h1>")
file_test = testdir.makepyfile(
"""
Expand All @@ -21,3 +24,31 @@ def test_pass(webtext):
"""
)
testdir.quick_qa("--driver", "Edge", file_test, passed=1)


@pytest.mark.skipif(sys.platform != "win32", reason="Edge only runs on Windows")
@pytest.mark.skipif(
LooseVersion(SELENIUM_VERSION) < LooseVersion("4.0.0"),
reason="Edge chromium only supported for selenium >= 4.0.0",
)
@pytest.mark.edge
@pytest.mark.parametrize("use_chromium", [True, False], ids=["chromium", "legacy"])
def test_launch(use_chromium, testdir, httpserver):
httpserver.serve_content(content="<h1>Success!</h1>")
file_test = testdir.makepyfile(
"""
import pytest
@pytest.mark.nondestructive
def test_pass(webtext):
assert webtext == u'Success!'
@pytest.fixture
def edge_options(edge_options):
edge_options.use_chromium = {}
return edge_options
""".format(
use_chromium
)
)
testdir.quick_qa("--driver", "Edge", file_test, passed=1)

0 comments on commit 3126dff

Please sign in to comment.