Java Spring MVC:使用selenium进行测试失败,未找到commons io(它存在)
我正在尝试用Selenium测试SpringMVC应用程序。不幸的是,到目前为止,我还没有太多的运气来启动和运行它。当我尝试用一个干净的tomcat和以下命令运行它时,它会抱怨找不到commons io 如果直接启动测试,则不会加载登录页面 正在启动apache:Java Spring MVC:使用selenium进行测试失败,未找到commons io(它存在),java,spring,maven,spring-mvc,selenium,Java,Spring,Maven,Spring Mvc,Selenium,我正在尝试用Selenium测试SpringMVC应用程序。不幸的是,到目前为止,我还没有太多的运气来启动和运行它。当我尝试用一个干净的tomcat和以下命令运行它时,它会抱怨找不到commons io 如果直接启动测试,则不会加载登录页面 正在启动apache: mvn clean tomcat7:run 错误日志: [ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (def
mvn clean tomcat7:run
错误日志:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project SOFTWARE: Could not start Tomcat: Failed to start component [StandardServer[-1]]: Failed to start component [StandardService[Tomcat]]: Failed to start component [StandardEngine[Tomcat]]: A child container failed during start -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Exception in thread "Thread-33" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at org.apache.tomcat.maven.plugin.tomcat7.run.RunMojo$2.run(RunMojo.java:295)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
带有commons io的POM.xml:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<archiveClasses>true</archiveClasses>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>false</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
登录页面未加载,我收到以下错误:
Tests in error:
SeleniumLoginFrontendTest.startTest:25 » NoSuchElement Unable to locate elemen...
SeleniumLoginFrontTest.java:
public class SeleniumLoginFrontendTest {
private WebDriver browser;
@Before
public void setup() {
browser = new FirefoxDriver();
}
@Test
public void startTest() {
browser.get("http://localhost:8080/login");
--> Below is line-25
browser.findElement(By.id("j_username")).sendKeys("");
browser.findElement(By.id("j_password")).sendKeys("");
browser.findElement(By.id("loginButton")).click();
browser.findElement(By.id("account")).click();
}
@After
public void tearDown() {
// browser.close();
}
}
那么,我到底做错了什么?任何帮助都很好。谢谢。:-)
更新
因此,我确实将commons io库设置为2.2版,但没有帮助。尝试显式指定一个版本:
<dependencies>
...
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
...
</dependencies>
...
公地io
公地io
2.2
...
无更改,在运行mvn clean&mvn install之前运行mvn clean tomcat7:run
。同样的错误。测试运行失败,只有那个错误。如果我在没有测试的情况下运行我的项目,那就没问题了。我发现tomcat7插件需要这种依赖关系:commons io commons io 2.2
通过验证jarcommons io的版本中是否存在org.apache.commons.io.FileUtils
来为您的commons io
添加适当的版本,因为该类缺少所有依赖关系一定是在一个单独的部分谁能告诉我为什么投票被否决?我认为应该强制规定,当用户投反对票时,必须发表评论。
<dependencies>
...
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
...
</dependencies>