Feature File
language-gherkinFeature: Application Login Background: When launch the browser from config variables And hit the homepage URL of the banking site @RegressionTest @Netbanking Scenario: User Page default Login with Reusability Given user netbanking login When user login with netbanking URL with "NormalUser1" and password "Pswd123953" Then Netbank homepage is displayed And users cards are displayed @Smoketest @RegressionTest @Mortage Scenario Outline: Mortgage user default login Given Mortgage user is landing in netbanking login page When Mortgage user is login with "<Username>" and password "<Password>" combination Then MortgageUser homepage is showing And MortgageUser cards are displayed in homepage Examples: | Username | Password | |---------------|------------| | MortgageUser1 | MRUser123 | | MortgageUser2 | MRUser456 |
Step Definitions
language-javapackage stepDefinitions;
import io.cucumber.java.After;
import io.cucumber.java.Before;
public class hookSteps {
@Before("@Netbanking")
public void netBankingSetup() {
System.out.println("Hook: setup the entries in Netbanking database");
}
@After
public void teardown() {
System.out.println("Hook: clear the entries ");
System.out.println("************************************************");
}
@Before("@Mortage")
public void mortageSetup() {
System.out.println("Hook: setup the entries in Mortage database");
}
}
Main Steps
language-javapackage stepDefinitions;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class MainSteps {
@When("launch the browser from config variables")
public void launch_the_browser_from_config_variables() {
System.out.println("Browser launched successfully");
}
@When("hit the homepage URL of banking site")
public void hit_the_homepage_url_of_banking_site() {
System.out.println("Hitting the banking site URL successfully");
}
@Given("user netbanking login")
public void user_netbanking_login() {
System.out.println("User landed on netbanking page with reusability");
}
@When("user login with netbanking URL with {string} and password {string}")
public void user_login_with_netbanking_URL(String username, String password) {
System.out.println("Username is ---> " + username + " & password is ---> " + password);
}
@Then("Netbank homepage is displayed")
public void Netbank_homepage_displayed() {
System.out.println("Home page is displayed");
}
@Then("users cards are displayed")
public void users_cards_are_displayed() {
System.out.println("Cards are displayed");
}
@Given("Mortgage user is landing in netbanking login page")
public void Mortgageuserislandingnetbankingpage() {
System.out.println("Mortgage User landed on netbanking page");
}
@When("Mortgage user is login with {string} and password {string} combination")
public void Mortgageuser_is_login_with_and_password_combination(String username, String password) {
System.out.println("User login with username ---> " + username + " & password is ---> " + password);
}
@Then("MortgageUser homepage is showing")
public void MortgageUserhomepageisshowing() {
System.out.println("Home page is showing to the users");
}
@Then("MortgageUser cards are displayed in homepage")
public void mortgage_user_cards_are_displayed_in_homepage() {
System.out.println("Cards are displayed to mortgage user");
}
}
Test Runner
language-javapackage cucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(features="src/test/java/features", glue ="stepDefinitions", tags= "@Smoketest or @RegressionTest", monochrome=true)
public class TestNGRunner extends AbstractTestNGCucumberTests {
}
Output:
Hook: setup the entries in Netbanking database
broswer launched successfully
Hitting the banking site URL successfully
User landed on netbanking page with resuablity
Username is ---> NormalUser1 & password is ---> Pswd123953
Home page is displayed
Cards are displayed
Hook: clear the entries
************************************************
Hook: setup the entries in Mortage database
broswer launched successfully
Hitting the banking site URL successfully
Mortage User landed on netbanking page
user login with username ---> MortageUser1 & password is ---> MRUser123
Home page is showing to the users
Cards are displayed to mortage user
Hook: clear the entries
************************************************
Hook: setup the entries in Mortage database
broswer launched successfully
Hitting the banking site URL successfully
Mortage User landed on netbanking page
user login with username ---> MortageUser2 & password is ---> MRUser456
Home page is showing to the users
Cards are displayed to mortage user
Hook: clear the entries
************************************************
PASSED: io.cucumber.testng.AbstractTestNGCucumberTests.runScenario("Mortage user default login", "Application Login")
Runs Cucumber Scenarios
PASSED: io.cucumber.testng.AbstractTestNGCucumberTests.runScenario("User Page default Login with Reusability", "Application Login")
Runs Cucumber Scenarios
PASSED: io.cucumber.testng.AbstractTestNGCucumberTests.runScenario("Mortage user default login", "Application Login")
Runs Cucumber Scenarios
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================
✅ Order of Execution in Your Setup
@Background
→ runs before each scenario
@Before
Hooks (tagged) → run before specific tagged scenarios
@After
Hook → runs after every scenario
Scenario
and Scenario Outline
Tags
to control execution from TestNGRunner
@Background
→ runs before each scenario
@Before
Hooks (tagged) → run before specific tagged scenarios
@After
Hook → runs after every scenario
Scenario
and Scenario Outline
Tags
to control execution from TestNGRunner
🔄 Test Flow – Execution Steps
tags = "@Smoketest or @RegressionTest"
Which means both scenarios will be executed
▶️ Execution Order – Step by Step
1️⃣ First Scenario: @RegressionTest @Netbanking
Scenario: User Page default Login with Reusability
Execution Flow:
2️⃣ Second Scenario Outline: @Smoketest @RegressionTest @Mortage
Executed twice (once per Examples row):
Iteration 1 – MortageUser1 / MRUser123
Iteration 2 – MortageUser2 / MRUser456
Same flow with different data