Skip to content

Commit

Permalink
Fix missing urllib3 dependency (#1123)
Browse files Browse the repository at this point in the history
* Fix missing urllib3 dependency
+ Tweak CI to run WD and non-WD tests separately. This better reflects
  real world environments.
  • Loading branch information
jsfehler committed Jan 17, 2023
1 parent 4ada941 commit 3d2502e
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 35 deletions.
52 changes: 41 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
6 changes: 5 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/get_browser.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 5 additions & 17 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

from splinter.exceptions import DriverNotFoundError

from selenium.common.exceptions import WebDriverException

import pytest


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions tests/test_webdriver.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
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

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"""
Expand Down
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d2502e

Please sign in to comment.