【问题标题】:meta-data label in feature file can't be resolve in qaf 2.1.13qaf 2.1.13 中无法解析功能文件中的元数据标签
【发布时间】:2019-03-16 10:09:00
【问题描述】:
  1. config.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();
    }
    

    测试被忽略。

【问题讨论】:

    标签: testng bdd gherkin qaf


    【解决方案1】:

    您正在使用GherkinScenarioFactory,它需要在 gherkin 语法中使用 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']}") 放置在步骤定义类中来将组添加到步骤中。这没有任何意义。应将组分配给测试用例/场景而不是步骤。
    • 此外,您不需要将@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);
       }
    } 
    

    【讨论】:

    • 嗨@user861594,我用这个例子只是想知道如何使用qaf的dataprovider,我的场景是我需要sql一组来自oracle的数据,每个数据将用于发布到一个API 获取响应,然后将 sql 数据与响应进行比较。我已经完成了这个场景使用一个sql数据,但是我需要使用一组数据。
    • 这看起来是一个单独的问题。您可以确认当前问题并发布另一个问题。
    • 使用数据库查询应该可以通过meta-datasqlQuery实现。对于使用 qaf 进行 API 测试,您可以参考 qaf-wf-support
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    相关资源
    最近更新 更多