Selenium scripts
This topic describes how to use Selenium scripts in performance tests. Selenium is an open-source load testing framework.
General requirements
Make sure that your environment meets the following requirements.
Tool | Version |
---|---|
Selenium | 4.19 |
Browser | Chrome 123 |
JUnit | 4.13.2 |
Mocha | 10.4.0 |
Prepare Selenium scripts using JUnit
Before you upload your Selenium script that uses JUnit, make sure that your environment meets the General requirements.
Prepare a script for uploading
These steps describe how to prepare your Selenium script for upload to the repository.
-
Create a storm.properties file that defines an execution type and entry point.
The file is a standard Java properties file (key/value pairs).
Copy codeExample of a storm.properties file:execution=Selenium
runner=junit
entrypoint=scratch.UnitTestSample
transactions=scratch.UnitTestSample.baseTest1,scratch.UnitTestSample.baseTest2The file should contain the following keys.
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>
. -
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 OpenText Core Performance Engineering. You do not need to include these frameworks in the .zip file.
-
Alternatively, if your JUnit test code is simple and you do not have a tool to build it as a .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. The .java file is compiled before the test is run.
Copy codeExample of a .java file in the sources field:execution=Selenium
runner=junit
entrypoint=MyChromeTest
sources=MyTest.java
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.
transactions=scratch.UnitTestSample.baseTest1,scratch.UnitTestSample.baseTest2
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
}
}
Prepare Selenium scripts using Mocha
Before you upload your Selenium script that uses Mocha, make sure that your environment meets the General requirements.
Prepare a script for uploading
This section describes how to prepare your Selenium script for upload to the repository.
-
Create a storm.json file that defines an execution type and transactions.
Copy codeExample of a storm.json file:{
"execution": "Selenium",
"runner": "mocha",
"transactions": ["sample - test item 1", "sample - test item 2"]
} -
Create an npm package that contains the storm.json file. For details on using the npm-pack command to create an npm package, see the npm documentation.
-
Upload the npm package (which is a .tgz file ) to your tenant.
Tip: The required Mocha and Selenium frameworks are already deployed in the product. You do not need to include these frameworks in the .tgz file.
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>
.
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);
});
});