gpt4 book ai didi

java - Spring MVC : Testing with selenium failing with commons-io not found(it exists)

转载 作者:行者123 更新时间:2023-11-30 10:48:01 24 4
gpt4 key购买 nike

我正在尝试使用 Selenium 测试 Spring-MVC 应用程序。不幸的是,到目前为止,我还没有足够的运气来启动和运行它。当我尝试使用以下命令使用干净的 tomcat 运行它时,它会提示找不到 commons-io。

如果我直接开始测试,那么登录页面是不会加载的。

启动 Apache :

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>

如果我直接尝试给出以下命令:

mvn clean test -Dtest=SeleniumLoginFrontendTest

登录页面未加载,出现此错误:

Tests in error: 
SeleniumLoginFrontendTest.startTest:25 » NoSuchElement Unable to locate elemen...

SeleniumLoginFrontendTest.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>

关于java - Spring MVC : Testing with selenium failing with commons-io not found(it exists),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35984939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com