5

I'm working on Selenium and I have this test method:

@Test
public void testHeight() {
    System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
    
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.rapidtables.com/convert/length/feet-to-cm.html");
    
    driver.findElement(By.xpath("//*[@id=\"x\"]")).sendKeys("6");
    driver.findElement(By.xpath("//*[@id=\"calc\"]")).click();
    
    WebElement txtBoxContent = driver.findElement(By.xpath("//*[@id=\"doc\"]/form/table/tbody/tr[3]/td[2]/input"));
    
    String result = txtBoxContent.getAttribute("value");
    
    driver.close();
    
    System.out.println("The value is: " + result);
    
    assertEquals((double)180,Double.valueOf(result), 5);
    
}

When I try to run Selenium in my project with Junit I receive this error. The strange thing is that I try to run the method in a new project that has only the method and all work fine. I didn't forget anything, Drivers/chromedriver.exe is included in my project, all the Selenium driver are added in the classpath.

java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()'
    at org.openqa.selenium.chrome.ChromeOptions.asMap(ChromeOptions.java:292)
    at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:94)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at test.selenium.TestAttractionViewSortByDistance.testHeight(TestAttractionViewSortByDistance.java:18)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
    at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
    at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
    at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:141)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

EDIT:

The problem was that the selenium libraries needs to be added also in WebContent/lib.

Simone
  • 425
  • 1
  • 6
  • 17

2 Answers2

6

This error message...

java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()'

...implies that there is some incompatibility between the version of the binaries you are using.

The Selenium project with Junit in which you see this error have mismatched versions of guava installed.


Solution

You need to configure compatible version of guava as per the list below:

  • Selenium v2.49.0 : Bump guava to version 19
  • Selenium v3.1.0 : Requires an update to the latest guava version 21.0
  • Selenium v3.5.0 : Bump guava to version 22.
  • Selenium v3.5.1 : Bump guava to version 23.
  • Selenium v3.12.0 : guava-23.6-jre
  • Selenium v3.13.0 : guava-25.0-jre
  • Selenium v3.14.0 : guava-25.0-jre
  • Selenium v3.141.0 : guava-25.0-jre
  • Selenium v3.141.5 : guava-25.0-jre
  • Selenium v3.141.59 : guava-25.0-jre

References

You can find a couple of relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I have selenium 3.141.59 with guava-25.0-jre. It's all fine with my other project that uses selenium. And in my library: Selenium>guva-25.0-jre.jar>com.google.common.colletImmutableList there is the method toImmutableList(). So I'm not understanding why there is an error – Simone Jan 30 '21 at 22:12
  • For me it was missing guava dependency, and 31.1-jre working fine with Selenium 4.1.2. – Xdg Mar 24 '22 at 05:33
  • As I have selenium 4.1.2 and am hitting this issue, is there a general answer that points to where we can find the right guava for each selenium version? – Joelle Boulet Apr 05 '22 at 17:56
1

Changing

org.seleniumhq.selenium:selenium-java:3.141.59 to

org.seleniumhq.selenium:selenium-java:4.1.1

in my gradle fixed it.

Big Pumpkin
  • 3,907
  • 1
  • 27
  • 18