2017-04-21 57 views
2

如何在多场景中运行黄瓜中的特定场景?如何在黄瓜中运行特定场景

特性文件

Feature: Test Milacron Smoke scenario 

    Scenario: Test login with valid credentials 
    Given open firefox and start application 
    When I click on Login 
    And enter valid "[email protected]" and valid "[email protected]" 
    Then Click on login and User should be able to login successfully 

    Scenario: Test shop for cart 
    Given Click on shop for carts 
    And select plates 
    When Click on Add to cart 
    Then product should be added in the cart successfully 
    And verify the product 

Scenario: Test login with valid credentials1 
    Given open firefox and start application 
    When I click on Login 
    And enter valid "[email protected]" and valid "[email protected]" 
    Then Click on login and User should be able to login successfully 

    Scenario: Test shop for cart1 
    Given Click on shop for carts 
    And select plates 
    When Click on Add to cart 
    Then product should be added in the cart successfully 
    And verify the product 

测试运行

package runner; 

import org.junit.runner.RunWith; 

import cucumber.api.junit.Cucumber; 

@RunWith(Cucumber.class) 
@Cucumber.Options(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"}) 

public class TestRunnr { 

} 

回答

0

您需要使用标签来过滤掉的情况。将标签放在特征文件中,并将其添加到跑步者的黄瓜选项中。

@RunScenarioExample 
Scenario: Test login with valid credential 

@Cucumber.Options(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"}, tags={"@RunScenarioExample"}) 
1

在下面的黄瓜中使用标签未来。

Feature: Test Milacron Smoke scenario 

    @Test1 
    Scenario: Test login with valid credentials 
    Given open firefox and start application 
    When I click on Login 
    And enter valid "[email protected]" and valid "[email protected]" 
    Then Click on login and User should be able to login successfully 

    @Test2 
    Scenario: Test shop for cart 
    Given Click on shop for carts 
    And select plates 
    When Click on Add to cart 
    Then product should be added in the cart successfully 
    And verify the product 

    @Test3 
    Scenario: Test login with valid credentials1 
    Given open firefox and start application 
    When I click on Login 
    And enter valid "[email protected]" and valid "[email protected]" 
    Then Click on login and User should be able to login successfully 

    @Test4 
    Scenario: Test shop for cart1 
    Given Click on shop for carts 
    And select plates 
    When Click on Add to cart 
    Then product should be added in the cart successfully 
    And verify the product 

如果您只想运行Test1场景更新运行程序文件,如下所示。

import org.junit.runner.RunWith; 

import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 

@RunWith(Cucumber.class) 
@CucumberOptions(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"},tags={"@Test1"}) 
public class TestRunner { 

} 

如果要执行多个场景,请保留逗号分隔标签,如下所述。

import org.junit.runner.RunWith; 

    import cucumber.api.CucumberOptions; 
    import cucumber.api.junit.Cucumber; 

    @RunWith(Cucumber.class) 
    @CucumberOptions(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"},tags={"@Test1,@Test2"}) 
    public class TestRunner { 

    } 
2

像其他答案建议,使用标签。如果你使用Maven的时候,你不用改变转轮文件 - 只需添加到您的通话行家

-Dcucumber.options="--tags @Test1" 

我喜欢这个方法的事情是,我不会冒险在亚军犯下的标签文件。

此外,这里是一个在maven中运行多个标签的例子。

0

您可以在使用标签的功能中使用选择性功能文件或选择性场景。请尝试使用此解决方案。

让我们考虑你有n个特征文件,你只需要从中运行选择性特征。然后用@tag名称命名每个功能文件。

例如:在此文件夹,如果你有特点n个 - “的src /主/资源/发布”

1功能文件名:

Login.feature

//文件里面开始与功能变量名称

@Login 
Feature: To Login to Email 

//Then feature name followed with scenario tag name 
@User1 

#Scenario1: 
Scenario Outline: Navigate and logon to gmail application 

Given User launches gmail application 
When User updates emailID <emailID> 
And User updates pwd <pwd>  
Then User clicks on Login Button 


Examples: 
    | emailID | pwd | 
    | [email protected]| 123 | 


@User2 

#Scenario2: 
Scenario Outline: Navigate and logon to facebook application 

//Write the code for scenario 2 as similar to above 

第二个特点文件名:

CreateEmail.feature

@Createmail 
Feature: Create email 

Scenario: Blah blah blah... 

//Write all Given when And Then 

第三特征文件名:

SendEmail.feature

@Sendemail 
Feature: Send email 

Scenario: Blah blah blah... 

//Write all Given when And Then 

所以从上面的测试文件。让我们考虑要单独测试1和第3的功能,然后你可以使用如下代码:

例如:

//这是运行特定功能的文件,这是1和3。同样,你可以如果在同一个特征文件中有n个编号场景,也可以使用标签进行场景。

@CucumberOptions(features= "src/main/resources/publish", tags="@Login, @Sendemail", format = {"pretty"}) 

//这是在特征文件中运行特定场景。如果您有多个场景,那么您可以编写指定您的场景标签和逗号。

@CucumberOptions(features= "src/main/resources/publish/Login.feature", tags="@User2", format = {"pretty"})