0

im writing a Java code on Jmeter (webdriver) in order to perform a load test, i need to implement implicit wait, something like :

WDS.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

But seems Jmeter is not understanding it, also i tried to use:

def wait = new org.openqa.selenium.support.ui.WebDriverWait(WDS.browser, 5); wait.until(org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable(org.openqa.selenium.By.xpath("//a[contains(text(),'More information')]")))

with no use.

The only thing worked with me is :

Thread.sleep(2000);

but it will not work with me when i will run the test with high load.

test plan and CSV files can be found in below URL: https://drive.google.com/file/d/1k5ZjhSEXiFPObwysNYKcwRZN0xxOkAHl/view?usp=sharing

Please have a look on the code and tell me what can i do :(

noting that script language is JAVA there is no option for JavaScript on Jmeter.

1 Answers1

0

There is no JAVA in JMeter's WebDriver Sampler, it's Beanshell interpreter and in order to be able to use Explicit Wait with the above code snippet you will need to switch the language to groovy (moreover it's recommended scripting option since JMeter 3.1)

You won't have to change a single line or even character, valid Java code in majority of cases is valid Groovy code.

Given you switch to Groovy the piece of code implementing the explicit wait which you copied and pasted from somewhere will start working.

Also don't mix implicit and explicit waits:

Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you, i tried to convert it to Groovy , but it didn't work, it gave me an error related to variables syntax and i didn't know what to do with it – Jumana Haimour Apr 19 '22 at 10:59
  • this is my first time to use selenium plugin in Jmeter, so please tell me if there is no java in jmeter webdriver sampler then why there is an option for it in the drop down list for scripting language ? also i used it and run the code and it worked fine ... my only problem is with the wait – Jumana Haimour Apr 19 '22 at 11:07
  • This is the error i faced when i changed to Groovy: Response code:500 Response message:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script2.groovy: 14: No expression for the array constructor call at line: 14 column: 37. File: Script2.groovy @ line 14, column 37. companyIdElement.sendKeys(new String[]{("CG197")}); – Jumana Haimour Apr 19 '22 at 11:11
  • I'm not going to answer each individual comment which looks like more a separate question, either convert the Explicit Wait syntax from Groovy to Beanshell or convert other conflicting statements from Beanshell to Groovy. – Dmitri T Apr 19 '22 at 11:31