How to run specific scenario in cucumber out of multiple scenario?
Feature file
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 "Thought@123"
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 "Thought@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
Test Runner
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 {
}
Use tags future in the cucumber like below.
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 "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 "[email protected]" 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
If you want to run only Test1 scenario update runner file like below.
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 {
}
If you want to execute multiple scenarios keep comma sepearated tags as mentioned below.
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 {
}