import cucumber.api.DataTable; cannot be resolved

时间:2019-05-09 19:48:33

标签: maven selenium selenium-webdriver cucumber bdd

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.

3 个答案:

答案 0 :(得分:1)

要点:人们在混合直接和传递依赖项时几乎没有遇到错误(如下所述)。因此,我们将不会混用直接和传递依赖项,尤其是它们的版本!这样做可能导致不可预测的结果。

  • 无法解析导入的cumul.api.junit
  • java.lang.NoClassDefFoundError:gherkin / IGherkinDialectProvider
  • 导入cumul.api.DataTable;无法解决

解决方案:请删除 cucumber-java cucumber-core cucumber-jvm-deps ,< Strong> Gerkin 和 junit 。它们是传递依赖,将由您的依赖提供。您可以在下面添加一组最小的黄瓜依赖性。

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

答案 1 :(得分:0)

I。选项

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。选项 尝试将Cucumber-core和Cucumber Java依赖项更新到最新版本: 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>

然后-重新导入Maven。 希望这会有所帮助

答案 2 :(得分:-2)

功能:然后用户输入用户名和密码 | mngr193115 | edytadA |

从您的问题中,上面注意到的是您使用的功能文件。 我同意您必须导入数据表,然后才能将功能文件更改为以下内容

功能:检查联合国和密码

场景:ScenarioName

然后用户输入用户名和密码

| mngr193115 | edytadA |