当前位置:网站首页>Using JMeter for web side automated testing

Using JMeter for web side automated testing

2022-06-22 02:48:00 Test plus

Preface

be familiar with jmeter I think all of you know that ,jmeter It is a tool for server-side performance testing .jmeter You can do it Web End to end automated testing , This feature is something I just learned recently , Personally, I think it is more interesting . Refer to some articles on the Internet , Text just try to experience how to use .

download WebDriver rely on

Core or need WebDriver Dependency to start web pages .

  1. Download address (https://jmeter-plugins.org/downloads/old/)JMeterPlugins-WebDriver-1.1.2 .

2. take JMeterPlugins-WebDriver-1.1.2\lib\ext Medium *.jar copy to D:\apache-jmeter-2.13\lib\ext Next .

3. take JMeterPlugins-WebDriver-1.1.2\lib Medium *.jar copy to D:\apache-jmeter-2.13\lib Next .

Add a plug-in configuration component

again jmeter after , In the configuration component, you can see Chromdriver Driver Config, Description: the plug-in configuration is successful .

Configure local Chrome Driver Address ,Chrome Driver You need to download it in advance .

add to WebDriver Sampler

Select... In the sampler WebDriver Sampler Sampler .

WebDriver Sampler The sampler supports multiple languages (java、beanshell、js), We use js Language to write automated test code .

Testing process : Open the web page -> Click on the search -> Input text -> Click finish

code snippet

var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //WebDriver classes
var wait = new support_ui.WebDriverWait(WDS.browser, );
var timeunit = java.util.concurrent.TimeUnit


WDS.sampleResult.sampleStart(); //captures sampler's start time
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");


WDS.browser.get('http://duckduckgo.com'); //opens website specified in 'http://duckduckgo.com'
WDS.log.info("Sample ended - navigated to duckduckgo.com");

var searchField = WDS.browser.findElement(pkg.By.id('search_form_input_homepage')); //saves search field into searchField
searchField.click(); //clicks search field

searchField.sendKeys(['blazemeter']); //types word "blazemeter" in field
WDS.log.info("Searched for BlazeMeter");

var button = WDS.browser.findElement(pkg.By.id('search_button_homepage')); //Find Search button
button.click(); //Click Search Button
WDS.log.info("Clicked on the search button");

var link = WDS.browser.findElement(pkg.By.cssSelector('#r1-0 > div > h2 > a.result__a > b')); //also saves selector as variable but uses CSS.
link.click(); //Click the search result's Link

// Set the total request timeout for the entire transaction 
WDS.browser.manage().timeouts().pageLoadTimeout(,timeunit.SECONDS);

WDS.sampleResult.sampleEnd();

When debugging scripts , open debug Logs are convenient for debugging .

summary

be based on jmeter Extensions for WebDriver And combine it with js Write test cases , Can achieve WEB End to end automated testing .jmeter Yes, inheritance can be provided Samlper Sampler development extended sampler ,WebDriver The principle of plug-in development is also based on this feature . But the use of jmeter do WEB End to end automated testing can be done but is not suitable for . So if you have the ability to develop , Let's write an automated script .

原网站

版权声明
本文为[Test plus]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211654558461.html