Skip to content

Minimal framework for web automation using selenium & pyautogui

Notifications You must be signed in to change notification settings

ayoubeddafali/sind

Repository files navigation


A minimal framework to automate web Actions/Plans, and run them in a containerized fashion.

build status

Structure

The project is composed of :

  • drivers/ : Contains the webdrivers for both chrome & firefox.
  • tests/ : Where you puts your tests.
  • downloads/ : An optional folder in case your selenium script will need to download/save something for the web.
  • Dockerfile.chrome : Dockerfile with necessary prerequisite for chrome browser.
  • main.py : Entry file.
  • Pipefile : Dev Packages.
  • plan.py : Example plan file.
  • start.sh : bash script used as entrypoint for the docker image.

Example Scenario

You will find in the current structure an example plan in the plan.py file.

You can start and override the file directly, or create your custom plans in separate files.

Don't forget to import your plan in the main.py file.

from plan import ExecutionPlan
..
..
..

executionPlan = ExecutionPlan(browser=driver, display=display, login=LOGIN, password=PASSWORD)
executionPlan.run(URL)

Development

While on development phase, you might need to run the plan locally and see your selenium script.

Make sure to have the following points marked.

  1. Install some tools :
$ sudo apt-get install -y xvfb xserver-xephyr
$ sudo apt-get install scrot -y
  1. Setup environment & dependencies
$ pip install pipenv 
$ make shell
$ make install
  1. Run your app :
$ make run

Run your tests

$ make test

Production

Once you've finished writing your scenario, you will then start by building a docker image :

$ IMAGE_TAG=custom_image:1.0  make image

And run it like :

$ docker run custom_image:1.0 
# Or 
$ docker run -v /tmp/screens:/home/agent/screenshots custom_image:1.0 
# Or
$ docker run -v /tmp/screens:/home/agent/screenshots -v /tmp/downloads:/home/agent/screenshots custom_image:1.0 
# You can also pass environments variables at runtime
# List can be found on the dockerfile

Available Tools :

  • selenium : Trivial
  • pyautogui : When selenium is no longer enough for slightly complex actions
  • pyscreenshot : To screen the execution state.

© 2020, Ayoub Ed-dafali.

forthebadge