在上一步输入数据表后,验证数据表中的期望

时间:2018-06-20 23:54:27

标签: java datatable cucumber

我的功能文件是:

 Scenario: New Application: Verify Verifycation Message
  Given user on Consumer Enquiry page as Internal Admin
  And user select New Application for Enquiry Type
  When user enters InputFileds to verify
|Product_Type|Member_Reference|ID_Number|ID_Expairy_Date|Date_of_Birth|Eng_Family_Name|Eng_First_Name|Arab_Family_Name|Arab_First_Name|
  ||||||||||
  |Credit Card|||||||||
  Then user should see Messages for the inputs
  |Message_Product_Type|Message_Member_Reference|Message_ID_Number|Message_ID_Expairy_Date|Message_Date_of_Birth|Message_Family_Name|Message_First_Name|
    |You must select the Product Type from the list.|You must enter the Member Reference.|You must enter the ID Number.|You must enter the ID Expiry Date.|You must enter the Date of Birth.|You must enter a Family Name.|You must enter a First Name.|
    ||You must enter the Member Reference.|You must enter the ID Number.|You must enter the ID Expiry Date.|You must enter the Date of Birth.|You must enter a Family Name.|You must enter a First Name.|

我要存档的是在键入不同的输入后验证同一页面的不同输出。

我的步骤定义如下:

@When("^user enters InputFileds to verify$")
public void user_enters_InputFileds_to_verify(List<ConsumerInputContext> consumerInputs) throws Throwable {
    pom.switchToMainFrame();
    for (ConsumerInputContext inputs : consumerInputs) {
        Wait.untilJqueryIsDone(testContext.getWebDriverManager().getDriver());
        consumerPage.sendProductType(inputs.getProduct_Type());
        consumerPage.sendMemberRef(inputs.getMember_Reference());
        consumerPage.sendIdNumberIpt(inputs.getID_Number());
        consumerPage.sendIdExpiryDateIpt(inputs.getID_Expairy_Date());
        consumerPage.sendDateOfBirthIpt(inputs.getDate_of_Birth());
        consumerPage.sendEngFamilyNameIpt(inputs.getEng_Family_Name());
        consumerPage.sendEngFirstNameIpt(inputs.getEng_First_Name());
        consumerPage.sendArabFamilyNameIpt(inputs.getArab_Family_Name());
        consumerPage.sendArabFirstNameIpt(inputs.getArab_First_Name());
        consumerPage.clickOnAddressButton();
        Wait.untilJqueryIsDone(testContext.getWebDriverManager().getDriver());
    }
    pom.switchToDefault();

}

@Then("user should see Messages for the inputs")
public void user_should_see_Messages_for_the_inputs(List<ConsumerInputMessage> msgTable) throws Throwable {
    pom.switchToMainFrame();
    System.out.println("consumerInputs.size=>" + msgTable.size());
    Wait.untilJqueryIsDone(testContext.getWebDriverManager().getDriver());
    List<String> actualMessages = consumerPage.getMessages();
    List<String> exptMessages = new ArrayList<String>();
    for (ConsumerInputMessage messages : msgTable) {
        if (!messages.getMessage_Product_Type().isEmpty())
            exptMessages.add(messages.getMessage_Product_Type());
        if (!messages.getMessage_Member_Reference().isEmpty())
            exptMessages.add(messages.getMessage_Member_Reference());
        if (!messages.getMessage_ID_Number().isEmpty())
            exptMessages.add(messages.getMessage_ID_Number());
        if (!messages.getMessage_ID_Expairy_Date().isEmpty())
            exptMessages.add(messages.getMessage_ID_Expairy_Date());
        if (!messages.getMessage_Date_of_Birth().isEmpty())
            exptMessages.add(messages.getMessage_Date_of_Birth());
        if (!messages.getMessage_Family_Name().isEmpty())
            exptMessages.add(messages.getMessage_Family_Name());
        if (!messages.getMessage_First_Name().isEmpty())
            exptMessages.add(messages.getMessage_First_Name());
    }
    Assert.assertEquals(actualMessages, exptMessages);
}

但是看起来每个step函数都运行整个数据表,然后运行next函数。最终我只能从最后一组输入文件中获取响应,而我要验证的数据表包含整个数据集。

任何人都可以分享您对此情况的解决方案吗?我认为这在现实生活中很普遍。

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要查看使用方案大纲而不是数据表。 ScenarioOutline将为每个数据集运行场景的完整步骤集。

Scenario Outline: New Application: Verify Verifycation Message
  Given user on Consumer Enquiry page as Internal Admin
  And user select New Application for Enquiry Type
  When user enters InputFileds to verify
    |Product_Type|Member_Reference|
    |<product_type>|<member_reference>|
  Then user should see Messages for the inputs
   |Message_Product_Type|Message_Member_Reference|
   |message_product_type>|<message_member_reference>|

  Examples:
      | Product_Type|Member_Reference|Message_Product_Type|Message_Member_Reference|
      | product type 1 |member reference 1|Message PT1|Message MR1|
      | product type 2 |member reference 2|Message PT2|Message MR2|

请参阅此-http://www.baeldung.com/cucumber-scenario-outline