Running Selenium Webdriver Scripts in JMeter

Share on Facebook0Share on LinkedIn0Share on Google+0Tweet about this on TwitterEmail this to someoneDigg this

Prerequisites
Download the latest version of JMeter (I am using 3.0 r1743807)
Download jmeter-plugins-manager-0.5.jar file and put it into lib/ext directory, then restart JMeter. http://jmeter-plugins.org/downloads/all/#Latest-Stable-Release

Let’s get started
Install the add ons using the JMeter plugin manager.
JMeterWebdriver1
JMeterWebdriver2

Create a new JMeter Project
Add a User Thread Group
JMeterWebdriver3
JMeterWebdriver4
Add a Webdriver Sampler
JMeterWebdriver5
Add the Chrome Driver Config
JMeterWebdriver6
Add the Chrome Driver Path
JMeterWebdriver7
Add a Listener View Results in Table
JMeterWebdriver8

Add User Defined Variables
JMeterWebdriver9

Add the following code in the Webdriver Sampler

var pkg = JavaImporter(org.openqa.selenium, org.openqa.selenium.support.ui)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_ui.WebDriverWait(WDS.browser, 15000)
WDS.sampleResult.sampleStart()
WDS.browser.get('${url}')
wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.xpath("//main/article[1]//a")))
var searchLink = WDS.browser.findElement(pkg.By.xpath("//main/article[1]//a"))
searchLink.click()
wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.xpath("//h1[@class='entry-title']")))
var results = WDS.browser.findElements(pkg.By.xpath("//h1[@class='entry-title']"))
if(results.empty) {
WDS.sampleResult.successful = false
WDS.sampleResult.responseMessage = 'Article page is not loaded'
}
WDS.sampleResult.sampleEnd()


Leave a Reply

Your email address will not be published. Required fields are marked *