【问题标题】:Cucumber Scenario Outline: Passing space strings " " as value in Examples tableCucumber 场景大纲:将空格字符串“”作为示例表中的值传递
【发布时间】:2020-09-06 08:09:10
【问题描述】:

我有一个 Cucumber 场景大纲,我想在其中的示例表中传递 6 个空格字符串 (" ") 作为值。在示例表中,将值留空,传递一个空字符串。我试过双引号和单引号,它是一样的。它传递 8 个字符串(包括 2 个引号),而不是 6 个。

场景大纲如下所示:

Scenario Outline: Change password - Negative Invalid Confirm Password

    Given I log in as a user on the change password page
    When I insert the current password
    And I insert password
    And I insert invalid confirm password <value>
    And I move focus to another element on the change password page
    Then <message> appears under the confirm password field

    Examples:                                                                                       
             |value           |message                           |
             |Aa1!            |Passwords Invalid or Do Not Match |
             |"      "        |Passwords Invalid or Do Not Match |

这就是特征定义的样子:

When(/^I insert invalid confirmPassword (.*)$/, async (confirmNewPass:string) => {
  await changePasswordPage.changePasswordComponent.insertConfirmNewPassword(confirmNewPass);
});

【问题讨论】:

    标签: typescript cucumber bdd gherkin


    【解决方案1】:

    你需要像这样创建特征文件

    Feature: Title of your feature
      I want to use this template for my feature file
    
    
      Scenario Outline: Title of your scenario outline
        Given I want to write a step 
        When I check for the <value> in step
        Then I verify the <message> in step
    
        Examples: 
         |value              |message                           |
         | "Aa1!"            | "Passwords Invalid or Do Not Match" |
         | "      "          | "Passwords Invalid or Do Not Match" |
    

    然后在步骤定义中你将不得不使用黄瓜表达式。

    示例代码写在下面

    @Given("I want to write a step")
    public void i_want_to_write_a_step() {
        // Write code here that turns the phrase above into concrete actions
        System.out.println("In a given method!");
    }
    @When("I check for the {string} in step")
    public void i_check_for_the_Aa1_in_step(String value) {
        // Write code here that turns the phrase above into concrete actions
         System.out.println("Value: " + value);
    }
    
    
    @Then("I verify the {string} in step")
    public void i_verify_the_Passwords_Invalid_or_Do_Not_Match_in_step(String message) {
        System.out.println("Message: " + message);
    }
    

    【讨论】:

    • 这真是太聪明了!
    • 它是 Java,但我需要 TypeScript 来定义此步骤:When(/^I insert invalid confirmPassword (.*)$/, async (confirmNewPass:string) => { await changePasswordPage.changePasswordComponent. insertConfirmNewPassword(confirmNewPass); });
    • 我的错,我也应该查看标签。我从来没有使用过我朋友的打字稿,但在业余时间我会研究一下。 :)
    • @DejanJovanović 它也适用于类型脚本。 cucumber.io/docs/cucumber/cucumber-expressions
    猜你喜欢
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多