web-dev-qa-db-ja.com

キュウリのデータベースエラー - io.cucumber.datatable.UndefinedDataTableTypeException:dataTableにcucumber.api.datatableに変換できません

Cucumber/selenium/java/Intellijを使用してシナリオを実行しようとしていますが、一方のステップでDataTableに関するエラーが発生しました。 DataTableは、テストランナーを使い始めていくつかのことを変更する前に、ステップの議論を正しく機能させて変換していましたが、これを機能させることはできません。

これがエラーです。

cucumber.runtime.CucumberException: Could not convert arguments for step [^I enter the following login details:$] defined at 'Steps.MaStepdefs.iEnterTheFollowingLoginDetails(DataTable) in file:/C:/Users/Kristian.Senior/Desktop/CukesReporting/target/test-classes/'.
It appears you did not register a data table type. The details are in the stacktrace below.
    at cucumber.runner.PickleStepDefinitionMatch.registerTypeInConfiguration(PickleStepDefinitionMatch.Java:59)
    at cucumber.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.Java:44)
    at cucumber.runner.TestStep.executeStep(TestStep.Java:63)
    at cucumber.runner.TestStep.run(TestStep.Java:49)
    at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.Java:43)
    at cucumber.runner.TestCase.run(TestCase.Java:45)
    at cucumber.runner.Runner.runPickle(Runner.Java:40)
    at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.Java:146)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.Java:68)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.Java:23)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.Java:309)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.Java:73)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.Java:122)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.Java:64)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:229)
    at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.Java:131)
    at org.junit.runners.ParentRunner.run(ParentRunner.Java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.Java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.Java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.Java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.Java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.Java:70)
Caused by: io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to cucumber.api.DataTable.
Please register a DataTableType with a TableTransformer, TableEntryTransformer or TableRowTransformer for cucumber.api.DataTable.
    at io.cucumber.datatable.UndefinedDataTableTypeException.singletonNoConverterDefined(UndefinedDataTableTypeException.Java:15)
    at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toSingleton(DataTableTypeRegistryTableConverter.Java:106)
    at io.cucumber.datatable.DataTableTypeRegistryTableConverter.convert(DataTableTypeRegistryTableConverter.Java:75)
    at io.cucumber.datatable.DataTable.convert(DataTable.Java:362)
    at io.cucumber.stepexpression.StepExpressionFactory$3.transform(StepExpressionFactory.Java:73)
    at io.cucumber.stepexpression.DataTableArgument.getValue(DataTableArgument.Java:19)
    at cucumber.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.Java:41)
    ... 29 more
 _

これが私のシナリオです:

Feature: LoginFeature
  This deals with logging in

  Scenario: Log in with correct username

    Given I navigate to the login page
    And I enter the following login details:
      | username | password |
      | cukey    | passwoid |
    And I click the login button
    Then I should land on the newest page
 _

これが私のステップ定義です:

package Steps;

import Base.BaseUtil;
import Pages.LoginPageObjeks;
import cucumber.api.DataTable;
import cucumber.api.PendingException;
import cucumber.api.Java.en.And;
import cucumber.api.Java.en.Given;
import cucumber.api.Java.en.Then;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.Assert;
import org.openqa.Selenium.By;
import org.openqa.Selenium.chrome.ChromeDriver;

import Java.util.ArrayList;
import Java.util.List;


public class MaStepdefs extends BaseUtil {
    private BaseUtil base;

    public MaStepdefs(BaseUtil base) {
        this.base = base;
    }

    @And("^I click the login button$")
    public void iClickTheLoginButton() throws Throwable {
        LoginPageObjeks page = new LoginPageObjeks(base.Driver);
        page.ClickLogin();

    }

    @Given("^I navigate to the login page$")
    public void iNavigateToTheLoginPage() throws Throwable {

        base.Driver.navigate().to("http://www.executeautomation.com/demosite/Login.html");

    }

