Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use Selenium WebDriver to complete the test in Jmeter

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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/ .

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report