AWS Device Farm for Selenium

AWS Device Farm for Selenium article created when amazon announced support to Selenium Remote Web Driver. Now we have another company that we can use for remote test execution. In this article, I will explain how to execute your test on AWS by changing few lines of code in your automation project.

I think it’s major news that AWS gets into this business. Most of the cloud testing companies host their services on AWS, Azure kinda cloud systems, and now AWS is in the same business with its full strength. They have the power of S3 to host videos, they have the cloud instance to execute the test and they can give you this service at a very cheap price. Now according to their pricing, if you execute 1.000 minutes of the test, you will pay 1.5$. It’s incredible…

Let’s run our first case in AWS.

In this example, I will use the sample project and convert it to AWS.

Install AWS CLI

First of all, you need to have AWS CLI installed in your environment. As a prerequisite, you need to have Python 2.7+ or 3+ in your environment.  Now let’s run the below command in the terminal.

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Then you should execute the below command so every user on your computer can access AWS CLI in the terminal.

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Finally, type the below code to check if AWS CLI is working properly or not.

aws --version

Create AWS Account

You should create an AWS account and set up your AWS Access Key ID and AWS Secret Access Key by following this link. After you create your ID and Secret Key, execute the below command.

aws configure

It will ask you to enter the credentials that you got from the previous steps. Just enter those keys.

canberkakduygu@canberks-MacBook-Pro IdeaProjects % aws configure
AWS Access Key ID [None]: AKIAJYXGQ3MKQVCFSDsHWS2A
AWS Secret Access Key [None]: +8G+kgX/tmOsd/R9Hjawew+iNFoK+w6N8hx8AYoxHbp5

Finally, it will ask you to enter an AWS region. Type us-west-2 or any other region. The region may change according to your Amazon account.

Create a Project in AWS

Go to https://console.aws.amazon.com/ and create a Desktop Browser testing project. You can check out the supported browsers and environments via this link. After you create your project, you will your project arn.

aws-desktop-sessions

Modify Test Project

All you need to do is to configure the code snippet where you configure your RemoteWebDriver. In the sample project that we use, we create the RemoteWebDriver like this.

@BeforeMethod
@Parameters(value={"browser"})
public void setup (String browser) throws MalformedURLException {
        //Set Browser to ThreadLocalMap
        driver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilityFactory.getCapabilities(browser)));
}

Now we change it as below

 @BeforeMethod
    @Parameters(value={"browser"})
    public void setup (String browser) throws MalformedURLException {
        //Set Browser to ThreadLocalMap
        String projectARN = "YOUR_PRIVATE_ARN_KEY";
       DeviceFarmClient client  = DeviceFarmClient.builder()
                .region(Region.US_WEST_2)
                .build();
        CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()
                .expiresInSeconds(200)
                .projectArn(projectARN)
                .build();
        CreateTestGridUrlResponse response = client.createTestGridUrl(request);
        URL testGridUrl = new URL(response.url());
        driver.set(new RemoteWebDriver(testGridUrl, capabilityFactory.getCapabilities(browser)));
    }

Now, execute your tests…

You will see that test results will appear in the device farm console in a minute.

aws-device-farm-browsers

GitHub Project

You can access the source code via this link.

Happy testing!

3 thoughts on “AWS Device Farm for Selenium”

  1. Canberk Akduygu, Thank you for sharing. Could you please help me with the maven dependencies ? I’m getting error ‘DeviceFarmClient cannot be resolved to a type’.

    I tried importing below, but getting error ‘software ‘ is not recognized
    import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.devicefarm.*;
    import software.amazon.awssdk.services.devicefarm.model.*;

    Reply

Leave a Comment

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