diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 87163a9f4..c4c532af4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,10 +13,48 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: + runs-on: ubuntu-latest + + strategy: + matrix: + include: + - PY_VER: py37 + python-version: 3.7 + - PY_VER: py38 + python-version: 3.8 + - PY_VER: py39 + python-version: 3.9 + - PY_VER: py310 + python-version: "3.10" + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: ${{matrix.python-version}} + + - name: Install test dependencies + run: pip install tox + + # Lint before running unit tests + - name: Run lint + run: tox -e lint + + - name: Run tests + run: | + tox -e tests -- -n 4 tests/test_browser.py tests/test_element_list.py tests/test_request_handler.py tests/test_xpath_concat.py + + - name: Run non-webdriver driver tests + run: | + tox -e tests -- -n 4 tests/test_flaskclient.py tests/test_zopetestbrowser.py tests/test_djangoclient.py tests/test_is_element_present_nojs.py + + # This workflow contains a single job called "build" + selenium3: # The type of runner that the job will run on # Java, Chrome, chromedriver, Firefox, geckodriver are installed by default on this machine. runs-on: ubuntu-latest @@ -52,25 +90,17 @@ jobs: run: | wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.3.0/selenium-server-4.3.0.jar -O selenium-server.jar - # Lint before running unit tests - - name: Run lint - run: tox -e lint - - name: Run Selenium Remote tests run: | echo "Start Selenium Server" xvfb-run java -jar selenium-server.jar standalone > selenium-server.log 2>&1 & timeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-server.log && exit 2) echo "Selenium server is ready, running tests" - tox -e tests -- tests/test_webdriver_remote.py - - - name: Run non-driver tests - run: | - tox -e tests -- -n 4 tests/test_is_element_present_nojs.py tests/test_browser.py tests/test_djangoclient.py tests/test_element_list.py tests/test_flaskclient.py tests/test_zopetestbrowser.py tests/test_request_handler.py tests/test_xpath_concat.py + tox -e tests_selenium3 -- tests/test_webdriver_remote.py - name: Run Selenium tests run: | - tox -e tests -- -n 4 tests/test_element_is_visible.py tests/test_screenshot.py tests/test_mouse_interaction.py tests/test_async_finder.py tests/test_html_snapshot.py tests/test_iframes.py tests/test_popups.py tests/test_webdriver.py tests/test_webdriver_firefox.py tests/test_webdriver_chrome.py; + tox -e tests_selenium3 -- -n 4 tests/test_element_is_visible.py tests/test_screenshot.py tests/test_mouse_interaction.py tests/test_async_finder.py tests/test_html_snapshot.py tests/test_iframes.py tests/test_popups.py tests/test_webdriver.py tests/test_webdriver_firefox.py tests/test_webdriver_chrome.py; selenium4: runs-on: ubuntu-latest diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d88f9c7d6..e960e2057 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -42,7 +42,7 @@ jobs: - name: Run tests for windows-only drivers run: | - tox -e tests_windows -- -n 4 tests/test_webdriver.py tests/test_popups.py tests/test_webdriver_edge_chromium.py; + tox -e tests_windows_selenium3 -- -n 4 tests/test_webdriver.py tests/test_popups.py tests/test_webdriver_edge_chromium.py; selenium4: runs-on: windows-latest diff --git a/setup.py b/setup.py index aff7927e4..b2f597286 100644 --- a/setup.py +++ b/setup.py @@ -50,14 +50,16 @@ def get_version_data() -> dict: }, packages=find_packages(exclude=["docs", "tests", "samples"]), include_package_data=True, - install_requires=[], + install_requires=[ + "urllib3 >=1.26.14,<2.0" + ], extras_require={ "zope.testbrowser": ["zope.testbrowser>=5.5.1", "lxml>=4.2.4", "cssselect"], "django": ["Django>=2.0.6", "lxml>=4.2.4", "cssselect"], "flask": ["Flask>=2.0.2", "lxml>=4.2.4", "cssselect"], "edge": ["msedge-selenium-tools"], "selenium3": ["selenium>=3.141.0,<4.0"], - "selenium4": ["selenium>=4.1.0,<5.0"], + "selenium4": ["selenium>=4.1.0,<4.2.0"], }, tests_require=["coverage", "flask"], ) diff --git a/tests/base.py b/tests/base.py index d36e5c7df..b26c4a3d0 100644 --- a/tests/base.py +++ b/tests/base.py @@ -8,7 +8,11 @@ import pytest -from selenium.common.exceptions import WebDriverException +try: + from selenium.common.exceptions import WebDriverException +except ModuleNotFoundError: + pass + from .click_elements import ClickElementsTest from .cookies import CookiesTest diff --git a/tests/get_browser.py b/tests/get_browser.py index c70ef1091..46e9462ed 100644 --- a/tests/get_browser.py +++ b/tests/get_browser.py @@ -1,7 +1,11 @@ import os from urllib import parse -from selenium import webdriver +# Catch for when non-webdriver set of tests are run. +try: + from selenium import webdriver +except ModuleNotFoundError: + pass from splinter import Browser diff --git a/tests/test_browser.py b/tests/test_browser.py index e5cb16246..53ddd6b25 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -10,8 +10,6 @@ from splinter.exceptions import DriverNotFoundError -from selenium.common.exceptions import WebDriverException - import pytest @@ -70,17 +68,6 @@ def test_browser_should_raise_an_exception_when_driver_is_not_found(): Browser("unknown-driver") -@pytest.mark.parametrize('browser_name', ['chrome', 'firefox']) -def test_browser_local_driver_not_present(browser_name): - """When chromedriver/geckodriver are not present on the system.""" - from splinter import Browser - - with pytest.raises(WebDriverException) as e: - Browser(browser_name, executable_path='failpath') - - assert "Message: 'failpath' executable needs to be in PATH." in str(e.value) - - def test_browser_driver_retry_count(): """Checks that the retry count is being used""" from splinter.browser import _DRIVERS @@ -117,7 +104,8 @@ def test_browser_log_missing_drivers(caplog): reload(browser) unpatch_driver(browser, old_import) - assert 1 == len(caplog.records) - record = caplog.records[0] - assert record.levelname == 'DEBUG' - assert 'Import Warning' in record.message + assert 7 == len(caplog.records) + for i in range(0, 6): + record = caplog.records[i] + assert record.levelname == 'DEBUG' + assert 'Import Warning' in record.message diff --git a/tests/test_webdriver.py b/tests/test_webdriver.py index a5f55f90b..fc7c5715c 100644 --- a/tests/test_webdriver.py +++ b/tests/test_webdriver.py @@ -1,5 +1,7 @@ import os +from selenium.common.exceptions import WebDriverException + from .base import supported_browsers from .get_browser import get_browser from .fake_webapp import EXAMPLE_APP @@ -7,6 +9,17 @@ import pytest +@pytest.mark.parametrize('browser_name', ['chrome', 'firefox']) +def test_webdriver_local_driver_not_present(browser_name): + """When chromedriver/geckodriver are not present on the system.""" + from splinter import Browser + + with pytest.raises(WebDriverException) as e: + Browser(browser_name, executable_path='failpath') + + assert "Message: 'failpath' executable needs to be in PATH." in str(e.value) + + @pytest.mark.parametrize('browser_name', supported_browsers) def test_attach_file(request, browser_name): """Should provide a way to change file field value""" diff --git a/tox.ini b/tox.ini index 0a3af5be8..0bf2ef565 100644 --- a/tox.ini +++ b/tox.ini @@ -6,13 +6,18 @@ exclude = [testenv:tests] -extras = selenium3, zope.testbrowser, django, flask +extras = zope.testbrowser, django, flask deps = -rrequirements/test.txt commands= pytest -v {posargs} +[testenv:tests_selenium3] +extras = selenium3 +deps = -rrequirements/test.txt +commands= + pytest -v {posargs} -[testenv:tests_windows] +[testenv:tests_windows_selenium3] extras = selenium3, edge deps = -rrequirements\test_windows.txt