Selenium tests

This topic describes how to use Selenium scripts in Controller scenarios.

Note:  

  • Use of Selenium scripts is provided as a tech preview feature.
  • You do not need a license to run Selenium scripts in Controller, 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. For details, see the Selenium documentation.

LoadRunner Professional supports integration of Selenium (currently only .java extensions) test scripts in your scenarios. You can run one or more Selenium scripts alongside any other LoadRunner Professional protocol script in a scenario.

LoadRunner Professional can execute the following Selenium test types:

  • Simple Java script
  • JUnit script
  • TestNG
  • TestNG with XML

Selenium scripts have the following features:

Annotations

For Simple Java script with a Main function, each execution is considered a transaction. If the script is configured to Run Until Completion, only one transaction will be seen. If it is executed with a schedule, the number of transactions will be equal to the number of iterations.

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

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 test execution.

ChromeOptions options= new ChromeOptions();

options.addArguments("--headless");

driver = new ChromeDriver(options);

Without this option, the number of browsers that will be opened will be equal to or greater than the quantity 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 that you use a dedicated machine for Selenium script execution. Running in parallel several ChromeDriver or FirefoxDriver instances may be resource consuming.

To prepare your environment for running Selenium scripts:

If your Selenium tests can be run on your machine, LoadRunner Professional will also be able to run it.

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

The LoadRunner 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.

Back to top

Using a Selenium script in a scenario

This section describes how to add your Selenium script to a scenario.

Note: Network Virtualization is not supported for Selenium tests.

To define a Selenium scenario:

  1. Make sure the load generator machines are set up to run Selenium tests, as described above.
  2. On the main Controller toolbar, click the New Scenario button .
  3. In the New Scenario dialog box, click Add Scripts. From the Script Type dropdown, select Selenium Scripts.
  4. Click Browse and select the Selenium script (.java file).
  5. Click OK in the New Scenario dialog box. The scenario containing the Selenium script opens in the Design tab.
  6. Right-click the script name, and select Runtime Settings. If required by the script, enter the Classpath or XML files.

  7. Scenario settings are defined within the Selenium script. The following settings can be defined in 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 and WebDriver for performance testing is generally not recommended. Instead, use the dedicated Web or DevWeb protocols.

  8. In the Run tab, click the Start Scenario button to begin running the scenario.

Back to top

Sample Selenium script

In the sample file you can see:

  • The test running with headless argument.

  • The script will run for 2 minutes.
  • Each iteration contains 2 @Test annotations => 2 transactions
// 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 Controller graphs:

  • Running Vusers
  • Transaction Response Time
  • Total Trans/Sec (Passed)
  • Trans/Sec (Passed)

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

Back to top

See also: