Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Python3, Selenium, Docker boilerplate for Test Automation projects.

License

Notifications You must be signed in to change notification settings

radiotaiso/python-test-automation-boilerplate

Repository files navigation

Test automation Boilerplate

Python + unittest + selenium = <3

Prerequisites

  • Python 3
  • Selenium (already in requrements.txt)
  • Virtualenvironment
  • Docker

Local setup

  1. Install python3
  2. Install virtualenv
$ pip3 install virtualenv
  1. Create a new virtualenv
$ virtualenv -p python3 your_env_name # env name can be anything
  1. Start the environment
$ source your_env_name/bin/activate
  1. Install dependencies in requirements.txt
$ pip install -r requirements.txt
  1. Install Chromedriver
$ wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
$ unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
  1. You're done!

Run the tests locally

All you need to do is:

python -m unittest

The unittest module can also be used from the command line to run single or multiple tests.

python -m unittest test1
python -m unittest test_module.TestClass
python -m unittest test_module.TestClass.test_method

Keep in mind that the files containing your tests need to be named test_{whatever} so it can be found by unit test, else you would have to pass the filename as an argument.

Run the tests using Docker

You have to build the image first

docker build . -t python-automation # you can name your image anything you want just remember it.

run it!

docker run -it python-automation

Troubleshooting

Common error #1

ImportError: Import by filename is not supported. is caused by not using python3, most systems come pre-bundled with python2 You can make sure you have the right python version with

$ python --version

You might need to run commands using python3 try:

$ which python3

and it should have a path to your virtualenv python installation.

Common error #2

ModuleNotFoundError: No module named 'selenium'

You don't have not installed selenium dependency in your virtualenv or your system. Make sure you follow the setup guide.