Could not convert arguments for asMap() in DataTable
See original GitHub issueSummary
Error when converting a DataTable with 2 columns (col1 = key, col2 = value) to a single object using TableTransformer
with asMap()
.
Expected Behavior
To map the DataTable to a single object. Same behavior as asMap()
in cucumber-jvm 2.x.x
.
Current Behavior
From the docs:
<String, String> Map<String, String> io.cucumber.datatable.DataTable.asMap(Type keyType, Type valueType)
Converts the table to a single map of keyType to valueType.
For each row the first cell is used to create the key value. The remaining cells are used to create the value. If the table only has a single column that value is null.
So for each row, the entry in the first column is expected to be the key in the map.
// Feature
Scenario: Scan Barcode
Given I Am At The Login Page
When I Log In As Valid User
| group | gpao |
| username | svgpao1 |
| password | REDACTED |
// Stepdef
@When("I Log In As Valid User")
public void I_Log_In_As_Valid_User(User user) throws Throwable {
Selenium.enterText(driver, user.getUsername(), "username");
Selenium.enterText(driver, user.getPassword(), "password");
Selenium.clickElement(driver, "sign.in");
LOGGER.debug("User Group=" + user.getGroup());
}
// Configurer
registry.defineDataTableType(new DataTableType(User.class, new TableTransformer<User>() {
@Override
public User transform(DataTable dataTable) throws Throwable {
Map<String, String> map = dataTable.asMap(String.class, String.class);
return new User(map);
}
}));
// User - constructor
public User(Map<String, String> map) {
this.group = map.get("group");
this.username = map.get("username");
this.password = map.get("password");
}
Stacktrace:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running jcucumberng.project.RunCukesTest
@sv @checker @packet
Feature: Enter Packet Details
As a checker
I want to enter the packet details
So that I can start entering item marks for scripts
@sv @checker @packet @barcode
Scenario: Scan Barcode # src/test/resources/jcucumberng/project/features/EnterPacketDetails.feature:8
[INFO ] 2018-08-16 13:19:39,520 ScenarioHook.beforeScenario() - BEGIN TEST -> Scan Barcode
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 33489
Only local connections are allowed.
Aug 16, 2018 1:19:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[INFO ] 2018-08-16 13:19:43,921 ScenarioHook.beforeScenario() - Browser=CHROME32_NOHEAD
[INFO ] 2018-08-16 13:19:45,089 ScenarioHook.beforeScenario() - Screen Resolution (WxH)=1920x1080
[DEBUG] 2018-08-16 13:19:46,919 EnterPacketDetailsSteps.I_Am_At_The_Login_Page() - Base URL=https://stable-scriptvalidation.cambridgeassessment.org.uk/#/login
Given I Am At The Login Page # EnterPacketDetailsSteps.I_Am_At_The_Login_Page()
When I Log In As Valid User # EnterPacketDetailsSteps.I_Log_In_As_Valid_User(User)
cucumber.runtime.CucumberException: Could not convert arguments for step [I Log In As Valid User] defined at 'jcucumberng.project.stepdefs.EnterPacketDetailsSteps.I_Log_In_As_Valid_User(User) in file:/Z:/workspace/java/jcucumberng-framework/target/test-classes/'.
The details are in the stacktrace below.
at cucumber.runtime.PickleStepDefinitionMatch.couldNotConvertArguments(PickleStepDefinitionMatch.java:69)
at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:46)
at cucumber.runner.TestStep.executeStep(TestStep.java:55)
at cucumber.runner.TestStep.run(TestStep.java:42)
at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)
at cucumber.runner.TestCase.run(TestCase.java:47)
at cucumber.runner.Runner.runPickle(Runner.java:44)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
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:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:98)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:55)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:107)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:383)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:344)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:417)
Caused by: io.cucumber.datatable.CucumberDataTableException: 'jcucumberng.project.domain.User' could not transform
| group | gpao |
| username | svgpao1 |
| password | *********** |
at io.cucumber.datatable.DataTableType.transform(DataTableType.java:86)
at io.cucumber.datatable.DataTableTypeRegistryTableConverter.convert(DataTableTypeRegistryTableConverter.java:53)
at io.cucumber.datatable.DataTable.convert(DataTable.java:336)
at io.cucumber.stepexpression.StepExpressionFactory$3.transform(StepExpressionFactory.java:72)
at io.cucumber.stepexpression.DataTableArgument.getValue(DataTableArgument.java:19)
at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:39)
... 33 more
Caused by: io.cucumber.datatable.CucumberDataTableException: Can't convert DataTable to Map<class java.lang.String,class java.lang.String>. You have to write the conversion for it in this method
at io.cucumber.datatable.ConversionRequired.toMap(ConversionRequired.java:33)
at io.cucumber.datatable.DataTable.asMap(DataTable.java:206)
at jcucumberng.project.typeregistry.DataTableConfigurer$2.transform(DataTableConfigurer.java:39)
at jcucumberng.project.typeregistry.DataTableConfigurer$2.transform(DataTableConfigurer.java:1)
at io.cucumber.datatable.DataTableType$TableTransformerAdaptor.transform(DataTableType.java:219)
at io.cucumber.datatable.DataTableType.transform(DataTableType.java:83)
... 38 more
And I Click The 'Scan barcode' Button # EnterPacketDetailsSteps.I_Click_The_Button(String)
[INFO ] 2018-08-16 13:19:47,956 ScenarioHook.afterScenario() - END TEST -> Scan Barcode - FAILED
Failed scenarios:
src/test/resources/jcucumberng/project/features/EnterPacketDetails.feature:8 # Scan Barcode
1 Scenarios (1 failed)
3 Steps (1 failed, 1 skipped, 1 passed)
0m11.013s
cucumber.runtime.CucumberException: Could not convert arguments for step [I Log In As Valid User] defined at 'jcucumberng.project.stepdefs.EnterPacketDetailsSteps.I_Log_In_As_Valid_User(User) in file:/Z:/workspace/java/jcucumberng-framework/target/test-classes/'.
The details are in the stacktrace below.
at cucumber.runtime.PickleStepDefinitionMatch.couldNotConvertArguments(PickleStepDefinitionMatch.java:69)
at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:46)
at cucumber.runner.TestStep.executeStep(TestStep.java:55)
at cucumber.runner.TestStep.run(TestStep.java:42)
at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)
at cucumber.runner.TestCase.run(TestCase.java:47)
at cucumber.runner.Runner.runPickle(Runner.java:44)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
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:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:98)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:55)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:107)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:383)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:344)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:417)
Caused by: io.cucumber.datatable.CucumberDataTableException: 'jcucumberng.project.domain.User' could not transform
| group | gpao |
| username | svgpao1 |
| password | *********** |
at io.cucumber.datatable.DataTableType.transform(DataTableType.java:86)
at io.cucumber.datatable.DataTableTypeRegistryTableConverter.convert(DataTableTypeRegistryTableConverter.java:53)
at io.cucumber.datatable.DataTable.convert(DataTable.java:336)
at io.cucumber.stepexpression.StepExpressionFactory$3.transform(StepExpressionFactory.java:72)
at io.cucumber.stepexpression.DataTableArgument.getValue(DataTableArgument.java:19)
at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:39)
... 33 more
Caused by: io.cucumber.datatable.CucumberDataTableException: Can't convert DataTable to Map<class java.lang.String,class java.lang.String>. You have to write the conversion for it in this method
at io.cucumber.datatable.ConversionRequired.toMap(ConversionRequired.java:33)
at io.cucumber.datatable.DataTable.asMap(DataTable.java:206)
at jcucumberng.project.typeregistry.DataTableConfigurer$2.transform(DataTableConfigurer.java:39)
at jcucumberng.project.typeregistry.DataTableConfigurer$2.transform(DataTableConfigurer.java:1)
at io.cucumber.datatable.DataTableType$TableTransformerAdaptor.transform(DataTableType.java:219)
at io.cucumber.datatable.DataTableType.transform(DataTableType.java:83)
... 38 more
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 14.498 s <<< FAILURE! - in jcucumberng.project.RunCukesTest
[ERROR] Scan Barcode(Enter Packet Details) Time elapsed: 10.508 s <<< ERROR!
cucumber.runtime.CucumberException:
Could not convert arguments for step [I Log In As Valid User] defined at 'jcucumberng.project.stepdefs.EnterPacketDetailsSteps.I_Log_In_As_Valid_User(User) in file:/Z:/workspace/java/jcucumberng-framework/target/test-classes/'.
The details are in the stacktrace below.
Caused by: io.cucumber.datatable.CucumberDataTableException:
'jcucumberng.project.domain.User' could not transform
| group | gpao |
| username | svgpao1 |
| password | *********** |
Caused by: io.cucumber.datatable.CucumberDataTableException: Can't convert DataTable to Map<class java.lang.String,class java.lang.String>. You have to write the conversion for it in this method
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] Could not convert arguments for step [I Log In As Valid User] defined at 'jcucumberng.project.stepdefs.EnterPacketDetailsSteps.I_Log_In_As_Valid_User(User) in file:/Z:/workspace/java/jcucumberng-framework/target/test-classes/'. The details are in the stacktrace below.
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.674 s
[INFO] Finished at: 2018-08-16T13:19:50+08:00
[INFO] ------------------------------------------------------------------------
Possible Solution
public User transform(DataTable dataTable) throws Throwable {
Map<String, String> map = dataTable.asMaps().get(0);
return new User(map);
}
public void I_Log_In_As_Valid_User(@Transpose User user) throws Throwable {
// Do something
}
While this achieves the expected result, asMap()
was supposed to do this by default without @Transpose
.
Your Environment
- Version used: 3.0.2
- Operating System and version: Win7 Pro SP1 x64
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
The old behaviour made it impossible to disambiguate between a transposed and regular 4x4 table.
By not making any assumptions about the table orientation we avoid this problem.
It also makes the use of the api a bit more consistent and less magical.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.