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 JMeterPlugins-WebDriver-1.3.1.zip, 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 https://jmeter-plugins.org/downloads/old/

 

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, org.openqa.selenium.support.ui)

##Here is the class to import support.ui, corresponding to selenium-support.jar

     WDS.log.info('WDS Name:' + WDS.name)

     WDS.sampleResult.sampleStart()

     WDS.browser.navigate().to("https://qas.cttq.com")

##Call the navigate method, jump to the url, and the corresponding method is in selenium-remote-driver.jar

     WDS.log.info('Browser Title:' + WDS.browser.getTitle())

##Call the getTitle method to capture the title. The corresponding method is in selenium-remote-driver.jar

     WDS.log.info('Browser CurrentUrl:' + WDS.browser.getCurrentUrl())    

     WDS.log.info('Cookie:' + WDS.browser.manage().getCookies())   

     WDS.log.info('Request Header: ' + WDS.sampleResult.getRequestHeaders())

     var what = WDS.browser.findElement(pkg.By.name('username'))

     what.sendKeys(['8107000'])

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

     var where = WDS.browser.findElement(pkg.By.name('password'))

     where.sendKeys(['000000'])

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

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

     button.click()

##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

wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.xpath("/html/body/div/header/div[1]/div/img")))

##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"))

     WDS.log.info('Result: ' + results)     if(results.empty) {

         WDS.sampleResult.successful = false

         WDS.sampleResult.responseMessage = "Login failed“

     }     else{WDS.log.info("Sign in")}

##Assert whether the element is captured successfully

     WDS.sampleResult.sampleEnd()

 } catch(ex) {

     WDS.log.error(ex)

     WDS.sampleResult.successful = false

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

     WDS.sampleResult.sampleEnd()

 }

Editor introduction

Script language settings

Introduction to shortcut keys

Common problem

Lack of method

Incompatible driver and browser versions

 


Topics: Programming Selenium