Error running an automated script using Selenium Web Driver when trying to read a CSV file

301 Views Asked by At

I'm trying to run an automated test using Selenium Web Driver (ChromeWebDriver) and in the script I need to read a CSV file with some parameters, the purpose of the script is to make a login on a site using different users, but I'm getting the following error when running with JUnit 5:

Error:

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

This is the code I'm trying ro run:

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());
    }

}

This is the CSV file with the parameters:

loginComPlanilhaCSV, email, password, resultado
, [email protected], 123456, MY ACCOUNT
, [email protected], 123456, MY ACCOUNT
, [email protected], 123456, MY ACCOUNT

These are the dependencies I have on the pom.xml file:

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

NOTE: I've already tried adding the cglib on the dependencies, but it didn't work.

NOTE2: I'm a beginner in Java and automation and this was the way I learned to read a CVS file, I know there are other ways, but if possible I'd like to continue using the same, if not, it's ok to learn a new way that will work as well.

Thanks in advance!

1

There are 1 best solutions below

0
On

It looks like this dependency is missing "com.springsource.net.sf.cglib-2.2.0.jar". Add this one in pom and try.

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