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;
});
The most solutions on the internet suggest to use Guava 21
, but this is not working for me.
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.
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.
I'm using java 1.8_71
.
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);
}
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 ?
Thanks in advance.
Update:
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.
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);
}
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
Update 2
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 %*
which I use as following:
D:\sln\Run.bat -u localhost -f D:\sln\target\sln-1.0-SNAPSHOT-tests.jar -c com.sln.SeleniumTest ...
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;