- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 cucumber-jvm 3.x.x
中,我想将只有 2 列的数据表转换为单个对象。这在 2.x.x
中曾经是自动的,但在新的主要版本中已被删除。
代码:
// 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");
}
堆栈跟踪:
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 | REDACTED |
最佳答案
除了@Transpose
,还需要修改transform方法。
public User transform(DataTable dataTable) throws Throwable {
return new User(dataTable.asMaps().get(0));
}
@When("I Log In As Valid User")
public void I_Log_In_As_Valid_User(@Transpose SilverUser user) throws Throwable {
System.out.println(user);
}
关于java - Cucumber-JVM 3 - 使用 asMap() 将 DataTable 转换为单个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51839707/
使用 Mobx,我尝试按照 booksSortedIdArray 中的顺序从 booksByIdMap 输出书籍的标题: class BookStore { @observable booksSo
我正在尝试 asMap 并希望输出与 coverType 匹配的书名: 这是BookStore: class BookStore { @observable coverType = 'soft
Javadoc说: Returns a view of the entries stored in this cache as a thread-safe map. Modifications mad
我正在使用 Google-guava-cache。将其定义为: Cache myCache= CacheBuilder.newBuilder().maximumSize(100).build();
本文整理了Java中org.springframework.beans.factory.config.YamlProcessor.asMap()方法的一些代码示例,展示了YamlProcessor.a
在 Guava 图书馆,我很困惑为什么Cache.asMap()与Cache.size()不一致, 除非 Cache.cleanUp()叫做。 Cache cache = CacheBuilder.n
在 cucumber-jvm 3.x.x 中,我想将只有 2 列的数据表转换为单个对象。这在 2.x.x 中曾经是自动的,但在新的主要版本中已被删除。 代码: // Feature Scenario:
假设我有这样的东西: Multimap data = TreeMultimap.create(); 我如何使用.headMap()在我的数据上?我想,TreeMultimap.asMap()这是要走的
我目前在一个对象上有以下属性: private IDictionary example; ExampleKey 在哪里 public class ExampleKey { public lon
我是一名优秀的程序员,十分优秀!