java.lang.NoSuchMethodError:org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;)使用selenium-server-standalone-3.12.0 [英] java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;) using selenium-server-standalone-3.12.0

查看:121
本文介绍了java.lang.NoSuchMethodError:org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;)使用selenium-server-standalone-3.12.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力解决硒问题:

I've been struggling with selenium to fix this issue:

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;

这是我收到此错误的地方:

This is where I get this error:

Wait<WebDriver> wait = new FluentWait<>(getDriverInstance())
        .withTimeout(timeout, TimeUnit.SECONDS)
        .pollingEvery(frequency, TimeUnit.SECONDS)
        .ignoring(NoSuchElementException.class);
wait.until(driver -> {
    assert driver != null;
    elt.click();
    return true;
});

Internet上大多数解决方案建议使用Guava 21,但这对我不起作用.

The most solutions on the internet suggest to use Guava 21, but this is not working for me.

在本地运行selenium效果很好,但我没有得到这个问题,问题是我们使用了运行器,该运行器将使用selenium-server-standalone-3.12.0在多个虚拟机上运行测试,并且在类路径中定义了所有依赖项我们在声明Guava的地方也使用了Guava的其他版本,从19到23.

Running selenium locally works just fine, and I don't get this issue, the problem is we use a runner that will use the selenium-server-standalone-3.12.0 to run tests on multiple virtual machines, and in the classpath we define all the dependencies we use, where I declared Guava as well, I also tried other versions of Guava from 19 to 23.

我尝试了多种解决方案,但现在我没有主意了,即使声明了Guava,我也不知道为什么仍然会出现此错误,并且可以清楚地看到在本地运行测试时,该就可以了.

I tried multiple solutions and now I'm out of ideas, I don't know why I'm still getting this error even though I have declared Guava, and I can clearly see when I run tests locally, that Guava 23 works just fine.

我正在使用Java 1.8_71.

I'm using java 1.8_71.

当我检查selenium-server-standalone-3.12.0的代码源时,等待"界面看起来像这样:

When I checked the code source of selenium-server-standalone-3.12.0 the Wait interface looks like this:

import java.util.function.Function;

public interface Wait<F> {
    <T> T until(Function<? super F, T> var1);
}

但是在本地,它看起来像这样:

But in local it looks like this:

import com.google.common.base.Function;

public interface Wait<F> {
    <T> T until(Function<? super F, T> var1);
}

但是,由于com.google.common.base.Function在Guava 23中扩展了com.google.common.base.Function,所以这应该不是问题,那么为什么我仍然会收到此错误?

But since com.google.common.base.Function is extending com.google.common.base.Function in Guava 23, this shouldn't be a problem, so why I'm still getting this error ?

谢谢.

我已经检查了独立jar的内容,并且其中包含Guava版本23.6-jre,因此我对该问题来自番石榴表示高度怀疑.

I have checked the content of the standalone jar, and it contains Guava version 23.6-jre, so I'm highly skeptical about the issue being from guava.

我还检查了Wait界面,它的定义如下:

I also checked the Wait interface and it's defined like this:

import java.util.function.Function;

public interface Wait<F> {
    <T> T until(Function<? super F, T> var1);
}

除了使用的Function接口来自java.util.function而不是com.google.common.base

I still don't understand why I'm getting until(Lcom/google/common/base/Function;) in the exception when the used Function interface is from java.util.function and not com.google.common.base

我已经通过查看intellij如何执行我的jar来解决了这个问题,所以我在类路径中添加了D:\..\target\test-classes,并且由于某种原因该异常消失了,为什么会这样?以及如何将test-classes中的文件包含到我的最终jar中?

I have somehow solved this issue by looking at how intellij executes my jar, so I added D:\..\target\test-classes to the classpath and the exception disappeared for some reason, why this happened ? and how can I include the files in test-classes to my final jar ?

通常我有一个运行我的测试的蝙蝠文件:

Normally I have a bat file that runs my test:

@SETLOCAL
@ECHO OFF
@set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_231"
@set PATH=%JAVA_HOME%\bin;D:\drivers;%PATH%


@set CLASSPATH=.;
@set CLASSPATH=%CLASSPATH%D:\sln\lib\*;
@set CLASSPATH=%CLASSPATH%D:\sln\selenium-server-standalone-3.12.0.jar;

echo %CLASSPATH%
"C:\Program Files\Java\jdk1.8.0_231\bin\java.exe" com.sln.Runner %*

我将其用作以下用途:

D:\sln\Run.bat -u localhost -f D:\sln\target\sln-1.0-SNAPSHOT-tests.jar -c com.sln.SeleniumTest ...

除非我将其添加到类路径中,否则将获得NoSuchMethodError异常:

This won't work I'll get the NoSuchMethodError exception unless I add this to the class path:

@set CLASSPATH=%CLASSPATH%D:\sln\target\test-classes;

推荐答案

此错误消息...

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;

...表示 Guava 版本不兼容.

...implies that the Guava version was incompatible.

根据 selenium-java-3.12.0 客户端工具包的内容,在使用 selenium-server-standalone-3.12.0 时,支持的的版本是:

As you are using selenium-server-standalone-3.12.0 as per the contents of selenium-java-3.12.0 client kits the supported guava version is:

guava-23.6-jre


快照


Snapshot

一个立即的解决方案是:

An immediate solution would be to:

  • 使用 guava-23.6-jre.jar
  • 升级 Guava

在您确认 Guava 版本为 23.6-jre 的第一次更新中,真正的问题似乎是

In your first update as you have confirmed that Guava version is 23.6-jre, the real issue seems to be constructor of FluentWait. The argument type for withTimeout and pollingEvery post Selenium v3.11.0, which was:

  • pollingEvery: pollingEvery(long duration, java.util.concurrent.TimeUnit unit)
  • withTimeout: withTimeout(long duration, java.util.concurrent.TimeUnit unit)

现在已弃用,新类型为 java.time.Duration .因此,您的有效代码块将是:

Are now Deprecated and the new type is java.time.Duration. So your effective code block will be:

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(500))
.ignoring(NoSuchElementException.class);

您可以在


其他注意事项

另外,


Additional Consideration

Additionally,

  • Your JDK version is 1.8_71 which is pretty old and ancient.
  • Solution: Ensure that JDK is upgraded to current levels JDK 8u222.

根据最佳实践,您需要:

As per the best practices you need to:

  • JDK 升级到最新级别 JDK 8u222 .
  • 升级到当前级别版本3.141.59 .
  • GeckoDriver Firefox 特定:
    • GeckoDriver 升级到 GeckoDriver v0.26.0 级.
    • GeckoDriver存在于所需位置.
    • GeckoDriver对非root用户具有可执行权限.
    • Firefox 版本升级到 Firefox v72.0 级别.
    • Upgrade JDK to recent levels JDK 8u222.
    • Upgrade Selenium to current levels Version 3.141.59.
    • GeckoDriver and Firefox specific:
      • Upgrade GeckoDriver to GeckoDriver v0.26.0 level.
      • GeckoDriver is present in the desired location.
      • GeckoDriver is having executable permission for non-root users.
      • Upgrade Firefox version to Firefox v72.0 levels.
      • ChromeDriver is updated to current ChromeDriver v79.0.3945.36 level.
      • Chrome is updated to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)

      您可以在以下位置找到相关的详细讨论:

      You can find a relevant detailed discussion in:

      这篇关于java.lang.NoSuchMethodError:org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;)使用selenium-server-standalone-3.12.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