猿问

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

我在 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 中再次调用驱动程序


@Before

public void signIn() throws Exception{

    auth.doSetup();

}


@After

public 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/ImmutableMap

at 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,现在我遇到了这个问题。


qq_笑_17
浏览 127回答 2
2回答

萧十郎

该ImmutableMap班是从谷歌集合库。尝试将此依赖项添加到您的项目中:Maven(添加到您的 pom.xml 依赖项部分):<dependency>&nbsp; &nbsp; <groupId>com.google.collections</groupId>&nbsp; &nbsp; <artifactId>google-collections</artifactId>&nbsp; &nbsp; <version>1.0</version>&nbsp; &nbsp; <scope>test</scope></dependency>Gradle(添加到您的 build.gradle 依赖项部分):testCompile group: 'com.google.collections', name: 'google-collections', version: '1.0'
随时随地看视频慕课网APP

相关分类

Java
我要回答