Selenium tests

This topic describes how to use Selenium scripts in LoadRunner Enterprise performance tests.

Note:  

  • You do not need a license to run Selenium scripts, but this may change in future versions.

  • Java 7 is currently not supported for replaying Selenium scripts.

Selenium tests overview

Selenium is an umbrella project for a range of tools and libraries that enable and support the automation of web browsers. Refer to the product documentation for more details.

LoadRunner Enterprise supports the integration of Selenium test scripts in your performance tests. You can run one or more Selenium scripts alongside other LoadRunner Enterprise scripts in a performance test.

Selenium scripts can be run on both Windows and Linux load generators.

LoadRunner Enterprise can run the following Selenium test types (currently only .java extensions):

  • Simple Java file

  • JUnit

  • TestNG

  • TestNG with XML

Selenium script features

The following Selenium features have an impact on the test when Selenium scripts are run in LoadRunner Enterprise:

  • Annotations.

    For a simple Java file with a Main function, each run is considered a transaction. If the script is configured to Run Until Completion, only one transaction is seen. If it is run with a schedule, the number of transactions is equal to the number of iterations.

    For JUnit and TestNG scripts, a transaction is indicated by the annotation @Test. If a script is run once, the number of transactions is equal to the number of @Test annotations found in the script.

    Note: When uploading Selenium tests to LoadRunner Enterprise, LoadRunner Enterprise searches for “import org.openqa.selenium” in one of the Java files. This is an indication that the Java file class uses objects from a Selenium package. If this expression is not found, the Selenium test cannot be uploaded.

  • Headless execution

    To reduce memory consumption and improve the Selenium script run experience from the Controller, we recommend using the Headless option for Selenium scripts. Using this option, there is no visible browser opened during a test run.

    ChromeOptions options= new ChromeOptions();

    options.addArguments("--headless");

    driver = new ChromeDriver(options);

    Without this option, the number of browsers that are opened is equal to or greater than the number of running Vusers.

Back to top

Prerequisite setup for Selenium tests

Selenium scripts can be run on a load generator on a Windows operating system.

Tip: We recommend using a dedicated machine for Selenium script runs. Running several ChromeDriver or FirefoxDriver instances in parallel may be resource consuming.

To prepare your environment for running Selenium scripts:

  • If your Selenium tests can be run on your machine, LoadRunner Enterprise is also able to run the tests on a LoadRunner Enterprise host used as load generator.

  • Make sure the WebDriver environment variable is defined in your system (ChromeDriver or GeckoDriver depending on the browser).

  • If you add or change the WebDriver path environment variables (under Advanced System Properties > Environment Variables), you must restart the LoadRunner Load Testing service or restart your system so that it recognizes the new path.

  • LoadRunner Enterprise hosts can search and detect an installed JDK and use it to run the Selenium test. When designing a performance test in LoadRunner Enterprise, you can also define the JDK path to use for running the Selenium test. For supported JDK/JRE versions, see the Supported Protocols guide (available from Support Matrix).

  • The LoadRunner Enterprise installation contains the Selenium Server jar. If the Selenium script uses other dependencies (classpath, or TestNG XML), make sure to add them to the script's runtime settings, under the Selenium node. Upload TestNG XML with the script, and set the parameter value to the name of the file.

  • By default, LoadRunner Enterprise runs Selenium scripts under the system account because the browsers and the Selenium driver are run under the system account. If you cannot use the system account to run the script, you can reconfigure the LoadRunner Agent of the host used as a load generator with a specified user account, so that the Selenium script is run under this account instead. For details, see Configure the LoadRunner Agent.

Back to top

Use a Selenium script in a performance test

This task describes how to add your Selenium script to a LoadRunner Enterprise performance test.

Note: Network Virtualization is not supported for Selenium tests.

  1. Prerequisites:

    • Make sure the load generator machines are set up to run Selenium tests, as described in Prerequisite setup for Selenium tests.

    • For supported versions of Selenium, see the Supported Protocols guide (available from Support Matrix).

    • Create Selenium scripts and save the scripts locally. The scripts must be saved in .zip format and must include your Selenium files and all other dependencies in the root folder of the .zip file.

  2. Upload Selenium scripts to LoadRunner Enterprise

    For details, see Upload a script to LoadRunner Enterprise.

    After uploading the script to LoadRunner Enterprise, the script is added to the test management tree. You can view and edit most scripts directly from within the LoadRunner Enterprise user interface. For details, see Edit a script.

  3. Create a LoadRunner Enterprise test, and assign the Selenium script to it.

    For details, see Design a test.

  4. Configure Runtime settings

    If required by the script, enter the Classpath or XML files.

    1. Select the test in the test management tree and click Edit Test.

    2. In the Groups and Workload view, select the Selenium script and click the Edit Runtime Settings button .

    3. In the Selenium tab of the Runtime Settings dialog box, enter the Classpath or XML files.

  5. Schedule the test.

    Scenario settings are defined within the Selenium script. The following settings can be defined in the Global Schedule:

    • Duration: Set to Run until completion. Recommended setting.

    • Start Vusers. When choosing this option, we recommend to use a limited number of Vusers.

      Note: Using Selenium together with WebDriver for performance testing is not recommended. Instead, use the dedicated Web or DevWeb protocols.

  6. Run the test.

    For details, see Manage a performance test run.

    Data points from Selenium tests are displayed in the LoadRunner Enterprise graphs. For details, see View Selenium test results.

Back to top

Sample Selenium script

In the sample file you can see:

  • The test runs with headless arguments.

  • The test runs for 2 minutes.

  • Each iteration contains 2 @Test annotations => 2 transactions

Copy code
// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeOptions;

public class Testrec1Test {
  private WebDriver driver;
  private Map<String,
  Object> vars;
  JavascriptExecutor js;

  @Before
  public void setUp() {
    /* driver = new ChromeDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>(); */

      ChromeOptions options= new ChromeOptions();
      options.addArguments("--headless");
      driver = new ChromeDriver(options);
      js = (JavascriptExecutor) driver;
      vars = new HashMap<String, Object>();
  }
  @After
  public void tearDown() {

    driver.quit();
  }
  @Test
  public void test1() {
    // Test name: test1
    // Step # | name | target | value
    // 1 | open | / |
    driver.get("http://Your_page.com");
    // 2 | setWindowSize | 1050x863 |
    driver.manage().window().setSize(new Dimension(1050, 863));
    // 3 | click | linkText=Example 1 |
    driver.findElement(By.linkText("Example 1")).click();
    // 4 | click | name=entry |
    driver.findElement(By.name("entry")).click();
    // 5 | type | name=entry | test
    driver.findElement(By.name("entry")).sendKeys("test");
    // 6 | click | css=p > input |
    driver.findElement(By.cssSelector("p > input")).click();
    // 7 | click | css=body |
    driver.findElement(By.cssSelector("body")).click();
    // 8 | click | css=body |
    driver.findElement(By.cssSelector("body")).click();
      //close in function
      driver.close();
      }

      @Test
      public void empty_function(){
      //dummy test
      }
}

Back to top

View Selenium test results

Selenium scripts produce results that are displayed in the following standard graphs:

  • Running Vusers

  • Transaction Response Time

  • Total Transactions per second (Passed)

  • Transactions per second (Passed)

The standard Throughput graph does not display results from Selenium scripts. Customized graphs cannot be generated from Selenium script results.

For graph details, see Runtime monitor graphs and Transaction monitor graphs.

Back to top

Notes and limitations

The only SLA measurement supported for a group defined with a Selenium script is Errors per Second when the Running Vusers load criterion is selected.

Back to top

See also: