This repo shows the fastest way to run WebDriver with pytest
- Python 3.6+
- Pipenv
- a tunnel - ngrok, localtunnel, serveo
# Clone the repo
git clone [email protected]:browsertron/pytest-webdriver-example.git
cd pytest-webdriver-example
pipenv install
# Generate Tests
pipenv run generate
# The app server is started for you in the background with `pipenv run app`
pipenv run test
Large suites can be run much quicker when the browsers are created remotely. To configure remote execution:
- Add a REMOTE_WEBDRIVER environment variable. This snippet uses Browsertron, but you can use any remote service you like.
~/.bash_profile export REMOTE_WEBDRIVER='https://token:[email protected]/wd/hub'
- Start a tunnel with ngrok, localtunnel, or serveo against port 8000
ngrok http 8000
- In another terminal, start the tests
pipenv run test --remote --url=YOUR_TUNNEL_URL
To create large test suites, we generate tests from templates in tests/
. The template tests/webdriver.template.py
has one template parameter {{num}}
. If you change any template, or want a larger test suite, run pipenv run generate
.
# Generate the desired number of tests (the default is 20)
pipenv run generate 25
- This example uses
pytest-parallel
to run tests concurrently. You can change the level of concurrency (--tests-per-worker
) intasks.py
. selenium
for Python doesn't use thread-safe requests by default, so running all the tests in the same thread withpytest-parallel
causes flakiness. To ensure thread safety,tests/webdriver_monkey_patch.py
is imported intests/conftest.py
until the official package supports thread-safe requests.
MIT