@Par1
Scenario: Item Counting
Given I am in Ebay Shopping Homepage
When I am seaching for 'iphone13'
Then I am validating the itemcount atleast 1500
@Par2
Scenario: Item Counting
Given I am in Ebay Shopping Homepage
When I am seaching for 'samsungs24'
Then I am validating the itemcount atleast 3000
@Par3
Scenario: Search Item in Category
Given I am in Ebay Shopping Homepage
When I am seaching for 'soap' in 'Baby'
===================================================
package Steps;
import static org.testng.Assert.fail;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
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 am seaching for {string}")
public void i_am_seaching_for(String str1) {
driver.findElement(By.id("gh-ac")).sendKeys(str1);
driver.findElement(By.className("gh-search-button__label")).click();
}
@Then("I am validating the itemcount atleast {int}")
public void i_am_validating_the_itemcount_atleast(Integer minCount) {
String strCount =driver.findElement(By.cssSelector("div[class='srp-controls__control srp-controls__count'] span:nth-child(1)")).getText().trim();
int actualCount=Integer.parseInt(strCount.replace(",", ""));
if (actualCount < minCount) {
fail("Item count is less than expected. Found: " + actualCount + ", Expected: " + minCount);
}
}
@When("I am seaching for {string} in {string}")
public void i_am_seaching_for_in(String item, String category) throws InterruptedException {
driver.findElement(By.id("gh-ac")).sendKeys(item);
Thread.sleep(1000);
driver.findElement(By.id("gh-cat")).click();
List<WebElement> cat = driver.findElements(By.xpath("//select[@id='gh-cat']/option"));
for(WebElement x : cat) {
if(x.getText().trim().equals(category)) {
x.click();
break;
}
}
Thread.sleep(1000);
driver.findElement(By.className("gh-search-button__label")).click();
Thread.sleep(2000);
}
}
package testRunner;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(features ="src/test/java/Features", glue = "Steps", tags = "@Par1 or @Par2 or @Par3", monochrome = true)
public class ParameterRunner extends AbstractTestNGCucumberTests {
}