Reputation: 1447
I've been using JMeter for quite a while but webdriver is new to me. I'm trying to do some timings for a multi-page scenario and have a question. I'm using JMeter webdriver sampler and HTMLunit:
Here is the scenario
1. Go to a web page http://162.243.100.234
2. Enter the word hello in the search box
3. Click on submit
What I want to get is:
1. How long it took to load the first page
2. How long it took from when I clicked on submit to when the results page was loaded
I have the following code which only gives me ONE sample timing. How do I change it so I'll have two?
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_ui.WebDriverWait(WDS.browser, 5000)
WDS.sampleResult.sampleStart()
WDS.browser.get('http://162.243.100.234/')
var searchField = WDS.browser.findElement(pkg.By.id('s'))
searchField.click()
searchField.sendKeys(['hello'])
var button = WDS.browser.findElement(pkg.By.id('searchsubmit'))
button.click()
WDS.sampleResult.sampleEnd()
I tried adding another sampleStart and sampleEnd but got and error. Do I need to use two samplers somehow?
Upvotes: 5
Views: 3154
Reputation: 168072
Yep, you need to split your code into 2 pieces:
First Sampler:
WDS.sampleResult.sampleStart()
WDS.browser.get('http://162.243.100.234')
WDS.sampleResult.sampleEnd()
Second Sampler:
var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
var searchField = WDS.browser.findElement(pkg.By.id('s'))
searchField.click()
searchField.sendKeys(['hello'])
var button = WDS.browser.findElement(pkg.By.id('searchsubmit'))
button.click()
WDS.sampleResult.sampleEnd()
Mention WDS.sampleResult.sampleStart()
and WDS.sampleResult.sampleEnd()
methods invocation
As per Using Selenium with JMeter's WebDriver Sampler guide
WDS.sampleResult.sampleStart() and WDS.sampleResult.sampleEnd() captures sampler’s time and will track it. You can remove them, the script will still work but you can’t get load time
Hope this helps
Upvotes: 2