Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Use Selenium WebDriver to complete the test in Jmeter

Shulou Source: shulou.com Published: 2022-06-03 06:59:34 11月17日 Update

Introduction

The following is selected from the book "Xiaoqiang Software testing Crazy handout"

Text

First of all, I have to lament the growing power of Jmeter, especially its plug-ins. As we have explained before, Jmeter can perform performance testing and interface testing, but this time it can rely on WebDriver to complete the functional automation testing of GUI.

Let's take the home page of my blog address as an example to explain. The general implementation steps are as follows:

1) download JMeterPlugins-WebDriver-1.3.1.zip, and after decompression, copy all the jar files in the lib directory and the JMeterPlugins-WebDriver.jar files in the lib/ext directory to the lib directory and the lib/ext directory in the local Jmeter installation directory.

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

3) start Jmeter and you can see that several new Driver Config have been added to the configuration element in figure 3.38.

Figure 3.38 configuration components

4) create a new jp@gc-Firefox Driver Config with the configuration shown in figure 3.39.

Figure 3.39 jp@gc-Firefox Driver Config

5) create a new jp@gc-WebDriver Sampler and write the following code:

/ / the test code starts, and the business to be tested can be placed between start and end.

WDS.sampleResult.sampleStart ()

Try {

/ / Open the home page of the blog

WDS.browser.get ('http://xqtesting.blog.51cto.com')

/ / end of test code

WDS.sampleResult.sampleEnd ()

} catch (x) {

WDS.sampleResult.sampleEnd ()

/ / failed to set to result

WDS.sampleResult.setSuccessful (false)

/ / the returned information is set to-_-sorry

WDS.sampleResult.setResponseMessage ('- _-sorry')

}

6) create a new view result tree and view the results with a table.

7) run the Jmeter script and you can see that the Firefox browser is automatically invoked and the operation is simulated. The final run result is shown in figure 3.40.

Figure 3.40 run result

The above is the easiest to use, and can be regarded as a try. Code writing in WebDriver Sampler can be extended. Just like you can write WebDriver, you can use By.id,By.cssSelector and other methods to locate and manipulate elements, similar to the following code:

Var pkg = JavaImporter (org.openqa.selenium)

WDS.browser.findElement (pkg.By.id ('what')). SendKeys ([' xiaoqiang'])

Interested friends can go to the official website to see the detailed sample code, address:

Http://jmeter-plugins.org/wiki/WebDriverSampler/ .

Tags: Tests directories code results runs configurations components blogs addresses files versions such as figure home page powerful crazy one book three business between information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia Huawei Apple Docker