I am currently writing a script on jmeter with the selenium library with groovy on jmeter, but I encounter a problem. I did several tests before in java directly but never got it. I think groovy does not understand a selenium library which is WebDriverWait, all the others work and pass all the tests but this one does not work, if you have more info I'm interested.
Here is the code and the error :
Code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
FirefoxOptions options = new FirefoxOptions().setAcceptInsecureCerts(true).addArguments("--marionette-port").addArguments("-private");
WebDriver driver = new FirefoxDriver(options);
JavascriptExecutor js = (JavascriptExecutor) driver;
String baseUrl = "xxxxxxxxxxxxxxxxxxxxxxx.com";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
WebDriverWait wait=new WebDriverWait(driver, Duration.ofSeconds(10));
Error
022-08-23 11:48:22,603 ERROR o.a.j.p.j.s.J.JSR223 Sampler: Uncaught error: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.support.ui.WebDriverWait(org.openqa.selenium.firefox.FirefoxDriver, java.time.Duration)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1845)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1615)
at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:286)
at Script69.run(Script69.groovy:32)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:231)
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:219)
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:72)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:651)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:570)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268)
at java.base/java.lang.Thread.run(Thread.java:833)
Thank you for reading and for your time, hoping you can help me.
CodePudding user response:
The latest WebDriver Sampler plugin version 3.3 comes with selenium-support 3.141.59 and looking into the JavaDoc there is no such a constructor which accepts Duration as a parameter so you need to either provide the timeout in seconds like:
WebDriverWait wait=new WebDriverWait(driver, 10L);
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?