public function tearDown() { $reflection = print_r(WebDriver::instance(), true); // quit browser instance if it is not already if (Util::hasString($reflection, "HttpCommandExecutor Object")) { WebDriver::instance()->quit(); } }
public function testBooking() { WebDriver::instance()->get("http://trivago.com"); Helper::waitUntilDocumentIsLoaded(); // asset serch box is present and visible on page Assert::elementFound(TrivagoHome::getSelector("searchBox")); // enter search string in search box TrivagoHome::getElement("searchBox")->sendKeys(self::SEARCH_CITY); // wait untill suggestion list appears try { Helper::waitUntilVisible(TrivagoHome::getSelector("suggestions")); } catch (Exception $e) { $this->fail("After entering city name in search box, suggestion list did not appear"); } // suggeation list is visible, pick matching one $matchingCity = TrivagoHome::getMatchingOptionFromSuggestionDropdown(self::SEARCH_CITY, self::SERCH_COUNTRY); // assert we see expected option in suggestion list $this->assertFalse($matchingCity == null, "Expected option Hamburg (Germany) do not appear in suggestion list"); // we have matching city in option list $matchingCity->click(); // lets calender be visible sleep(1); $this->assertTrue(TrivagoHome::getElement("calendarPopup")->isDisplayed(), "After clicking on city from suggestion list, Calendar did not appear"); // close calendar in order to see the hotel list TrivagoHome::closeCalendar(); // hotel list is reloaded after intial load. hence wait // TODO: figure out better way to wait than just sleep for harcoded time sleep(6); TrivagoHome::waitUntilHotelListIsLoaded(); // collect all hotels from search list $hotels = TrivagoHome::getHotels(); // make sure we have sufficient hotels in list $this->assertTrue(count($hotels) > 2, "Not sufficient hotels found in list"); // as per test case, we need to pick second hotels from list // scroll page up before clicking on view all deals link Helper::scrollPageToBottomByPixel(300); $hotels[1]->viewAllDealsClick(); $hotels[1]->waitUntilDealsIsLoaded(); $hotelName = $hotels[1]->getName(); // deals are visible now $deals = $hotels[1]->getAllDeals(); // make sure we have few deals in list $this->assertTrue(count($deals) > 2, "Not sufficient deals found in list"); // as per test, click on third deal $deals[2]->click(); Helper::waitUntilPopupUrlContains('www.trivago'); // lets third party website load its content sleep(2); $window = new Window(); $this->assertTrue(Util::hasString($window->getText(), $hotelName, true), "Expected hotel name '{$hotelName}' do not found on partner website"); $window->close(); }
static function waitUntilPopupUrlContains($string, $waitSeconds = 20) { $expireSeconds = 0; $windows = WebDriver::instance()->getWindowHandles(); if (count($windows) < 2) { throw new \Exception("No popup window found"); } WebDriver::instance()->switchTo()->window($windows[1]); while ($expireSeconds < $waitSeconds) { if (Util::hasString(WebDriver::instance()->getCurrentURL(), $string)) { break; } sleep(1); $expireSeconds++; } // WebDriver::instance()->switchTo()->window($windows[0]); if ($expireSeconds >= $waitSeconds) { throw new Timeout("Timeout after {$waitSeconds} seconds wait. Url does not change from: {$string} to something else"); } }
public function hasText($text) { return Util::hasString($this->element->getText(), $text, true); }