Skip to content

Instantly share code, notes, and snippets.

@oofnivek
Created July 8, 2024 14:41
Show Gist options
  • Save oofnivek/5d8f243a5c4a0157a32ccf619e9bf989 to your computer and use it in GitHub Desktop.
Save oofnivek/5d8f243a5c4a0157a32ccf619e9bf989 to your computer and use it in GitHub Desktop.
package stepDefinitions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class MyStepDefinitions {
WebDriver driver = new ChromeDriver();
String titleWanted;
@Given("User is at home page")
public void user_is_at_home_page() {
System.setProperty("webdriver.chrome.driver", "/Users/oofnivek/Documents/chromedriver");
driver.get("https://www.wikipedia.org/");
}
@When("User searched for a title {string}")
public void user_searched_for_a_title(String title) {
this.titleWanted = title.toLowerCase();
System.out.println(String.format("Title wanted = %s", titleWanted));
driver.findElement(By.xpath("//input[@id='searchInput']")).sendKeys(title + "\n");
}
@Then("User found the page")
public void user_found_the_page() {
String titleObtained = driver.findElement(By.xpath("//h1[@id='firstHeading']")).getText().toLowerCase();
System.out.println(String.format("String obtained = %s", titleObtained));
Assert.assertEquals(titleWanted, titleObtained);
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment