Reputation: 1
I am facing an issue with the Web driver sampler in J meter. I have written a simple code in web driver sampler where i have given a url and passing few credentials to login.
When i run the test.. the browser gets invoked, the url is passed onto the address bar and then the browser gets closed or crashes. Sometimes the browser gets crashed after passing the passwords. Pls have a look at the below code and let me know if i am missing on something.
Code. var pkg=JavaImporter(org.openqa.selenium) //import java selenium package var support_ui=JavaImporter(org.openqa.selenium.support.ui.WebDriverWait) var ui=JavaImporter(org.openqa.selenium.support.ui) var wait=new support_ui.WebDriverWait(WDS.browser,20000) WDS.sampleResult.sampleStart()
WDS.browser.get('https://web2qa.westlaw.com/signon/default.wl?bhcp=1&fn=_top&newdoor=true&rs=WLW14.07&vr=2.0')
var Onepass=WDS.browser.findElement(pkg.By.id('OnePassHeaderLink'))
Onepass.click()
var usernameField = WDS.browser.findElement(pkg.By.id('pwd'))
usernameField.sendKeys(['pwd1'])
var passwordField = WDS.browser.findElement(pkg.By.id('clientid'))
passwordField.sendKeys(['pwd2'])
var loginButton=WDS.browser.findElement(pkg.By.id('login_submit'))
loginButton.click()
WDS.log.info(WDS.name + ' has logged an entry')
WDS.sampleResult.sampleEnd()
1.I did reduce the timeout period, Still the Issue persists. 2.i have added the code u mentioned even in the username Field and passwordField still the browser crashes once the page gets loaded. 3.Please find the screenshot and the error log below.
Error Log: 2014/07/22 01:27:56 INFO - jmeter.threads.JMeterThread: Running PostProcessors in forward order 2014/07/22 01:27:56 INFO - jmeter.threads.ThreadGroup: Started thread group number 1 2014/07/22 01:27:56 INFO - jmeter.engine.StandardJMeterEngine: All thread groups have been started 2014/07/22 01:27:56 INFO - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 2014/07/22 01:28:09 INFO - com.googlecode.jmeter.plugins.webdriver.config.WebDriverConfig: iterationStart() 2014/07/22 01:28:09 INFO - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Current thread name: 'Thread Group 1-1', has browser: 'FirefoxDriver: firefox on XP (098965b0-fea8-4428-9e6e-76d1385cecc2)' 2014/07/22 01:28:22 ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: sun.org.mozilla.javascript.internal.WrappedException: Wrapped org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"login_submit"} Command duration or timeout: 32 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.34.0', revision: '11cd0ef93615408e0b6b3bfa28defe125906461a', time: '2013-08-06 11:43:14' System info: os.name: 'Windows 2003', os.arch: 'x86', os.version: '5.2', java.version: '1.6.0_37' Session ID: 098965b0-fea8-4428-9e6e-76d1385cecc2 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=16.0.2, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}] (#18) in at line number 18 2014/07/22 01:28:22 INFO - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 2014/07/22 01:28:22 INFO - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 2014/07/22 01:28:22 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(false,local)
Upvotes: 0
Views: 605
Reputation: 168092
First of all WebDriverWait(WDS.browser,20000)
Are you sure that 20000 seconds is correct timeout for waiting element to appear? It's 5.5 hours. If you need 20 seconds just put 20 in there.
Second:
Elements may not be loaded immediately after browser.get
request. For instance if element is being loaded with AJAX it may take some additional time for it to appear in DOM and WebDriver could interact with it.
So I would suggest something like:
WDS.browser.get('https://web2qa.westlaw.com/signon/default.wl?bhcp=1&fn=_top&newdoor=true&rs=WLW14.07&vr=2.0')
wait.until(ui.ExpectedConditions.presenceOfElementLocated(pkg.By.id('OnePassHeaderLink')))
var Onepass=WDS.browser.findElement(pkg.By.id('OnePassHeaderLink'))
Onepass.click()
Apply the same for usernameField
, passwordField
, etc.
Third: If you still experience any problems add View Results Tree listener or inspect jmeter.log
file to find out the reason of your test failure and update your question with error messages as Stack Overflow community is not telepathic enough to guess what's wrong with your test.
See Using Selenium with JMeter's WebDriver Sampler guide for more details on how to use WebDriver Sampler.
Upvotes: 0