在带有groovy的jeter上找不到匹配的构造函数:org.Openqa.selenium.support.ui.WebDriverWait

xxe27gdn  于 2022-09-21  发布在  其他
关注(0)|答案(1)|浏览(92)

我目前正在写一个jeter上的脚本,用的是seum库和jeter上的groovy,但我遇到了一个问题。我以前直接用Java做了几次测试,但从来没有得到过。我认为Groovy不理解WebDriverWait的Selence库,所有其他库都可以工作并通过所有测试,但这个不能工作,如果你有更多信息,我有兴趣。

以下是代码和错误:

代码

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));

错误

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)

感谢您的阅读和您的时间,希望您能帮助我。

ukxgm1gy

ukxgm1gy1#

最新的WebDriver Sampler plugin version 3.3附带selenium-support 3.141.59,查看JavaDoc,没有这样的构造函数接受Duration作为参数,因此您需要以秒为单位提供超时,如下所示:

WebDriverWait wait=new WebDriverWait(driver, 10L);

有关在JMeter:Apache Groovy: What Is Groovy Used For?中编写Groovy脚本的更多信息

相关问题