@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 |
=======================================================================
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 on Flipkart Homepage")
public void i_am_on_flipkart_homepage() throws InterruptedException {
driver.get("https://www.flipkart.com/");
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);
}
}}
=========================================================================
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 = "@Tc07",
dryRun = false,
plugin = {"pretty", "html:target/cucumber-report.html"}
)
public class FlipKartTestRunner {
}
=========================================================================