我正在尝试使用Selenium Web驱动程序(ChromeWebDriver(运行自动测试,在脚本中我需要读取带有一些参数的CSV文件,脚本的目的是使用不同的用户登录站点,但是在使用JUnit 5运行时出现以下错误:
错误:
java.lang.NoClassDefFoundError: net/sf/cglib/proxy/Callback
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: net.sf.cglib.proxy.Callback
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
这是我正在尝试运行的代码:
package selenium;
import org.easetech.easytest.annotation.DataLoader;
import org.easetech.easytest.annotation.Param;
import org.easetech.easytest.runner.DataDrivenTestRunner;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
@RunWith(DataDrivenTestRunner.class)
@DataLoader(filePaths = "C:\Users\RODOLFOTRINCA\eclipse-workspace\apostila\src\test\java\resources\login.csv")
public class LoginCsv {
static WebDriver driver;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\Users\RODOLFOTRINCA\eclipse-workspace\apostila\drivers\chromedriver.exe");
driver = new ChromeDriver(); //cria obj do tipo WebDriver
driver.manage().window().maximize(); //maximiza janela
driver.get("http://automationpractice.com/index.php"); //abre o site desejado
}
@After
public void tearDown() throws Exception {
Thread.sleep(1500);
driver.quit();
}
@Test
public void loginComPlanilhaCSV(@Param(name="email")String email,
@Param(name="password")String password,
@Param(name="resultado")String resultado) throws Exception {
driver.findElement(By.className("login")).click();
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("passwd")).sendKeys(password);
driver.findElement(By.id("SubmitLogin")).click();
Assert.assertEquals(resultado, driver.findElement(By.tagName("h1")).getText());
}
}
这是带有参数的 CSV 文件:
loginComPlanilhaCSV, email, password, resultado
, teste01@teste.com.br, 123456, MY ACCOUNT
, teste02@teste.com.br, 123456, MY ACCOUNT
, teste03@teste.com.br, 123456, MY ACCOUNT
这些是我对pom.xml文件的依赖关系:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.easetech/easytest-core -->
<dependency>
<groupId>org.easetech</groupId>
<artifactId>easytest-core</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
注意:我已经尝试在依赖项上添加 cglib,但它不起作用。
注意2:我是Java和自动化的初学者,这是我学习阅读CVS文件的方式,我知道还有其他方法,但如果可能的话,我想继续使用相同的方法,如果没有,也可以学习一种新的方法也可以。
提前感谢!
看起来这个依赖项缺少"com.springsource.net.sf.cglib-2.2.0.jar"。 在pom中添加这个并尝试。
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
</dependency>