UI Testing using Selenium WebDriver and Chrome inside AWS Lambda

0 (10)


What is AWS Lambda?

Amazon explains, AWS Lambda (λ) as a ‘serverless’ compute service, meaning the developers, don’t have to worry about which AWS resources to launch, or how will they manage them, they just put the code on lambda and it runs, it’s that simple! It helps you to focus on core-competency i.e. App Building or the code.

Where will I use AWS Lambda?

AWS Lambda executes your backend code, by automatically managing the AWS resources. When we say ‘manage’, it includes launching or terminating instances, health checkups, auto scaling, updating or patching new updates etc.

So, how does it work?

The code that you want Lambda to run is known as a Lambda function. Now, as we know a function runs only when it is called, right? Here, Event Source is the entity which triggers a Lambda Function, and then the task is executed.

Where to use Lambda?

You can use it with multiple services

And also you can use it with Chatbot

Pricing in AWS Lambda

Like most of the AWS services, AWS Lambda is also a pay per use service, meaning you only pay what you use, therefore you are charged on the following parameters

  • The number of requests that you make to your lambda function
  • The duration for which your code executes.

* Source: AWS official website

How to use Selenium Webdriver and Chrome inside AWS Lambda?


  • We will use Chromium version 62 in headless mode
  • You need to have AWS Account , if you don’t have one you can your own account from this link


1- Login to AWS Management Console and Select AWS Lambda from Compute Services

2- Click on Create new a function

3- Select option Create from scratch (default select)

4- Add the function name and create new role and click on Create Button

5- Congratulation you create your first Lambda function

6- Select that you will upload the code from .zip folder

7- upload the file that you downloaded from this link


The code contains a node.js code that running selenium script using chrome in headless mode and get the page title from the url

'use strict';

exports.handler = (event, context, callback) => {
    var webdriver = require('selenium-webdriver');
    var chrome = require('selenium-webdriver/chrome');
    var builder = new webdriver.Builder().forBrowser('chrome');
    var chromeOptions = new chrome.Options();
    const defaultChromeFlags = [
        '--window-size=1280x1696', // Letter size'--no-sandbox',


    var driver = builder.build();
    driver.getTitle().then(function(title) {

        console.log("Page title for " + event.url + " is " + title)
        callback(null, 'Page title for ' + event.url + ' is ' + title);


8- In Basic setting section you need to increase the memory to the max value and also increase the timeout to be 5 min.

Then on Save button to upload your code and apply the changes

9- Wait the saving until the success status displayed

10 – Now we will add a Test event using a JSON file and add the url as a test data

11- Save your test event and click on Test button

Congratulation the test passed and the result will be the page title of the url that you are using

You can also Monitor the requests using AWS CloudWatch and all the logs info.




In Part 2 we will talking about

Testing at Scale with AWS Lambda

And Part 3 will be about

Using AWS CodePipeline, AWS CodeBuild, and AWS Lambda for Serverless Automated UI Testing

Good Luck and Happy Testing 🙂

We ♥ Automation Testing

AWS Lambda ♥ Selenium

One thought on “UI Testing using Selenium WebDriver and Chrome inside AWS Lambda

  1. hello, im unable to click any button after launching browser in lambda. Can you provide syntax to click button in nodejs script.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.