Java 使用映射字段传递实体。如何映射从要素文件发送的变量
我试图传递一个只有一个字段的实体,这是一个映射>。我很难弄清楚如何让cucumber从实体中的特征文件传递变量 以下是实体对象:Java 使用映射字段传递实体。如何映射从要素文件发送的变量,java,selenium,automation,cucumber,Java,Selenium,Automation,Cucumber,我试图传递一个只有一个字段的实体,这是一个映射>。我很难弄清楚如何让cucumber从实体中的特征文件传递变量 以下是实体对象: public class Page { // change the List to represent a List of Questions when the class is implemented. private Map<Integer, List<String>> questions; public Map&
public class Page {
// change the List to represent a List of Questions when the class is implemented.
private Map<Integer, List<String>> questions;
public Map<Integer, List<String>> getQuestions() {
return questions;
}
public void setQuestions(Map<Integer, List<String>> questions) {
this.questions = questions;
}
}
步骤定义:
@And("^completes the questionnaire structure:$")
public void completesTheQuestionnaireStructure(List<Page> pages) throws Throwable {
questionnaireCreator.createQuestionnaireStructure(pages.get(0));
}
@和(“^完成问卷结构:$”)
public void complete问题重组(列表页)抛出可丢弃的{
questionnaireCreator.createQuestionnaireStructure(pages.get(0));
}
我想将映射的键设置为我从场景中传递的int,以及键后面的值特定的问题列表,目前它正在抛出一个异常:“cucumber.runtime.cucucumberException:Duplicate field questions”
有人遇到过这样的问题吗?你是如何着手解决的?不确定是否要将宁静和黄瓜混合在一起。如果可行,您可以尝试以下解决方案 另外,我从github和maven假设这个版本仍然只支持Cucumber2,所以XStream可以工作 需要从数据表中删除标题并修改问题列表。 并完成问卷结构:
| 1 | Q1 - NPS Question,Q2 - Fitness Driver Question,Q3 - Feedback Request Question |
| 2 | Q3 - Feedback Request Question |
在步骤定义代码中使用此选项。Cucumber本身无法将其转换为列表作为地图中的键。您可以使用新映射设置到页面对象中
@And("^completes the questionnaire structure:$")
public void completesTheQuestionnaireStructure(Map<Integer, String> pages) throws Throwable {
Map<Integer, List<String>> pageNew = new HashMap<>();
pages.forEach((k, v) -> pageNew.put(k, Arrays.asList(v.split(","))));
System.out.println(pageNew);
}
@和(“^完成问卷结构:$”)
public void complete问题重组(地图页)抛出可丢弃{
Map pageNew=新HashMap();
pages.forEach((k,v)->pageNew.put(k,Arrays.asList(v.split(“”));
系统输出打印项次(新页);
}
你正在使用哪一版本的cucumber?@Grasshopper Serenity with cucumber 1.9.8
@And("^completes the questionnaire structure:$")
public void completesTheQuestionnaireStructure(Map<Integer, String> pages) throws Throwable {
Map<Integer, List<String>> pageNew = new HashMap<>();
pages.forEach((k, v) -> pageNew.put(k, Arrays.asList(v.split(","))));
System.out.println(pageNew);
}