如何只执行场景大纲的几个随机示例?

时间:2018-08-29 06:26:16

标签: selenium selenium-webdriver cucumber gherkin cucumber-java

方案概述:登录FaceBook

Given Enter "<emailId>"

And Enter the "<password>"

When Click on Login button

Then Navigated to HomePage

示例:

| emailId |密码|

| abc @ ***。com | abcd |

| 123 @ ***。com | 1234 |

| @@#$ @ ***。com | !@#$ |

->我只想用“ 123@***.com”执行测试用例。我们如何实现这一目标?

当我放置2个示例时,在第二个示例中出现了编译错误“在'Examples:'处缺少EOF”。

谢谢。

1 个答案:

答案 0 :(得分:2)

您可以使用标志来控制后续步骤的执行。方案大纲:创建

Given Enter "<emailId>"
And Enter Password "<password>"
And Check "<runFlag>"
When Click on Login button
Then Navigated to HomePage

Examples: 
  | emailId         | password | runFlag  |
  | abc@***.com     |     abcd | N        |
  | 123@***.com     |     1234 | Y        |
  | @#$@***.com     |     !@#$ | N        |

然后使用flag变量创建自己的逻辑,以控制执行流程和后续步骤的声明

private static String flag;

    @Given("^Enter \"([^\"]*)\"$")
    public void enter(String username) throws Throwable {
        System.out.println("=============================================================");
        System.out.println("Username: " + username);
    }

    @Given("^Enter Password \"([^\"]*)\"$")
    public void enter_p(String password) throws Throwable {
        System.out.println("Password: " + password);
    }

    @Given("^Check \"([^\"]*)\"$")
    public void check(String runFlag) throws Throwable {
        System.out.println("Run Flag: " + runFlag);
        flag = runFlag;
    }

    @When("^Click on Login button$")
    public void click_on_Login_button() throws Throwable {
        if("Y".equalsIgnoreCase(flag)){
            System.out.println("Clicked Login");
        }else{
            System.out.println("Skipped: RunFlag=" + flag);
        }
    }

    @Then("^Navigated to HomePage$")
    public void navigated_to_HomePage() throws Throwable {
        if("Y".equalsIgnoreCase(flag)){
            System.out.println("Navigated to homepage");
        }else{
            System.out.println("Skipped: RunFlag=" + flag);
        }
    }