static function at($url, $title = null) { self::$unitTest->assertEquals(trim(WebDriver::instance()->getCurrentUrl(), "/"), trim($url, "/")); if ($title) { self::$unitTest->assertEquals(WebDriver::instance()->getTitle(), $title); } }
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 close() { if (!$this->switchTo()) { return false; } $url = WebDriver::instance()->close(); $this->switchToDefault(); return true; }
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 getElementY($element) { return WebDriver::instance()->findElement(\WebDriverBy::cssSelector(self::get($element)))->getLocation()->getY(); }
static function buildMessage($message) { $prefix = str_replace(BASE_URL, '', WebDriver::instance()->getCurrentUrl()); $prefix = $prefix ? $prefix : '/'; $prefix .= '@' . self::getBrowserClientWidth() . 'x' . self::getBrowserClientHeight(); $message = str_replace('{{browser_url}}', WebDriver::instance()->getCurrentUrl(), $message); $message = str_replace('{{browser_width}}', self::getBrowserClientWidth(), $message); $message = str_replace('{{browser_height}}', self::getBrowserClientHeight(), $message); return "{$prefix}: {$message}"; }
public function click() { // normal click not working. Use mouse hover and click WebDriver::instance()->action()->moveToElement($this->element)->clickAndHold()->release()->perform(); }