我如何在黄瓜中运行特定场景

Rak*_*mar 7 cucumber selenium-webdriver cucumber-java

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

特征文件

Feature: Test Test Smoke scenario

  Scenario: Test login with valid credentials
    Given open firefox and start application
Run Code Online (Sandbox Code Playgroud)

jhbhhjhj 当我点击登录并输入有效的“kumar.rakesh@yopmail.com”和有效的“admin@123”然后点击登录,用户应该能够成功登录

  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 "kumar.rakesh@yopmail.com" and valid "admin@123"
    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
Run Code Online (Sandbox Code Playgroud)

测试运行器

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 {

}
Run Code Online (Sandbox Code Playgroud)

小智 7

在黄瓜中使用 future 标签,如下所示。

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 "kumar.rakesh@thoughtfocus.com" and valid "Thought@123"
    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 "kumar.rakesh@thoughtfocus.com" and valid "Thought@123"
    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
Run Code Online (Sandbox Code Playgroud)

如果您只想运行 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 {

}
Run Code Online (Sandbox Code Playgroud)

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

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 {

    }
Run Code Online (Sandbox Code Playgroud)


Gra*_*per 0

您需要使用标签来过滤场景。将标签放在功能文件上,并将其添加到运行器的 cucumberoptions 中。

@RunScenarioExample
Scenario: Test login with valid credential

@Cucumber.Options(features="features",glue={"steps"},format = {"pretty", "html:target/Destination"}, tags={"@RunScenarioExample"})
Run Code Online (Sandbox Code Playgroud)