Have you ever felt annoyed because of the long waiting time for receiving test results? Maybe after a few hours, you’ve figured out that there had been a network connection issue in the middle of testing, and half of the results can go to the trash? That may happen when your tests are dependent on each other or when you have plenty of them and execution lasts forever. It’s quite a common issue. But there’s actually a solution that can not only save your time but also your money – parallelization in the Cloud.

How It Started

Developing UI tests for a few months, starting from scratch, and maintaining existing tests, I found out that it has become something huge that will be difficult to take care of very soon. An increasing number of test scenarios made every day led to bottlenecks. One day when I got to the office, it turned out that the nightly tests were not over yet. Since then, I have tried to find a way to avoid such situations.

A breakthrough was the presentation of Tomasz Konieczny during the Testwarez conference in 2019. He proved that it’s possible to run Selenium tests in parallel using AWS Lambda. There’s actually one blog that helped me with basic Selenium and Headless Chrome configuration on AWS. The Headless Chrome is a light-weighted browser that has no user interface. I went a step forward and created a solution that allows designing tests in the Behavior-Driven Development process and using the Page Object Model pattern approach, run them in parallel, and finally – build a summary report.

Setting Up the Project

The first thing we need to do is signing up for Amazon Web Services. Once we have an account and set proper values in credentials and config files (.aws directory), we can create a new project in PyCharm, Visual Studio Code, or in any other IDE supporting Python. We’ll need at least four directories here. We called them ‘lambda’, ‘selenium_layer’, ‘test_list’, ‘tests’ and there’s also one additional – ‘driver’, where we keep a chromedriver file, which is used when running tests locally in a sequential way.

In the beginning, we’re going to install the required libraries. Those versions work fine on AWS, but you can check newer if you want.

requirements.txt

allure_behave==2.8.6

behave==1.2.6

boto3==1.10.23

botocore==1.13.23

selenium==2.37.0

What’s important, we should install them in the proper directory – ‘site-packages’.

installing in proper directory: site packages

We’ll need also some additional packages:

Allure Commandline (download)

Chromedriver (download)

Headless Chromium (download)

All those things will be deployed to AWS using Serverless Framework, which you need to install following the docs. The Serverless Framework was designed to provision the AWS Lambda Functions, Events, and infrastructure Resources safely and quickly. It translates all syntax in serverless.yml to a single AWS CloudFormation template which is used for deployments.

Architecture – Lambda Layers

Now we can create a serverless.yml file in the ‘selenium-layer’ directory and define Lambda Layers we want to create. Make sure that your .zip files have the same names as in this file. Here we can also set the AWS region in which we want to create our Lambda functions and layers.

serverless.yml

service: lambda-selenium-layer

provider:

  name: aws

  runtime: python3.6

  region: eu-central-1

  timeout: 30

layers:

  selenium:

   path: selenium

   CompatibleRuntimes: [

    "python3.6"

   ]

  chromedriver:

   package:

    artifact: chromedriver_241.zip

  chrome:

   package:

    artifact: headless-chromium_52.zip

  allure:

   package:

    artifact: allure-commandline_210.zip

resources:

  Outputs:

   SeleniumLayerExport:

    Value:

     Ref: SeleniumLambdaLayer

    Export:

     Name: SeleniumLambdaLayer

   ChromedriverLayerExport:

    Value:

     Ref: ChromedriverLambdaLayer

    Export:

     Name: ChromedriverLambdaLayer

   ChromeLayerExport:

    Value:

     Ref: ChromeLambdaLayer

    Export:

     Name: ChromeLambdaLayer

   AllureLayerExport:

    Value:

     Ref: AllureLambdaLayer

    Export:

     Name: AllureLambdaLayer

Within this file, we’re going to deploy a service consisting of four layers. Each of them plays an important role in the whole testing process.

#aws #aws lambda #qa and software testing #serveless

How to Run Selenium BDD Tests in Parallel with AWS Lambda
3.60 GEEK