Created
July 8, 2024 14:41
-
-
Save oofnivek/5d8f243a5c4a0157a32ccf619e9bf989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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