为了账号安全,请及时绑定邮箱和手机立即绑定

没有不可变对象的 Selenium/JUnit 中的不可变映射错误

没有不可变对象的 Selenium/JUnit 中的不可变映射错误

qq_笑_17 2021-05-31 14:15:15
我在 Intellij 中使用 Java/Selenium/JUnit/ANT,当我运行我的 build.xml 文件并且它到达我的测试运行器时,我开始收到不可变映射错误。我没有任何不可变对象。import org.openqa.selenium.By;import org.openqa.selenium.Capabilities;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.edge.EdgeDriver;import org.openqa.selenium.edge.EdgeDriverService;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.support.ui.WebDriverWait;import java.io.IOException;public class Auth {public WebDriver driver;public WebDriverWait wait;public static void main(String[] args){    System.out.println("Let's Go.");}public boolean doSetup() throws IOException {    System.setProperty("webdriver.edge.driver", "C:/Path/to/MicrosoftWebDriver.exe" );    driver = new EdgeDriver();    Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();    String browserName = cap.getBrowserName().toLowerCase();    //System.out.println(browserName);      if(browserName.equals("microsoftedge")) {      }    return true;}然后在我的测试中将其作为 @Before 调用,并在 @After 中再次调用驱动程序@Beforepublic void signIn() throws Exception{    auth.doSetup();}@Afterpublic void tearDown() throws Exception {    auth.driver.quit();}这引发了以下错误:  <testcase classname="adminTests.adminWorkspaceMenu" name="adminWorkspace" time="0.025"><error message="com/google/common/collect/ImmutableMap" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMapat org.openqa.selenium.remote.service.DriverService$Builder.&lt;init&gt;(DriverService.java:249)at org.openqa.selenium.edge.EdgeDriverService$Builder.&lt;init&gt;(EdgeDriverService.java:72)at org.openqa.selenium.edge.EdgeDriverService.createDefaultService(EdgeDriverService.java:68)at org.openqa.selenium.edge.EdgeDriver.&lt;init&gt;(EdgeDriver.java:96)at userTests.Auth.doSetup(Auth.java:33)我想要一个解决方法来避免这个错误,我最初在 Eclipse 中编写这个项目时没有遇到这个问题,但是由于各种原因,我不得不切换到 Intellij,现在我遇到了这个问题。
查看完整描述

2 回答

?
萧十郎

TA贡献1815条经验 获得超13个赞

该ImmutableMap班是从谷歌集合库。尝试将此依赖项添加到您的项目中:


Maven(添加到您的 pom.xml 依赖项部分):


<dependency>

    <groupId>com.google.collections</groupId>

    <artifactId>google-collections</artifactId>

    <version>1.0</version>

    <scope>test</scope>

</dependency>

Gradle(添加到您的 build.gradle 依赖项部分):


testCompile group: 'com.google.collections', name: 'google-collections', version: '1.0'



查看完整回答
反对 回复 2021-06-02
  • 2 回答
  • 0 关注
  • 126 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信