A complete program to run Maven BDD framework in Selenium:
//Feature File
Feature: Test the functionality A
@SmokeTest @SystemTest
Scenario Outline: Test the functionality A
Given open the browser
When the URL "https://www.google.com" is
entered
And enter <UID> and <PWD> and click Login
Then user should be logged in
Examples:
|UID|PWD|
|RamSmith|Ram@123|
//Step
Definition
public class StepDefinition {
WebDriver
driver = null;
@Before //Global hook
public void precondition() {
System.setProperty("webdriver.chrome.driver", "C:\\path\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
}
@Before("@SystemTest")//tagged hook
public void precondition() {
System.out.println(" This is Tagged Hook ");
}
@After //Global hook
public void postCondition() {
driver.quit();
}
@Given("^open the browser$")
public void openBrowser() throws Exception {
System.out.println("The browser is open");
}
@When("^the
URL \"(.*)\" is entered$")
public void brwserEntered(String url) throws Exception {
driver.get(url);
}
@And("^enter
\"(.*)\" and \"(.*)\" and click Login$")
public void brwserEntered(String uid, String pwd) throws Exception {
driver.findElement(By.xpath("..")).sendKeys(uid);
driver.findElement(By.xpath("..")).sendKeys(pwd);
driver.findElement(By.xpath("..")).click();
}
@Then("^user
should be logged into the page$")
public void insideaPge() throws Exception {
String
pageTitle = driver.getTitle();
Assert.assertEquals(pageTitle, "Googlelogin", "This is not correct");
}
//Test
Runner
@RunWith(Cucumber.class)
@CucumberOptions(
features
= "C:\\asdf.feature",
glue
= {"StepDefinition"},
dryRun
= false ,
format
= {"pretty","json:test-output/report.json","...xml","....html:test-output/report1.html"},
monochrome
= true,
tags
= {"~@SmokeTest", "@SystemTest"},//ignore @SmokeTest
strict
= true
)
public class TestRunner() {
}
No comments:
Post a Comment