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 testLarge 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-parallelto run tests concurrently. You can change the level of concurrency (--tests-per-worker) intasks.py. seleniumfor Python doesn't use thread-safe requests by default, so running all the tests in the same thread withpytest-parallelcauses flakiness. To ensure thread safety,tests/webdriver_monkey_patch.pyis imported intests/conftest.pyuntil the official package supports thread-safe requests.
MIT