Share this page

# Selenium tests

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

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

In this topic:

## 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 product documentation.

Controller supports the integration of Selenium test scripts in your scenarios. You can run one or more Selenium scripts alongside any other protocol script in a scenario.

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

Controller can execute the following Selenium test types (currently only .java extensions):

- Simple Java script
- JUnit script
- TestNG
- TestNG with XML

Selenium script features

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

- 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 is seen. If it is executed 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 executed once, the number of transactions is 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 Controller, we recommend using the Headless option for Selenium scripts. Using this option, no visible browser opens during test execution.

  ChromeOptions options= new ChromeOptions();

  options.addArguments("--headless");

  driver = new ChromeDriver(options);

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

Back to top

## Prerequisite setup for Selenium tests

The following are the prerequisites for using Selenium scripts in Controller scenarios.

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

- If your Selenium tests can be run on your machine, Controller is also able to run the tests.

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

- The OpenText Professional Performance Engineering installation contains the Selenium Server jar. If the Selenium script uses other dependencies (Classpath, or TestNG XML), in the script's runtime settings Selenium node, set the parameter value to that file name.

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 file names.

7. 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 using a limited number of Vusers.

     Note: Using Selenium together with 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 runs with headless argument.

- The test runs 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 display 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

## Notes and tips

Note the following when working with Selenium tests:

- Both the Classpath and TestNG XML fields in the runtime settings support absolute and relative paths. The start directory for the relative path is the script directory (where the .java script file is located).

- If there are several XMLs connected to each other, then specify the main XML in the runtime settings.

- If there are several XML configuration files in a script folder, and no XML is specified in the runtime settings, then all XML files are executed.

- If the input from the XML field (in the runtime settings) is not valid, only the first script that is uploaded in Controller is executed.

- For some specific versions of ChromeDriver, the script works as expected only after the definition of an additional Chrome attribute, as in the example below:

  ChromeOptions options = new ChromeOptions();

  options.addArguments("--remote-allow-origins=*");

  ChromeDriver driver = new ChromeDriver(options);

  Note: This behavior may also be present when running the script without Controller.

- When using a Linux load generator, we recommend defining additional attributes for the Selenium .java script. The example below shows these changes when using Chrome.

  import org.openqa.selenium.chrome.ChromeOptions;

  ChromeOptions options = new ChromeOptions();

  System.setProperty("webdriver.chrome.driver", "//path_to_driver");

  options.addArguments("start-maximized"); // open Browser in maximized mode

  options.addArguments("disable-infobars"); // disabling infobars

  options.addArguments("--disable-extensions"); // disabling extensions

  options.addArguments("--disable-gpu");

  options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems

  options.addArguments("--no-sandbox"); // Bypass OS security model

  options.addArguments("--headless"); // Bypass OS security model

  driver = new ChromeDriver(options);

Back to top

See also:

- Design load test scenarios
- New Scenario dialog box

https://admhelp.microfocus.com Professional Performance Engineering,VuGen 8942
Tips to improve your search results... OpenText™ Professional Performance Engineering Help Center OpenText™ Professional Performance Engineering Help 26.1 All View Local Help Center View Online Help Center Version: