我在 Intellij 中使用 Java/Selenium/JUnit/ANT,當(dāng)我運行我的 build.xml 文件并且它到達(dá)我的測試運行器時,我開始收到不可變映射錯誤。我沒有任何不可變對象。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 調(diào)用,并在 @After 中再次調(diào)用驅(qū)動程序@Beforepublic void signIn() throws Exception{ auth.doSetup();}@Afterpublic void tearDown() throws Exception { auth.driver.quit();}這引發(fā)了以下錯誤: <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.<init>(DriverService.java:249)at org.openqa.selenium.edge.EdgeDriverService$Builder.<init>(EdgeDriverService.java:72)at org.openqa.selenium.edge.EdgeDriverService.createDefaultService(EdgeDriverService.java:68)at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:96)at userTests.Auth.doSetup(Auth.java:33)我想要一個解決方法來避免這個錯誤,我最初在 Eclipse 中編寫這個項目時沒有遇到這個問題,但是由于各種原因,我不得不切換到 Intellij,現(xiàn)在我遇到了這個問題。
2 回答

蕭十郎
TA貢獻(xiàn)1815條經(jīng)驗 獲得超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'
添加回答
舉報
0/150
提交
取消