问题描述
我正在尝试将 vales 作为黄瓜中的 DataTable。如何在 QAF 中做到这一点?
@test
Scenario: DataTable Examples
Given I am on github login page
And I enter usernames and passwords "${args[0]}"
| testuser_1 | Test@153 |
StepDeFinition
@And("^I enter usernames and passwords \"([^\"]*)\"$")
public void iEnterUsernamesAndPasswords(Map<Object,Object> data) {
System.out.println("------------->" +data.get(0));
}
错误消息:
[WINDOWS 91.0.4472.77]: ▀ ▀ ▀ END STEP: Given I am on github login page ▀ ▀ ▀
17:28:22.608 [[WINDOWS 91.0.4472.77]] ERROR com.qmetry.qaf.automation.step.StepNotFoundException -
/**
* Auto-generated code snippet by QMetry Automation Framework.
*/
@QAFTestStep(description="I enter usernames and passwords {0}{1}")
public void iEnterUsernamesAndPasswords(String str0,Object[] objArray1){
//Todo: remove NotYetImplementedException and call test steps
throw new NotYetImplementedException();
}
/**
* Auto-generated code snippet by QMetry Automation Framework.
*/
@QAFTestStep(description="I enter usernames and passwords {0}{1}")
public void iEnterUsernamesAndPasswords(String str0,Object[] objArray1){
//Todo: remove NotYetImplementedException and call test steps
throw new NotYetImplementedException();
}
解决方法
args[0]
当您有数据驱动的场景(带有示例的场景)并且您想要从数据提供者引用整个记录时使用。在这种情况下,如果您想传递地图,您可以尝试以下方式:
@test
Scenario: DataTable Examples
Given I am on github login page
And I enter usernames and passwords "{'username':'testuser_1','password':'Test@153'}"
或
@test
Scenario: DataTable Examples
Given I am on github login page
And I enter usernames and passwords
| username | password |
| testuser_1 | Test@153 |
您可以参考 feature files 和 step implementation。