jmeter and Java selenium automation

Posted by millesm on Tue, 12 Nov 2019 18:45:24 +0100

Jmeter can complete the UI automation test through WebDriver, and can also test the browser side pressure on the system. The following jiar package is required

Basic configuration

1: Download, and after decompression, copy all jar files under the lib directory and JMeterPlugins-WebDriver.jar files under the lib/ext directory to the lib directory and the lib/ext directory under the local Jmeter installation directory.

Download address


2: enter the lib directory under the local Jmeter installation directory, delete the lower version of httpclient, httpcore and httpmime, and only keep the higher version.

3: start Jmeter, and you can see that several driver configs have been added to the configuration component in Figure 3.38.

4: create a new Chrome Driver Config


5: after creating a new WebDriver Sampler, you can write some selenium scripts

Selenium script parsing

try {

     var pkg = JavaImporter(org.openqa.selenium,

##Here is the class to import support.ui, corresponding to selenium-support.jar'WDS Name:' +



##Call the navigate method, jump to the url, and the corresponding method is in selenium-remote-driver.jar'Browser Title:' + WDS.browser.getTitle())

##Call the getTitle method to capture the title. The corresponding method is in selenium-remote-driver.jar'Browser CurrentUrl:' + WDS.browser.getCurrentUrl()) 'Cookie:' + WDS.browser.manage().getCookies())'Request Header: ' + WDS.sampleResult.getRequestHeaders())

     var what = WDS.browser.findElement('username'))


##Locate the name element, trigger the sendKeys event, and fill in the login name

     var where = WDS.browser.findElement('password'))


##Locate the name element, trigger the sendKeys event, and fill in the login name

     var button = WDS.browser.findElement('login-btn'))

##Locate the id element, trigger the click event, and click log in

##Several encapsulation elements and events are called above. The corresponding methods are in selenium-remote-driver.jar

     var wait = new pkg.WebDriverWait(WDS.browser, 5000)

##WebDriverWait is called, and the corresponding method is in selenium-support.jar. The value is ms


##Call the previous wait 5s to force the wait element to appear

     var results = WDS.browser.findElements(pkg.By.xpath("/html/body/div/header/div[1]/div/img"))'Result: ' + results)     if(results.empty) {

         WDS.sampleResult.successful = false

         WDS.sampleResult.responseMessage = "Login failed“

     }     else{"Sign in")}

##Assert whether the element is captured successfully


 } catch(ex) {


     WDS.sampleResult.successful = false

     WDS.sampleResult.responseMessage = 'There were no results returned'



Editor introduction

Script language settings

Introduction to shortcut keys

Common problem

Lack of method

Incompatible driver and browser versions


Topics: Programming Selenium