我跑:
mvn clean test
我收到此错误:
[错误]无法执行目标 org.apache.maven.plugins:行家-编译器插件:3.2:testCompile 项目suman上的(default-testCompile):编译失败[错误] /home/oleg/WebstormProjects/oresoftware/sumanjs/sce-test/suman/src/test/java/suman/SeleniumTest.java:[21,15] 无法访问org.openqa.selenium.HasInputDevices [ERROR]类文件 找不到org.openqa.selenium.HasInputDevices
我正在看这个:
看起来我的FirefoxDriver或ChromeDriver导致了这个问题。
这是我的pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>suman</groupId>
<artifactId>suman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>suman</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.29.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.0rc3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.0rc3</version>
</dependency>
</dependencies>
</project>
我有两个测试脚本,一个使用ChromeDriver,另一个使用FirefoxDriver,它们看起来像这样:
package suman;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumTest {
private static FirefoxDriver driver;
private WebElement element;
@BeforeClass
public static void openBrowser(){
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void valid_UserCredential(){
System.out.println("Starting test " + new Object(){}.getClass().getEnclosingMethod().getName());
driver.get("http://www.store.demoqa.com");
driver.findElement(By.xpath(".//*[@id='account']/a")).click();
driver.findElement(By.id("log")).sendKeys("testuser_3");
driver.findElement(By.id("pwd")).sendKeys("Test@123");
driver.findElement(By.id("login")).click();
try{
element = driver.findElement (By.xpath(".//*[@id='account_logout']/a"));
}catch (Exception e){
}
Assert.assertNotNull(element);
System.out.println("Ending test " + new Object(){}.getClass().getEnclosingMethod().getName());
}
@Test
public void inValid_UserCredential()
{
System.out.println("Starting test " + new Object(){}.getClass().getEnclosingMethod().getName());
driver.get("http://www.store.demoqa.com");
driver.findElement(By.xpath(".//*[@id='account']/a")).click();
driver.findElement(By.id("log")).sendKeys("testuser");
driver.findElement(By.id("pwd")).sendKeys("Test@123");
driver.findElement(By.id("login")).click();
try{
element = driver.findElement (By.xpath(".//*[@id='account_logout']/a"));
}catch (Exception e){
}
Assert.assertNotNull(element);
System.out.println("Ending test " + new Object(){}.getClass().getEnclosingMethod().getName());
}
@AfterClass
public static void closeBrowser(){
driver.quit();
}
}
有谁知道如何修复此编译错误?
答案 0 :(得分:2)
您收到此错误,因为您的pom.xml中的依赖项不兼容 依赖列表应该是这样的。
import java.io.*;
public final class SystemDemo{
public final static InputStream give=null;//the same variables
public final static PrintStream take=null;
public final static PrintStream error = null;
}