Skip to main content

How to Set Up a Selenium Virtual User Script

Overview​

This guide shows how to create, configure, and run a Selenium Virtual User (VU) in Eggplant Performance Studio. It covers creating a custom VU type, writing scripts, selecting a browser, and running/debugging tests.


1) Create a custom Selenium Java Virtual User Type​

  1. In the Workspace tree, right-click Selenium Java Virtual User

  2. Select New Virtual User

  3. Enter a name and click OK

Your class will extend SeleniumVirtualUser.


2) Create an empty Selenium script​

  1. Right-click the Scripts folder

  2. Select New empty script

  3. Choose your custom Selenium VU type

  4. Enter script name and package

/img/selenium-vu-setup-create-empty-script.png


3) Create a test from the script​

  1. Right-click the script → Create test

  2. Enter a Test name and VU Group name

  3. Configure VU count, injectors, and runtime settings

/img/selenium-vu-setup-create-test-from-script.png


4) Open in Eclipse and debug​

  1. Right-click the VU Group in the Test view → Debug

  2. Two Eclipse projects appear:

    • Workspace project – Selenium VU framework + your custom VU

    • Project – test classes and scripts

/img/selenium-vu-setup-run-script-in-eclipse.png
Editing in Eclipse is the recommended workflow for Java Selenium VUs.


5) Configure the Selenium Virtual User (balanced defaults)​

Set defaults programmatically in your custom VU’s pre() (no env vars / properties required):

public class MyDriverVU extends SeleniumVirtualUser {
@Override
public void pre() throws Exception {
super.pre();

getVU().setWaitForReady(true)
.setReadyWaitMs(400)
.setCdpMetricsEnabled(false)
.setCdpBudgetMs(200)
.setClickRetries(2)
.setRecordPostClickNav(true)
.setNavDedupWindowMs(300);

// Choose a driver
initialiseHtmlUnitDriver(); // Headless Chrome in this integration
// or: initialiseChromeDriver();
// or: initialiseFirefoxDriver();
// or: initialiseEdgeDriver();
}
}

Driver‑specific examples​



FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("dom.ipc.processCount", 1);
profile.setPreference("gfx.webrender.force-disabled", true);
profile.setPreference("layers.acceleration.disabled", true);
FirefoxOptions options = new FirefoxOptions().setProfile(profile).setAcceptInsecureCerts(true);
initialiseFirefoxDriver(options);

​

initialiseEdgeDriver();

​

org.openqa.selenium.WebDriver custom = new MyCustomDriver();
initialiseWebDriver(custom);


6) Write your Selenium script​

​

getWebDriver().get("https://example.com");
getWebDriver().findElement(By.id("q")).sendKeys("eggplant selenium");
getWebDriver().findElement(By.cssSelector("button[type='submit']")).click();

​

// The wrapped click() retries lightly and records navigation + metrics if URL changes
getWebDriver().findElement(By.linkText("Details")).click();

​

List<org.openqa.selenium.WebElement> banners = getWebDriver().findElements(By.cssSelector(".cookie-banner .accept"));
if (!banners.isEmpty()) banners.get(0).click();


7) Run the test in Test Controller​

  • Select injectors and VU counts

  • Execute iterations

  • Review logs and timing results

Metrics are captured from:

  • Chrome DevTools (when enabled)

  • JS Navigation Timing (fallback)

  • Wrapped navigation endpoints (start/end request hooks)


8) Tips & best practices​

  • Prefer Headless Chrome for most regression/perf runs (fast and compatible)

  • Keep CDP disabled unless you specifically need deep timing breakdowns

  • Avoid hard-coding driver paths in code; let Selenium resolve them when possible

  • Use stable selectors (id, name, aria, semantic CSS)

  • Keep pre() short and deterministic for repeatable timing