Created
December 19, 2024 18:29
-
-
Save borodicht/47cd5a60a5b195c0976283b85cf28eee to your computer and use it in GitHub Desktop.
This file contains hidden or 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 steps; | |
import io.cucumber.java.en.Given; | |
import io.cucumber.java.en.Then; | |
import io.cucumber.java.en.When; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.testng.Assert; | |
import java.time.Duration; | |
import java.util.List; | |
public class SearchStep { | |
WebDriver driver; | |
@Given("booking search page is opened") | |
public void bookingSearchPageIsOpened() { | |
driver = new ChromeDriver(); | |
driver.manage().window().maximize(); | |
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | |
driver.get("https://www.booking.com/searchresults.en-gb.html"); | |
} | |
@When("user searches for {string}") | |
public void userSearchesFor(String hotel) { | |
driver.findElement(By.xpath("//input[@name = 'ss']")).sendKeys(hotel); | |
driver.findElement(By.cssSelector("button[type=submit]")).click(); | |
} | |
@Then("{string} hotel is shown") | |
public void hotelIsShown(String expectedResult) { | |
List<WebElement> titles = driver.findElements(By.xpath("//*[@data-testid='title']")); | |
boolean isHotelFound = false; | |
for (WebElement title: titles) { | |
if (title.getText().equals(expectedResult)) { | |
isHotelFound = true; | |
break; | |
} | |
} | |
Assert.assertTrue(isHotelFound); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment