java.lang.NoSuchMethodError自动化测试问题selenium-java

今天使用selenium-java自动操作火狐浏览器,代码如下:

package com.stylefeng.guns.test;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class SeleniumTest
{
    public static void main(String[] args)
    {
        System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir") + "/src/main/resources/geckodriver.exe");
        System.setProperty("webdriver.firefox.bin","E://Program Files//Mozilla Firefox//firefox.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.baidu.com");
        driver.quit();
    }
}

运行后结果报错如下:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet(Ljava/util/Comparator;)Ljava/util/stream/Collector;
	at org.openqa.selenium.remote.NewSessionPayload.lambda$validate$4(NewSessionPayload.java:199)
	at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:372)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:373)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at org.openqa.selenium.remote.NewSessionPayload.validate(NewSessionPayload.java:215)
	at org.openqa.selenium.remote.NewSessionPayload.(NewSessionPayload.java:163)
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:114)
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:107)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
	at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
	at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
	at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
	at com.stylefeng.guns.test.SeleniumTest.main(SeleniumTest.java:15)

一开始以为是java版本问题导致util包出问题找不到,换了几个版本都没有任何作用

后来看了下前面这个错误com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet

去找了下com.google.common.collect这个包,导入这个包就OK了

		
		
			org.seleniumhq.selenium
			selenium-java
			3.14.0
		
		
		
			com.google.guava
			guava
			27.0-jre
		

 

你可能感兴趣的:(自动化测试,测试)