Skip to content

Commit

Permalink
Switch js tests env and build from phantomjs to chrome
Browse files Browse the repository at this point in the history
By "Switch js tests env" read "get the conda env to resolve without
conflicts.

ASIM-5273
  • Loading branch information
prusse-martin committed Nov 9, 2023
1 parent fbf5142 commit 5cbe5a3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 53 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: browser-actions/[email protected]
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
Expand Down
4 changes: 4 additions & 0 deletions _base_environment.devenv.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% set TEST_QMXGRAPH = os.environ.get('TEST_QMXGRAPH', '0') != '0' %}
name: qmxgraph

dependencies:
Expand All @@ -16,5 +17,8 @@ dependencies:
environment:
PYTHONPATH:
- {{ root }}/src
{% if TEST_QMXGRAPH %}
- {{ root }}/tests
{% endif %}
MYPYPATH:
- {{ root }}/src
7 changes: 4 additions & 3 deletions environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ includes:
environment:
# Tip: Use `--driver <driver_name>` to change driver for a single run
{% if TEST_QMXGRAPH %}
PYTEST_ADDOPTS: --driver PhantomJS
PYTEST_ADDOPTS: --driver Chrome
{% endif %}

dependencies:
- python ={{ PYTHON_VERSION }}

{% if TEST_QMXGRAPH %}
- cherrypy
- cherrypy >=18.0.0
- pytest-mock
- pytest-qt
- pytest-rerunfailures
- pytest-selenium >=1,<2
- pytest-selenium >2
- pytest-timeout
- selenium >=4.0.0, <4.10.0
{% if sys.platform != 'win32' %}
- pytest-xvfb
{% endif %}
Expand Down
28 changes: 4 additions & 24 deletions esss_environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,9 @@ includes:
- {{ root }}/_base_environment.devenv.yml

environment:
# PhantomJS
# pros:
# * doesn't open a browser (i.e. known as headless)
# * as consequence, doesn't interfere with developer GUI
# * uses Webkit, same web browser engine used by Qt
#
# cons:
# * seems slower than Firefox driver
# * harder to debug (can't put a breakpoint and take a look at web driver's
# browser, for instance)
#
# Firefox
# pros:
# * easier to debug (Firefox [and Chrome] already come with developer tools
# builtin nowadays)
#
# cons:
# * pops up a Firefox instance for each test
# * it is not the same web browser engine as used by Qt
#
# Tip: Use `--driver <driver_name>` to change driver for a single run
{% if TEST_QMXGRAPH %}
PYTEST_ADDOPTS: --driver PhantomJS
PYTEST_ADDOPTS: --driver Chrome
{% else %}
PYTEST_ADDOPTS: ""
{% endif %}
Expand All @@ -49,13 +29,13 @@ dependencies:
{% if TEST_QMXGRAPH %}
- conda-wrappers

- cherrypy==7.1.0
- phantomjs>=2.1
- cherrypy>=18.0.0
- pytest-mock>=1.4.0
- pytest-qt>=2.1.0
- pytest-selenium>=1.2.1,<2
- pytest-selenium>2
- pytest-timeout>=1.0.0
- pytest-xdist>=1.15
- selenium >=4.0.0, <4.10.0
{% if sys.platform != 'win32' %}
- pytest-xvfb
{% endif %}
Expand Down
Empty file removed tests/__init__.py
Empty file.
29 changes: 10 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from selenium.webdriver.chrome.options import Options as ChromeOptions


def pytest_configure(config):
Expand All @@ -22,25 +23,15 @@ def pytest_configure(config):


@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)
def chrome_options(chrome_options: ChromeOptions) -> ChromeOptions:
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
# Comment `--headless` and uncomment `--auto-open-devtools-for-tabs` to be
# able to debug the javascript from tests using selenium.
chrome_options.add_argument("--headless")
# chrome_options.add_argument("--auto-open-devtools-for-tabs")
return chrome_options


@pytest.fixture
Expand Down
5 changes: 2 additions & 3 deletions tests/test_js_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from tests.conftest import BaseGraphCase
from tests.conftest import GraphCaseFactory
from conftest import BaseGraphCase
from conftest import GraphCaseFactory


@pytest.fixture
Expand Down
8 changes: 4 additions & 4 deletions tests/test_qt_js_integration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import json
import re
import textwrap
from contextlib import nullcontext
from functools import partial

import pytest
import pytestqt.exceptions
from _pytest.compat import nullcontext
from PyQt5.QtCore import QByteArray
from PyQt5.QtCore import QDataStream
from PyQt5.QtCore import QIODevice
Expand All @@ -16,6 +15,7 @@
from PyQt5.QtGui import QDragMoveEvent
from PyQt5.QtGui import QDropEvent
from pytest_mock import MockFixture
from pytestqt.exceptions import TimeoutError as pytestqt_TimeoutError

import qmxgraph.constants
import qmxgraph.js
Expand Down Expand Up @@ -72,8 +72,8 @@ def check_call(expected):
with events.delaying_signals():
events.cells_added_slot(["2"])

with pytest.raises(pytestqt.exceptions.TimeoutError):
expected = [call(["1"]), call(["2"])]
expected = [call(["1"]), call(["2"])]
with pytest.raises((AssertionError, pytestqt_TimeoutError)):
qtbot.waitUntil(partial(check_call, expected), timeout=1000)

qtbot.waitUntil(partial(check_call, expected))
Expand Down

0 comments on commit 5cbe5a3

Please sign in to comment.