Skip to content

Commit

Permalink
Use Firefox as webdriver for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Dec 9, 2022
1 parent f20a6f2 commit 4adffc4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
7 changes: 4 additions & 3 deletions environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ includes:
environment:
# Tip: Use `--driver <driver_name>` to change driver for a single run
{% if TEST_QMXGRAPH %}
PYTEST_ADDOPTS: --driver PhantomJS
PYTEST_ADDOPTS: --driver Firefox
{% endif %}

dependencies:
Expand All @@ -18,11 +18,12 @@ dependencies:
{% if TEST_QMXGRAPH %}
- cherrypy
- hypothesis =3.11
- phantomjs
- firefox
- geckodriver
- pytest-mock
- pytest-qt
- pytest-rerunfailures
- pytest-selenium >=1,<2
- pytest-selenium
- pytest-timeout
- typing-extensions <4.2.0 # [PYTHON_VERSION=="3.6"]
# Pin importlib_resources due to #151.
Expand Down
1 change: 0 additions & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
git clone --depth=1 --branch v3.7.5 https://github.com/jgraph/mxgraph.git
export PYTEST_ADDOPTS="--driver PhantomJS"
export MXGRAPHPATH=mxgraph
inv qrc
inv test
34 changes: 3 additions & 31 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import shutil

import pytest

Expand All @@ -10,43 +9,16 @@ def pytest_configure(config):
# of pytest so they can't reliably be removed by a fixture.
config.cache.set('qmxgraph/ports', [])

# Ensure phantomjs is available.
phantomjs = shutil.which("phantomjs")
assert phantomjs is not None

lock_file = _get_port_lock_filename(config.rootdir)
if os.path.isfile(lock_file):
os.remove(lock_file)


# Fixtures --------------------------------------------------------------------


@pytest.fixture
def phantomjs_driver(capabilities, driver_path, port):
"""
Overrides default `phantomjs_driver` driver from pytest-selenium.
Default implementation uses ephemeral ports just as our tests but
it doesn't provide any way to configure them, for this reason we basically
recreate the driver fixture using port fixture.
"""
kwargs = {}
if capabilities:
kwargs['desired_capabilities'] = capabilities
if driver_path is not None:
kwargs['executable_path'] = driver_path

kwargs['port'] = port.get()

from selenium.webdriver import PhantomJS

return PhantomJS(**kwargs)


@pytest.fixture
def driver_args():
return ['--debug=true']
def firefox_options(firefox_options):
firefox_options.headless = True
return firefox_options


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit 4adffc4

Please sign in to comment.