Search code examples
javajavascriptseleniumselenium-webdriverjmeter

Couldn't access Methods using Jmeter-Webdriver


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)
**var support_page=JavaImporter(org.openqa.selenium.WebDriver.Timeouts)**
**var support_p=new support_page.pageLoadTimeout(30, TimeUnit.SECONDS)**
var url = WDS.args[0];
var user = WDS.args[1];
var pwd = WDS.args[2];

WDS.sampleResult.sampleStart()
WDS.browser.get(url)
var wait=new support_ui.WebDriverWait(WDS.browser,15000)
var userName = WDS.browser.findElement(pkg.By.id('Login_txtUserName')).sendKeys([user])
//userName.click()
//userName.sendKeys(['pandian'])
var userPwd = WDS.browser.findElement(pkg.By.id('Login_txtPassword')).sendKeys([pwd])
//userPwd.click()
//userPwd.sendKeys(['1234'])
var button = WDS.browser.findElement(pkg.By.id('Login_btnLogin')).click()
//button.click()

When I try to import WebDriver.Timeouts class it's imported but I am not able to access the Method pageLoadTimeout, when I run jmeter it says

Response message: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "TimeUnit" is not defined. (#5) in at line number 5

Can you please provide me the code for JMETER to access pageLoadTimeout()?


Solution

  • There is an easier and better way to get things done. Try the following code:

    var timeunit = java.util.concurrent.TimeUnit
    
    WDS.sampleResult.sampleStart()
    WDS.browser.manage().timeouts().pageLoadTimeout(1, timeunit.SECONDS);
    WDS.browser.get('http://google.com')
    WDS.sampleResult.sampleEnd()
    

    See Using Selenium with JMeter's WebDriver Sampler guide for more details on Selenium scripting in Apache JMeter using WebDriver Sample plugin.