Write the step definitions and implement the test methods for the previous feature file created in Exercise 1
Right-click on the feature file > Run As > Cucumber Feature.
In the console window, you will see an undefined scenario and a line “You can implement missing steps with the snippets below:”
Create a Java Class in your project and paste these code snippets and implement the test methods.
package cucumber;
import static org.testng.Assert.assertEquals;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class CucumberEx1 {
WebDriver driver = null;
@Given("Open Browser")
public void open_browser() {
driver = new ChromeDriver();
System.out.println("Chrome Browser is open");
}
@When("navigate to google.com")
public void navigate_to_google_com() {
driver.get("https://www.google.com/");
System.out.println("Navigate to Google");
}
@Then("Validate the Google page is open")
public void validate_the_google_page_is_open() {
String title = driver.getTitle();
assertEquals(title, "Google");
System.out.println("Validating the title of the webpage which is " +title);
}
@Then("Close the browser")
public void close_the_browser() {
driver.close();
System.out.println("Closing Browser");
}
}
Copyright © 2023 - Proleed Academy | All Rights Reserved.