Feature: Flipkart Shopping
@Tc01
Scenario: Flipkart homepage title Validation
Given I am on Flipkart Homepage
When I am validating the current URL
@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
===========================================================================
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;
}
}
============================================================================
package StepDefinations;
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 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");
}
@When("I click on Login button")
public void i_click_on_login_button() throws InterruptedException {
driver.findElement(By.xpath("//span[normalize-space()='Login']")).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);
}
}
=============================================================================
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 = "@Tc02 or @Tc01",
dryRun = false,
plugin = {"pretty", "html:target/cucumber-report.html"}
)
public class FlipKartTestRunner {
}
=============================================================================