我在Intellij中使用Java / Selenium / JUnit / ANT,当我运行build.xml文件并将其连接到Test Runner时,我开始遇到Immutable Map错误。我没有任何不可变的对象。
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.<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)
at adminTests.adminWorkspaceMenu.signIn(adminWorkspaceMenu.java:19)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
</error>
<error type="java.lang.NullPointerException">java.lang.NullPointerException
at adminTests.adminWorkspaceMenu.tearDown(adminWorkspaceMenu.java:39)
</error>
</testcase>
我想要一个避免该错误的解决方法,当我最初在Eclipse中对该项目进行编码时,我并没有遇到这种情况,但是由于种种原因,我不得不切换到Intellij,现在遇到了这个问题。 / p>
答案 0 :(得分:0)
ImmutableMap
类来自Google收藏库。尝试将此依赖项添加到您的项目中:
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'
答案 1 :(得分:0)
将此添加到pom中:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>