public class CustomDataProdvider {
@DataProvider(name="my-custom-dp")
public static Object[][] dataProviderForBDD(){
Map<Object, Object> rec1 = Maps.newHashMap();
rec1.put("fruit", "grapes");
rec1.put("color", "green");
Map<Object, Object> rec2 = Maps.newHashMap();
rec2.put("fruit", "banana");
rec2.put("color", "yellow");
return new Object[][]{ {rec1},{rec2}};
}
@TestForTest
SCENARIO : Custom Data provider Example
META-DATA: {"dataProvider":"my-custom-dp", "dataProviderClass":"com.qmetry.qaf.example.CustomDataProvider", "description":"Data driven test that uses custom data provider"}
Given I am on fruits and colors activity
When i select '${fruit}'
Then the color should be '${color}'
END
@MetaData(value = "{'groups':['smoke']}")
@QAFTestStepProvider
public class TestDataProdivider {
@QAFTestStep(description = "I am on fruits and colors activity")
public void test(){
System.out.println("I am on fruits and colors activity");
}
@QAFTestStep(description = "i select {fruit}")
public void testfruit(String fruit){
System.out.println(fruit);
}
@QAFTestStep(description = "the color should be {color}")
public void testcolor(String color){
System.out.println(color);
}
}
@QAFTestStep(description="META-DATA: {0}")
public void mETADATA(Map<Object,Object> mapObj0){
//TODO: remove NotYetImplementedException and call test steps
throw new NotYetImplementedException();
}
测试被忽略了您正在使用GherkinScenarioFactory
,它希望bdd采用小黄瓜语法。在小黄瓜Meta-data
不受支持,但在qaf-bdd支持。你应该使用com.qmetry.qaf.automation.step.client.text.BDDTestFactory
。您的bdd文件,比如说suite1.bdd,应该如下所示与BDDTestFactory
一起使用。
SCENARIO : Custom Data provider Example
META-DATA: {"dataProvider":"my-custom-dp", "dataProviderClass":"com.qmetry.qaf.example.CustomDataProvider", "description":"Data driven test that uses custom data provider","groups":{"TestForTest","smoke"}}
Given I am on fruits and colors activity
When i select '${fruit}'
Then the color should be '${color}'
END
如果你与原始进行比较,你会发现@TestForTest
移动了元数据,使你的场景与qaf-bdd兼容。确保您的bdd文件具有扩展名.bdd
以与BDDTestFactory
一起使用。
您的配置文件应如下所示:
<suite name="QAF-Demo" verbose="0">
<test name="BDD Tests">
<parameter name="step.provider.pkg" value="com.qmetry.qaf.example.steps" />
<parameter name="scenario.file.loc" value="scenarios" />
<groups>
<run>
<include name="TestForTest"/>
</run>
</groups>
<classes>
<class name="com.qmetry.qaf.automation.step.client.text.BDDTestFactory" />
</classes>
</test>
</suite>
很少有观察到:
@MetaData(value = "{'groups':['smoke']}")
放在步骤定义类中来将组添加到步骤中。这没有任何意义。应将组分配给testcase / scenario而不是步骤。@QAFTestStepProvider
,因为您使用@QAFTestStep
将方法标记为步骤。所以你的步骤定义类应该如下所示:
public class TestDataProdivider {
@QAFTestStep(description = "I am on fruits and colors activity")
public void test(){
System.out.println("I am on fruits and colors activity");
}
@QAFTestStep(description = "i select {fruit}")
public void testfruit(String fruit){
System.out.println(fruit);
}
@QAFTestStep(description = "the color should be {color}")
public void testcolor(String color){
System.out.println(color);
}
}