FlipkartWebElements.feature
Feature: Flipkart Shopping
@FlipkartWebElements @Tc01
Scenario: Flipkart homepage title Validation
Given I am on Flipkart Homepage
When I am validating the current URL
@FlipkartWebElements @Tc02
Scenario: Login Page Title Validation
Given I am on Flipkart Homepage
When I click on Login button
Then I validating the Navigated page url and Title of the Page
@FlipkartWebElements @Tc03
Scenario: Item Counting
Given I am in Ebay Shopping Homepage
When I am seaching for 'iphone13'
Then I am validating the itemcount atleast 1500
@FlipkartWebElements @Tc04
Scenario: Item Counting
Given I am in Ebay Shopping Homepage
When I am seaching for 'samsungs24'
Then I am validating the itemcount atleast 3000
@FlipkartWebElements @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 |
@FlipkartWebElements @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 |
@FlipkartWebElements @Tc07
Scenario Outline: HomePage links and Titile Validation
Given I am in Ebay Shopping Homepage
When I click on '<link>'
Then I Navigated to '<url>' and title 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 |
========================================================================
TestNGRunner.java
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\\FlipkartWebElements.feature",
glue = {"StepDefinations"},
monochrome = true,
tags = "@FlipkartWebElements and @Tc06",
dryRun = false,
plugin = {"pretty", "html:target/cucumber-report.html"}
)
public class FlipKartTestRunner {
}
========================================================================
CommonSteps.java(hooks)
package StepDefinations;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.After;
import io.cucumber.java.Before;
public class FlipKartCommonSteps {
private WebDriver driver;
@Before()
public void Setup() throws InterruptedException {
driver = new ChromeDriver();
driver.manage().window().maximize();
Thread.sleep(2000);
System.out.println("Got Executed ---> global hook- BEFORE");
}
@After()
public void QuitBrowser() throws InterruptedException {
driver.quit();
System.out.println("Got Executed ---> global hook- AFTER");
Thread.sleep(2000);
}
public WebDriver getDriver() {
return driver;
}
}
========================================================================
WebElements.java
package WebElements;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class FlipkartWebElements {
WebDriver driver;
@FindBy(xpath = "//span[normalize-space()='Login']") public WebElement Flipkartloginbutton;
@FindBy(id = "gh-ac") public WebElement EbayItemSearchText;
@FindBy(className = "gh-search-button__label") public WebElement EbaySearchButton;
@FindBy(css = "div[class='srp-controls__control srp-controls__count'] span:nth-child(1)") public WebElement EbaySearchItemCount;
@FindBy(linkText = "Advanced")public WebElement AdvanceSearchLink;
@FindBy(xpath = "//input[@id='_nkw']") public WebElement FirstrowFirstColumn;
@FindBy(xpath ="//input[@id='_ex_kw']")public WebElement FirstrowSecondColumn;
@FindBy(xpath ="//input[@name='_udlo']")public WebElement FirstrowThirdColumn;
@FindBy(xpath ="//input[@name='_udhi']")public WebElement FirstrowFourthColumn;
@FindBy(xpath = "//div[@class='field adv-keywords__btn-help']//button[@type='submit'][normalize-space()='Search']")
public WebElement FilterSearchButton;
public FlipkartWebElements(WebDriver driver) {
this.driver= driver;
PageFactory.initElements(driver, this);
}
}
========================================================================
FlipKartWebElementsSteps.java
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.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import WebElements.FlipkartWebElements;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class FlipKartWebElementsSteps {
WebDriver driver;
FlipkartWebElements elements;
public FlipKartWebElementsSteps(FlipKartCommonSteps commonsteps) {
this.driver = commonsteps.getDriver();
elements = new FlipkartWebElements(driver);
PageFactory.initElements(driver, elements);
}
@Given("I am on Flipkart Homepage")
public void i_am_on_flipkart_homepage() throws InterruptedException {
driver.get("https://www.flipkart.com/");
Thread.sleep(2000);
}
@When("I am validating the current URL")
public void i_am_validating_the_current_URL() {
String actualurl = driver.getCurrentUrl();
String expectedurl = "https://www.flipkart.com/";
if (actualurl.equals(expectedurl)) {
System.out.println("I am in Flipkart Homepage: Url is-->" + expectedurl);
} else
System.out.println("I am not in Flipkart Homepage");
driver.quit();
}
@When("I click on Login button")
public void i_click_on_login_button() throws InterruptedException {
elements.Flipkartloginbutton.click();
Thread.sleep(2000);
}
@Then("I validating the Navigated page url and Title of the Page")
public void i_validating_the_navigated_page_url_and_title_of_the_page() {
String actualurl = driver.getCurrentUrl();
String expectedurl = "https://www.flipkart.com/account/login?ret=/";
if (actualurl.equals(expectedurl)) {
System.out.println("I am in Flipkart Homepage: Url is-->" + expectedurl);
} else
System.out.println("I am not in Flipkart Homepage");
String expectedTitle = "Here's the amazing journey that you've had with Flipkart";
String actualTitle = driver.getTitle();
Assert.assertEquals(expectedTitle, actualTitle,
"title not matched ! Expected " + expectedTitle + ", but found : " + actualTitle);
}
@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) {
elements.EbayItemSearchText.sendKeys(str1);
elements.EbaySearchButton.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 advanced search on item")
public void I_advanced_search_on_item(io.cucumber.datatable.DataTable dataTable) throws InterruptedException {
elements.AdvanceSearchLink.click();
elements.FirstrowFirstColumn.sendKeys(dataTable.cell(1, 0));
elements.FirstrowSecondColumn.sendKeys(dataTable.cell(1, 1));
elements.FirstrowThirdColumn.sendKeys(dataTable.cell(1, 2));
elements.FirstrowFourthColumn.sendKeys(dataTable.cell(1, 3));
Thread.sleep(2000);
elements.FilterSearchButton.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) {
elements.FirstrowFirstColumn.clear();
elements.FirstrowFirstColumn.sendKeys(rows1.get("keyword"));
elements.FirstrowSecondColumn.clear();
elements.FirstrowSecondColumn.sendKeys(rows1.get("Exclude"));
elements.FirstrowThirdColumn.clear();
elements.FirstrowThirdColumn.sendKeys(rows1.get("min"));
elements.FirstrowFourthColumn.clear();
elements.FirstrowFourthColumn.sendKeys(rows1.get("max"));
Thread.sleep(2000);
elements.FilterSearchButton.click();
Thread.sleep(2000);
driver.navigate().back();
Thread.sleep(2000);
}
}
@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 Navigated to {string} and title is {string}")
public void i_navigated_to_and_title_is(String url, String title) {
String currenturl=driver.getCurrentUrl();
String currentTitle = driver.getTitle();
if(!currenturl.contains(url)) {
throw new AssertionError("url not matched ! Expected" +url+ ", but found : "+currenturl);
}
if(!currentTitle.contains(title)) {
throw new AssertionError("Title not matched ! Expected" +title+ ", but found : "+currentTitle);
}
}
}
==============================================
✅ Flipkart WebElements Flipkartloginbutton----> @FindBy(xpath = "//span[normalize-space()='Login']")
✅ eBay Search WebElements Element Name Locator EbayItemSearchText----> @FindBy(id = "gh-ac") EbaySearchButton----> @FindBy(className = "gh-search-button__label") EbaySearchItemCount----> @FindBy(css = "...")
✅ eBay Advanced Search Filters AdvanceSearchLink----> @FindBy(linkText = "Advanced") FirstrowFirstColumn----> @FindBy(xpath = "//input[@id='_nkw']") FirstrowSecondColumn----> @FindBy(xpath = "//input[@id='_ex_kw']") FirstrowThirdColumn----> @FindBy(xpath = "//input[@name='_udlo']") FirstrowFourthColumn----> @FindBy(xpath = "//input[@name='_udhi']") FilterSearchButton----> @FindBy(xpath = "...Search']")