Skip to content

Demo project that generates JMeter DSL tests from existing Selenium tests.

License

Notifications You must be signed in to change notification settings

abstracta/selenium-jmeter-dsl-demo

Repository files navigation

Selenium JMeter DSL demo

This is a demo project that contains a Selenium test for Retail Store demo app and generates and run performance tests using JMeter DSL.

Requirements

  • Docker + Docker compose
  • Maven 3.5+
  • Java 19+

Project Structure

Path Description
retailstore-test Selenium Test project
retailstore-test/docker-compose.yml Provisioning of Retail Store demo app
RetailStoreTest Selenium Test for Retail Store app
.env Configuration file for Selenium Test
selenium-jmeter-dsl Module contains main logic for recording and executing performance test. Including integration with Jmeter DSL
JmeterDslSeleniumRecorder JUnit extension which generates JMeter DSL test plan from a Selenium Test.
docker-compose.yml Provisioning for Grafana & InfluxDB

Usage

Selenium test execution

To start Retail Store demo app, go to retailstore-test folder and run:

docker-compose up

Set local hosts file so retailstore.test points to localhost:

echo '127.0.0.1 retailstore.test' >> /private/etc/hosts

You can run RetailStoreTest either using an IDE or using:

mvn clean test

To see the actual flow running you can remove "--headless=new" chrome option and set THINK_TIME_MILLIS to a value like 1000 in .env file.

Remember resetting THINK_TIME_MILLIS to 0, and re-adding "--headless=new" chrome option before running performance test.

Performance test recording & tuning

  1. Add selenium-jmeter-dsl dependency to retailstore-test/pom.xml:

    <dependency>
      <groupId>us.abstracta</groupId>
      <artifactId>selenium-jmeter-dsl</artifactId>
      <version>${project.version}</version>
    </dependency>
  2. Register JmeterDslSeleniumRecorder JUnit extension in RetailStoreTest.

    @RegisterExtension
    public final JmeterDslSeleniumRecorder recorder = new JmeterDslSeleniumRecorder()
        .basePageObject(BasePage.class);
  3. Add JmeterDslSeleniumRecorder as proxy in WebDriver options.

    options.setProxy(recorder.getProxy());
  4. Run RetailStoreTest & review generated PerformanceTest.java.

  5. Add InfluxDB listener config to .env:

    INFLUX_URI=http://localhost:8086
    INFLUX_ORG=abstracta
    INFLUX_BUCKET=selenium
    INFLUX_TOKEN=token
    
  6. Add correlation rule to JmeterDslSeleniumRecorder. For fixed values in test plan, productId for instance, look into target/recordings generated XML files for responses containing the ID and define extraction and replacement regexes.

    @RegisterExtension
    private final JmeterDslSeleniumRecorder recorder = new JmeterDslSeleniumRecorder()
        .correlationRule("productId",
            "name=\"productId\" value=\"([^\"]+)\"",
            "productId=(.*)")
        .basePageObject(BasePage.class);
  7. Re-run RetailStoreTest and review PerformanceTest.java.

  8. Run PerformanceTest test method and review calls (replacing just for this run influxDbListener with resultsTreeVisualizer, and then restoring influxDbListener).

  9. Tune thread group configuration in PerformanceTest.java

    threadGroup()
      .rampToAndHold(10, Duration.ZERO, Duration.ofMinutes(1))
      .rampToAndHold(20, Duration.ZERO, Duration.ofMinutes(1))
      .rampToAndHold(50, Duration.ZERO, Duration.ofMinutes(3))
      .children(...)
  10. Remove JUnit extension & proxy from RetailStoreTest.java.

  11. Start InfluxDB & Grafana running at root location of this project:

    docker-compose up
  12. Start PerformanceTest main method.

  13. Review results in Grafana at http://localhost:3000 with admin & 1234.

About

Demo project that generates JMeter DSL tests from existing Selenium tests.

Topics

Resources

License

Stars

Watchers

Forks

Languages