0
  1. 配置文件

xml运行配置

  1. 提供者类:

    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}};
      }
    
  2. 特征:

    @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
    
  3. 脚步:

    @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);
       }
    }
    
  4. 结果:

    @QAFTestStep(description="META-DATA: {0}")
    public void mETADATA(Map<Object,Object> mapObj0){
       //TODO: remove NotYetImplementedException and call test steps
       throw new NotYetImplementedException();
    }
    

    测试被忽略。

4

1 回答 1

0

您正在使用GherkinScenarioFactorywhich expects bdd in gherkin 语法。在小黄瓜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']}")步骤定义类来将组添加到步骤中。这没有任何意义。应该将组分配给测试用例/场景而不是步骤。
  • 此外,您不需要放置@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);
   }
} 
于 2018-09-05T20:31:21.463 回答