【问题标题】:Error running an automated script using Selenium Web Driver when trying to read a CSV file尝试读取 CSV 文件时使用 Selenium Web Driver 运行自动化脚本时出错
【发布时间】:2018-11-08 23:00:59
【问题描述】:

我正在尝试使用 Selenium Web Driver (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 文件的方式,我知道还有其他方式,但如果可能的话,我想继续使用相同的方式,如果没有,可以学习一种同样有效的新方法。

提前致谢!

【问题讨论】:

  • 我可以正常运行您的代码。
  • 我认为这是我的计算机的问题,一位同事也能够毫无错误地运行代码,但另一个人遇到了同样的问题,我们找不到问题所在。我已经重新安装了 Eclipse,但我一直遇到同样的问题。
  • 我尝试了其他帖子中提出的解决方案,但仍然遇到同样的错误。

标签: java selenium-webdriver junit selenium-chromedriver chrome-web-driver


【解决方案1】:

此依赖项似乎缺少“com.springsource.net.sf.cglib-2.2.0.jar”。 在 pom 中添加这个并尝试。

<dependency>
  <groupId>cglib</groupId>
  <artifactId>cglib-nodep</artifactId>
  <version>2.2</version>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-12
    • 2018-12-29
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 2016-03-23
    相关资源
    最近更新 更多