Example4-Parameterization-Singledata / Multidata

@Tc05

Scenario: Filters in Advanced Search Page

Given I am in Ebay Shopping Homepage

When I advanced search on item

| keyword | Exclude | min | max |

| iphone 11 | refurbished | 300 | 900 |

@Tc06

Scenario: Multiple Filters in Advanced Search Page

Given I am in Ebay Shopping Homepage

When I advanced search on items with multiple filters

| keyword | Exclude | min | max |

| iphone 11 | refurbished | 300 | 900 |

| iphone 13 | refurbished | 500 | 1000 |

| Samusung S24 | refurbished | 1000 | 5000 |

 

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

package TestNGRunnerFiles;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;

import io.cucumber.junit.CucumberOptions;


@RunWith(Cucumber.class)

@CucumberOptions(

features = "src/test/java/FeatureFiles",

glue = {"StepDefinations"},

monochrome = true,

tags = "@Tc05 or @Tc06",

dryRun = false,

plugin = {"pretty", "html:target/cucumber-report.html"}

)

public class FlipKartTestRunner {

}


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

package StepDefinations;


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.testng.Assert;


import io.cucumber.java.en.Given;

import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;


public class FlipKartSteps {


WebDriver driver;


public FlipKartSteps(FlipKartCommonSteps commonsteps) {

this.driver = commonsteps.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 advanced search on item")

public void I_advanced_search_on_item(io.cucumber.datatable.DataTable dataTable) throws InterruptedException {

driver.findElement(By.linkText("Advanced")).click();

driver.findElement(By.xpath("//input[@id='_nkw']")).sendKeys(dataTable.cell(1, 0));

driver.findElement(By.xpath("//input[@id='_ex_kw']")).sendKeys(dataTable.cell(1, 1));

driver.findElement(By.xpath("//input[@name='_udlo']")).sendKeys(dataTable.cell(1, 2));

driver.findElement(By.xpath("//input[@name='_udhi']")).sendKeys(dataTable.cell(1, 3));

Thread.sleep(2000);

driver.findElement(By.xpath(

"//div[@class='field adv-keywords__btn-help']//button[@type='submit'][normalize-space()='Search']"))

.click();

Thread.sleep(2000);

}


@When("I advanced search on items with multiple filters")

public void i_advanced_search_on_items_with_multiple_filters(io.cucumber.datatable.DataTable multidata)

throws InterruptedException {

driver.findElement(By.linkText("Advanced")).click();


List<Map<String, String>> rows = multidata.asMaps();

for (Map<String, String> rows1 : rows) {

driver.findElement(By.xpath("//input[@id='_nkw']")).clear();

driver.findElement(By.xpath("//input[@id='_nkw']")).sendKeys(rows1.get("keyword"));


driver.findElement(By.xpath("//input[@id='_ex_kw']")).clear();

driver.findElement(By.xpath("//input[@id='_ex_kw']")).sendKeys(rows1.get("Exclude"));


driver.findElement(By.xpath("//input[@name='_udlo']")).clear();

driver.findElement(By.xpath("//input[@name='_udlo']")).sendKeys(rows1.get("min"));


driver.findElement(By.xpath("//input[@name='_udhi']")).clear();

driver.findElement(By.xpath("//input[@name='_udhi']")).sendKeys(rows1.get("max"));


Thread.sleep(2000);

driver.findElement(By.xpath(

"//div[@class='field adv-keywords__btn-help']//button[@type='submit'][normalize-space()='Search']"))

.click();

Thread.sleep(2000);

driver.navigate().back();

Thread.sleep(2000);


}


}


}