Parameterization (Using Scenario Outline)(Example)

package testRunner;


import org.junit.runner.RunWith;


import io.cucumber.junit.Cucumber;

import io.cucumber.junit.CucumberOptions;


@RunWith(Cucumber.class)

@CucumberOptions(features ={"src/test/java/Features"}, glue = {"Steps"}, tags = "@Par6", monochrome = true)

public class ParameterRunner {

}



==========================


@Par6

Scenario Outline: Home Page Links

Given I am in Ebay Shopping Homepage

When I click on '<link>'

Then I validated the page navigates to '<url>' and titie is '<title>'


Examples:

| link | url | title | |

| Deals | https://www.ebay.com/globaldeals | Daily Deals on eBay | Best deals and Free Shipping |

| Fashion | https://www.ebay.com/b/Fashion/bn_7000259856 | Fashion | eBay |

| Sports | https://www.ebay.com/b/Sporting-Goods/888/bn_1865031 | Sporting Goods | eBay |



==========================

package Steps;


import static org.testng.Assert.fail;


import java.util.List;

import java.util.Map;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;


import io.cucumber.datatable.DataTable;

import io.cucumber.java.en.Given;

import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;


public class ParameterSteps {

WebDriver driver;

public ParameterSteps(HookSteps hook_steps) {

this.driver=hook_steps.getDriver();

}

@Given("I am in Ebay Shopping Homepage")

public void i_am_in_ebay_shopping_homepage() throws InterruptedException {

driver.get("https://www.ebay.com/");

Thread.sleep(1000);

}


@When("I click on {string}")

public void i_click_on(String link) throws InterruptedException {

driver.findElement(By.linkText(link)).click();

Thread.sleep(1500);

}


@Then("I validated the page navigates to {string} and titie is {string}")

public void i_validated_the_page_navigates_to_and_titie_is(String url, String title) {

String cururl=driver.getCurrentUrl();

String actualtitle = driver.getTitle();

if (!cururl.contains(url)) {

throw new AssertionError("url not matched ! Expected" +url+ ", but found : "+cururl);

}

if (!actualtitle.contains(title)) {

throw new AssertionError("title not matched ! Expected " +title+ ", but found : "+actualtitle);

}

}

}


================