I am trying to sum up the whole thing using few Bullet points.
You need to create 3 files in Eclipse.
- Feature file
- CreateAccount.feature
- Login.Feature
Feature: Login
Description: This feature is to test the login functionalityScenario: Successful Login with Valid Credentials
Given User is on Home Page
When User enters Username and Password
And Clicks Go button
Then A message is displayed
- Step Definition File:
@Given("^User is on Home Page$") public void user_is_on_Home_Page() { System.setProperty("webdriver.gecko.driver", "H:\\somePath\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); URL = "http://www.somesite.com/"; driver.get(URL); } @When("^User enters Username and Password$") public void user_enters_UserName_and_Password() { WebElement loginLink = driver.findElement(By.id("login")); loginLink.click(); WebElement emailField = driver.findElement(By.xpath("//div[@id='email']//input")); emailField.sendKeys("test@test.com"); WebElement passwordField = driver.findElement(By.xpath("//div[@id='password']//input")); passwordField.sendKeys("abcabc"); } @When("^Clicks Go button$") public void clicks_Go_button() { WebElement goButton = driver.findElement(By.id("goButton")); goButton.click(); } @Then("^A message is displayed$") public void a_message_is_displayed() throws Throwable { WebElement practicePage = driver.findElement(By.id("DrpDwn")); practicePage.click(); System.out.println("Login Successful"); } }public class TestingSteps { static WebDriver driver; static String URL;
- JUnit Runner
-
package tests; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions( features="src/feature", glue={"stepdefinition"} ) public class TestRun { }
4. Right click on the TestRunner file and click on Run as Java Application.
-