    @And("^I enter the following login details:$")
    public void iEnterTheFollowingLoginDetails(DataTable table) throws Throwable {

        List<User> users = new ArrayList<User>();

        users = table.asList(User.class);

        LoginPageObjeks page = new LoginPageObjeks(base.Driver);

        for (User user : users) {
            page.Login(user.username, user.password);

            //base.Driver.findElement(By.name("UserName")).sendKeys(user.username);
            //base.Driver.findElement(By.name("Password")).sendKeys(user.password);

            Thread.sleep(2000);


        }
    }
        @Then("^I should land on the newest page$")
        public void iShouldLandOnTheNewestPage () throws Throwable {
            Assert.assertEquals("It's not displayed", base.Driver.findElement(By.id("Initial")).isDisplayed(), true);
        }



    }

    class User {
        public String username;
        public String password;

        public User(String userName, String passWord) {
            username = userName;
            password = passWord;
        }
    }
 _

これが私のPOMです:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.Apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.Apache.org/POM/4.0.0 http://maven.Apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>ownCukes</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
            </plugin>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>

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

        <dependency>
            <groupId>org.seleniumhq.Selenium</groupId>
            <artifactId>Selenium-Java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.2.0</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>4.2.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.6</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>


    </dependencies>


</project>
 _

そしてこれが私のTestRunnerです。

package Runner;


import cucumber.api.CucumberOptions;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = {"src/test/Java/features"}, glue = "Steps")

public class TestRunner {
}
 _

データテーブルの種類が何であるか、または登録する方法はわかりませんか。私はDataTableTypeとTypeGistryと一緒にめちゃくちゃにしてみましたが、私は専門家ではありません。あらゆる助けがありがとう

3
golf umbrella

あなたは古いバージョンを使用しています、それは今です:

import io.cucumber.datatable.DataTable;
 _

参照 [〜#〜] Changelog [〜#〜] キュウリJVM、引用:

[コア] DataTableをio.cucumber.datatable.datatableに置き換える(#1248 m.p. korstanje、BjörnRasmusson、Marit Van Dijk)カスタムデータテーブルタイプは、TypeRegistryConfigurerを実装することで定義できます。

これでそれを使用する方法はわずかに異なる方法があります。

サンプルGherkinステップ:

And I update ADDRESS tab data in building form
  | Input         | Value        |
  | Building name | New name     |
  | Ref           | Some ref     |
 _

ステップの実装:

@And("^some test step$")
public void someTestStep(DataTable table)
{
    List<List<String>> data = table.asLists(String.class);
    String buildingName = data.get(1).get(1);
    String reference = data.get(2).get(1);
}
 _
5
Matthewek
    I have created a code which will not use **DataTable** concept. You can update this below implementation so that you will not have any failures in your scripts in future.

    CucumberUtil.Java:
    -----------------
    import Java.util.HashMap;
    import Java.util.List;
    import Java.util.Map;

    public class CucumberUtil {
    //     public static synchronized Map<String, String> TableDictionaryConverter(DataTable table) {                    -- removed this concept because of version issues in DataTable
           public static synchronized Map<String, String> TableDictionaryConverter(List<List<String>> data) {
                  Map<String, String> mapTable = new HashMap<String, String>();
                  for(List<String> rows: data) {
                         mapTable.put(rows.get(0), rows.get(1)); 
                  }
                  return mapTable;
           }

feature:
-------
And I enter the following login details:
      | username | cukey    |
      | password | passwoid |

step defn:
---------
@And("^I enter the following login details:$")
    public void iEnterTheFollowingLoginDetails(List<List<String>> table) throws Throwable {

        Map<String, String> mapTable = CucumberUtil.TableDictionaryConverter(table);

        LoginPageObjeks page = new LoginPageObjeks(base.Driver);

        page.Login(mapTable.get("username"), mapTable.get("password"));

        Thread.sleep(2000);

        }
    }
 _
0
Gopi Chandran