Chaitanya Maligi
Chaitanya Maligi

Reputation: 215

import cucumber.api.DataTable; cannot be resolved

I am trying to automate DataTables in Cucumber where i have written the appropriate feature and step definition for the same. Eclipse is suggesting to import io.cucumber.datatable.DataTable; and when I use the raw() method, eclipse throws an error saying "The method raw() is undefined for the type DataTable"

Feature : Then user enters username and password
| mngr193115 | edytadA |

Step Definition :

@Then("^user enters username and password$")
    public void user_enters_username_and_password(DataTable credentials) {
        //driver.findElement(By.linkText("ACCOUNT")).click();
        List<List<String>> data = credentials.raw();
        driver.findElement(By.xpath("//input[@type='text']")).sendKeys();       
        driver.findElement(By.name("password")).sendKeys(password);
    }

Below is my POM.xml file

 <dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm</artifactId>
    <version>4.3.0</version>
    <type>pom</type>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>4.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>gherkin</artifactId>
    <version>5.1.0</version>
</dependency>
<dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
     <version>3.141.59</version>
 </dependency>   
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>
</dependencies>
</project>

expected - to resolve the import issues and import cucumber.api.DataTable;

Actual - Eclipse is suggesting to import import io.cucumber.datatable.DataTable; for DataTable and when I import the same, i am not able to use raw() method.

Upvotes: 0

Views: 8329

Answers (5)

Uttam Shrestha
Uttam Shrestha

Reputation: 1

I also had an issue while using raw() so instead I changed it to cells() which worked fine

    @And("^I enter following for login$")
    public void iEnterFollowingForLogin(DataTable table) throws Throwable{
        List<List<String>> data = table.cells();
        System.out.println("Username: "+data.get(1).get(0));
        System.out.println("Password: "+data.get(1).get(1));
    }

Upvotes: 0

saitharun
saitharun

Reputation: 11

If you are using io.cucumber instead of cucumber.api import then use cells() method which is an alternative of the raw() method in io.cucumber package.

Example:

List<List<String>> testData = data.cells();

System.out.println(testData.get(0).get(0)); //displays the first element of dataTable //of 0th row and 0th column

Upvotes: 1

Santhanaprabha
Santhanaprabha

Reputation: 11

Feature : Then user enters username and password | mngr193115 | edytadA |

From your question what is notice was above was the feature file you used. I agree that you have to do import for datatable and before that can you please change the feature file to below if not

Feature : To check the UN and Pwd

Scenario : ScenarioName

Then user enters username and password

| mngr193115 | edytadA |

Upvotes: -2

Main Point: People have been facing few errors (mentioned below) as they mix direct & transitive dependencies. So we shall not mix direct & transitive dependencies specially their versions! Doing so can cause unpredictable outcome.

  • The import cucumber.api.junit cannot be resolved
  • java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
  • import cucumber.api.DataTable; cannot be resolved

Solution: Please remove cucumber-java, cucumber-core, cucumber-jvm-deps, gherkin & junit. They're transitive dependencies and will be provided by your dependencies. You can add below set of minimal cucumber dependencies.

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>

Upvotes: 4

eugene.polschikov
eugene.polschikov

Reputation: 7339

I. option

https://mvnrepository.com/artifact/io.cucumber/datatable-dependencies/1.1.12 https://mvnrepository.com/artifact/io.cucumber/datatable/1.0.3

<!-- https://mvnrepository.com/artifact/io.cucumber/datatable-dependencies -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>datatable-dependencies</artifactId>
    <version>1.1.12</version>
</dependency>



<!-- https://mvnrepository.com/artifact/io.cucumber/datatable -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>datatable</artifactId>
    <version>1.0.3</version>
</dependency>

II. option Try out to update cucumber-core and cucumber java dependencies up to latest versions: https://mvnrepository.com/artifact/io.cucumber/cucumber-core/4.3.1

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>4.3.1</version>
</dependency>

https://mvnrepository.com/artifact/io.cucumber/cucumber-java

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.3.1</version>
</dependency>

And after that- do maven reimport. Hope this helps

Upvotes: 0

Related Questions