• linford copeland

Executing Selenium tests remotely from AWS with Sauce Labs

Executing UI tests from AWS presents a challenge with the execution environment. You'll need to decide whether you standup up an execution server with AWS that has a browser to run the tests 'locally', or choose to execute the tests against a remote environment like Sauce Labs?


In this post we'll show you how to integrate your Selenium tests into the AWS CodePipeline we have built over the last couple of blog posts. We'll integrate Sauce Labs into the project, outsourcing the test execution environment.


If like us your using a Java project for your Selenium tests you can find how to guides with demo examples https://wiki.saucelabs.com/display/DOCS/Java+Test+Setup+Example and https://github.com/saucelabs-training/demo-java.


Like the previous posts this is not a how to for java, selenium, Sauce Labs or Cucumber, the aim with this is to help you move your test automation efforts to a cloud testing context, using the native services AWS provides.


So to begin with you'll need to integrate your framework with Sauce Labs, we've done it in the example below by initialising a remote webdriver with our Sauce Labs url and the Capabilities we need to pass in.



Next up we need to create a buildspec.yml so CodeBuild knows what to do. Makes sense to us to store this with the UI automation project you're executing. We have a simple example below for what we've used in our example project that build with Maven.



Next up we need to amend the petstore-api-pipeline.yaml file (or whatever you have called your CodePipeline definition) to include the Selenium project. As its stored in a seperate repo we'll start off by adding a parameter definition, so we can pass the repo name into the CloudFormation CLI command that creates the pipeline.





Next up we'll add the section that CodeBuild uses to build the environment, passing in the repo parameter name created in the previous step.




As before we'll add another step to the Source stage of the pipeline definition to checkout the Selenium project from the repo we passed in, remembering to change the name of the artifact produced so you can the artifact into the pipeline action that defines when the project is built and tests ran.


Finally we'll add in the pipeline action to run the selenium tests, using the OutputArtifact name created in the checkout step as the input.




Now we're ready to run the CloudFormation command used to trigger the pipeline creation. We need to add the following to the command to pass in the repo details for the Selenium project


ParameterKey=<REPLACE_ME_GITHUB_SELENIUM_REPO_NAME>,ParameterValue=<REPLACE_ME_GITHUB_REPO> \



When you've run the CloudFormation command you'll see the checkout step added to the pipeline, like the screen shot below.




You'll also see the step that builds the Selenium project and runs the tests. In the example below we have a failing pipeline step as we have a failing test!



You can check out the CodeBuild logs to see console logs for the project build, in this case telling us the Cucumber tests ran



Over in our Sauce Labs account we can see that the Test Results of that test run.


We're hoping that after this short series of blogs you have the started of a pattern for integrating your automated tests into a AWS code build/deploy/test pipeline, enabling you and your team to get super fast feedback! We've given some examples of integrating tests written in different tools and languages for two layers of the pyramid (API and UI), executing either locally in AWS or remotely in Sauce Labs.


If you have any questions, queries or comments on this topic or anything relating to test automation, please reach out to us at info@loupetestware.com


Thanks for reading!

07791 754044

The TechnoCentre, Coventry University Technology Park, Puma Way, Coventry CV1 2TT, UK

  • LinkedIn
  • Twitter

©2020 Loupe Testware - All Rights Reserved | Registered & England and Wales - Company No. 11407097 - VAT No. 303875406 | Privacy Policy