Load Testing with Selenium

This tutorial demonstrates how existing Selenium automation tests can be modified into developed load tests using Step.

25%
More revenue
80x
Better performance
45%
Less maintenance
In all areas of the bank and across all products, we have intelligent automation. These intelligent processes increase both employee and customer satisfaction.”
Denisa Skantova
|
Denisa Skantova

In this short tutorial, we will demonstrate how existing Selenium automation tests can be turned into completely developed load tests in just a few minutes, by leveraging the Step platform.

Prerequisites

  • Step: You can either install Step Enterprise or OS following the quick setup guide or get a SaaS instance up and running in minutes. For most users the SaaS option is recommended, you can get it easily up and running on stepcloud.ch.
  • Git
  • Maven

Hint: The optional software is recommended to follow the local parts of this tutorial. You can skip all steps requiring ChromeDriver and still finish the tutorial if you are only following the SaaS solution.

Preparing the sample project

We have prepared a sample project that will be used throughout this tutorial which uses Selenium to automate interactions with a test environment called OpenCart that is provided by us.

1. Get the code 

The project is available on GitHub; to clone it using git, run:

git clone https://github.com/exense/demo-opencart-selenium.git
2. (optional) Run tests locally, requires ChromeDriver

To see the interactions that are performed, run the JUnit tests:

cd demo-opencart-selenium

# If ChromeDriver is installed system-wide and added to the path:
mvn clean compile test

# Otherwise, explicitly specify the ChromeDriver path:
mvn clean compile test -Dwebdriver.chrome.driver=c:/tools/chromedriver/chromedriver.exe

The test cases navigate automatically through the “Desktop” and “Components” categories of OpenCart, as defined in the unit tests.

3. Check the source code 

Take a moment to look at the sample project code – we tried to keep it as simple and straightforward as possible.

You’ll notice that the test class (SiteTest.java) is really just a standard JUnit class, with only two changes:

  • First, the individual test methods carry an additional @step.handlers.javahandler.Keyword annotation. These annotations make the respective methods available as Keywords within Step.
  • Second, the test class itself extends the class step.handlers.javahandler.AbstractKeyword. This is a technical requirement that ensures that Step can actually use the Keyword methods.

These modifications are sufficient for the provided functionality to be used for load tests in the Step framework.

4. Create a Keyword Package 

To package the functionality in a jar file, run:

mvn clean package -DskipTests

This creates a file, named demo-opencart-selenium-0.0.0.jar, in the "target" folder of the project directory. This is the file that we will use in the subsequent steps.

Switch to your Step instance

If you have access to an existing Step instance (on-premise or cloud), access it and log in, see prerequisits if not. Remember that for on-premise setup Chrome and Chromedriver must be available on the Step’s agents.

1. Import the keyword package

Step has a special view for managing Keywords. This screenshot shows the Keywords view with the Upload Package dialog open as a reference for the next steps.

  1. Navigate to Keywords
  2. Click the Upload Package button
  3. Select the demo-opencart-selenium-0.0.0.jar as the package file
    Hint: Make sure you selected the correct file. If sucessfull you will see two keywords listed.
  4. Click Save to do the import
2. Define the load test

Now that all the basics are established, we can define an actual load test. This is done in Step with plans.

  1. Navigate to Plans
  2. Click + to create a new plan
  3. Enter a name
  4. Select "TestScenario" as a Template
  5. Click Save and edit
3. Configure the plan

The visual editor is the main tool in to create and edit plans in Step. We will use this to create the load testing scenario, so get familiar with the UI explained in this screenshot:

For our load test we will create a thread group that will repeatedly execute a task on OpenCart to simulate high loads.

  1. Add a ThreadGroup child to the plan by clicking the + next to "ThreadGroup" in Controls in the Component tabs.
    Hint:
    Filter the components to easily find your controls.
  2. In the thread group, the action to be performed is added by selecting it from Keywords in the Component tabs.
  3. Configure each ThreadGroup with the following parameters:
  • Number of Threads: 10 So the ThreadGroup runs 10 threads in parallel.
  • Number of iterations per thread: (empty): There should not be a limit on the number of iterations per thread;
  • Maximum duration (ms): 600000: The ThreadGroup should terminate after a maximum of 10 minutes (600000 ms).

Note: Find out more about the ThreadGroup configuration in the documentation: ThreadGroup.

After this your tree should look like this and the ThreadGroup should contain this configuration

4. Run the load test

To run the load test, simply click the start execution button (play icon) on top of the plan and confirm by clicking it in the dialog again.

NOTE: As the ThreadGroup was configured to use 10 threads, and there is only one ThreadGroup running in parallel, the total number of parallel threads is 10. This, in turn, means that 10 agents must be available concurrently for this scenario to run successfully.

If you have less than 10 agents in your cluster, the execution will make use of the available agents, but parts of the plan will fail because the required resources cannot be allocated.

To set the needed number of agents follow the installation guide for Step on-premise Installing agents or go to the cluster details in the Step Portal and set the browser-java agents to 10 for Step SaaS.

5. Check the status of your executions on the “Executions'' tab.

The execution automatically opens, you can continue using Step and go to Executions in the menu and click on an individual execution to get a detailed view of that execution to open it again.

Hint: This can be done at any time, including when an execution is currently running

Status for a successfully finished execution

6. Analyze the performance

By selecting the "Performance” tab you will get a visualization of the executions performance. There you can see if the System Under Test, in our case OpenCart, can handle the amount of load we tested it with.

What do you want to do?

Step can take care of many challenges in the full development cycle. Easily get started by selecting your use case.

Type of task
1 / 2
Previous

Want to hear our latest updates about automation?

Don't miss out on our weekly blog posts - Subscribe now!