Selenium scripts in LoadRunner Cloud

LoadRunner Cloud supports Selenium, an open-source load testing framework.

Note: You can only run Selenium scripts on cloud-based load generators—not on on-premises load generators.

General requirements

Make sure that your environment meets the following requirements:

Tool Version
Selenium 4.1.0
Browser

Chrome 95

JUnit 4.13.2
Mocha 9.1.3

Back to top

Prepare Selenium scripts using JUnit

Before you upload your Selenium script that uses JUnit, make sure that your environment meets the General requirements.

Preparing a script for uploading

These steps describe how to prepare your Selenium script for its upload to the LoadRunner Cloud repository.

  1. Create a storm.properties file that defines an execution type and entry point.

    The file is a standard Java properties file (key/value pairs). For example:

    execution=Selenium
    runner=junit
    entrypoint=scratch.UnitTestSample
    transactions=scratch.UnitTestSample.baseTest1,scratch.UnitTestSample.baseTest2
    Key Description
    execution The execution engine type for the script.
    runner The name of the testing framework. By default, the runner is junit.
    entrypoint The entry for the testing framework. The entry point is the full class name of the Junit test entry . In the above example, it is scratch.UnitTestSample.
    transactions

    A list of transaction names, separated by commas, which are displayed on the Load tests > SLA page.

    Transaction names are in the format: <package name>.<class name>.<test method name>.

  2. Create a .zip file that contains the storm.properties file, your Selenium script (.jar) files and all other dependencies. The storm.properties file and the *.jar files must be located in the root folder of the .zip file.

    Tip:  

    • The required JUnit and Selenium frameworks are already deployed in LoadRunner Cloud. You do not need to include these frameworks in the .zip file.
  3. Alternatively, if your JUnit test code is simple and you do not have a tool to build it as .jar file, you can specify a .java file name in the sources field in storm.properties. Then, create a .zip file to include both the .java and storm.properties files. LoadRunner Cloud compiles the .java file before running the test.

    For example:

    execution=Selenium

    runner=junit

    entrypoint=MyChromeTest

    sources=MyTest.java

Back to top

Transaction definitions - JUnit

Transactions defined in the storm.properties file appear in the Load tests > SLA page.

Transactions are defined in the JUnit test framework and transaction names are in the format: <test class full name>.<test method>.

In addition, all tests in your Selenium script are reported as transactions.

Transaction names example:

Transactions are: “scratch.UnitTestSample.baseTest1” and “scratch.UnitTestSample.baseTest2”

transactions=scratch.UnitTestSample.baseTest1,scratch.UnitTestSample.baseTest2

JUnit Test java class example:

package scratch;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;

public class UnitTestSample {
  private WebDriver driver;
  @Before
  public void setUp() {
    driver = new ChromeDriver();
  }
 @After
  public void tearDown() {
    driver.quit();
  }
  @Test
  public void nodejs() {
    driver.get(https://nodejs.org/en/);
    driver.manage().window().setSize(new Dimension(1525, 813));
    driver.findElement(By.cssSelector(".list-divider-pipe > li:nth-child(4) > a")).click();
    driver.findElement(By.linkText("Guides")).click();
    driver.findElement(By.cssSelector(".list-divider-pipe > li:nth-child(2) > a")).click();
  }
  @Test
  public void baseTest1() {
      // The test method
  }
  
  @Test
  public void baseTest2() {
      // The test method
  }    
}

Back to top

Prepare Selenium scripts using Mocha

Before you upload your Selenium script that uses Mocha, make sure that your environment meets the General requirements.

Preparing a script for uploading

This section describes how to prepare your Selenium script for its upload to the LoadRunner Cloud repository.

  1. Create a storm.json file that defines an execution type and transactions. For example:

    {
        "execution": "Selenium",
        "runner": "mocha",
        "transactions": ["sample - test item 1", "sample - test item 2"]
    }
    
  2. Create an npm package that contains the storm.json file. For details on creating an npm package, see https://docs.npmjs.com/cli/pack.

  3. Upload the npm package (which is a .tgz file ) to LoadRunner Cloud.

    Tip: The required Mocha and Selenium frameworks are already deployed in LoadRunner Cloud. You do not need to include these frameworks in the .tgz file.

Back to top

Transaction definitions - Mocha

Transactions defined in the storm.json file appear in the Load tests > SLA page.

Transactions are defined in the Mocha test framework and transaction names are in the format: <test suite name>-<test item name>.

The example below includes one transaction called sample - test item:

describe('sample', function() {
     it('test item', function(done) {
        const driver = new Builder().forBrowser('chrome').build();
        setTimeout(() => {
            driver.get('https://software.microfocus.com');
            driver.quit();
            done();
         }, 1000);
     });
});

Back to top