/** * Loads google page and searches for some keyword */ public function testFetchGoogleResults() { if ($this->assertTrue($this->connect(), 'Failed connecting to Selenium web driver.')) { $url = 'http://www.google.com/'; $this->driver->get($url); $title = $this->driver->getTitle(); if ($this->assertTrue(false !== stripos($title, 'Google'), 'Failed loading page from [' . $url . ']')) { $element = $this->driver->findElementBy(LocatorStrategy::name, "q"); $element->sendKeys("php webdriver bindings"); $element->submit(); $image = $this->driver->getScreenshot(); $image = base64_decode($image); TestUtils::snapshot($image, 'google-screenshot-1', false, 'google-screenshot-1.png'); } // you may want to place it under tearDown() $this->driver->closeWindow(); } }
/** * Fetch page from google and search for some keyword. */ public function testFetchGoogleResults() { $browser = new SimpleBrowser(); // inject debugging cookie, if we want to debug request - makes sense only if we do request to the same server with DBG module if (!empty($_COOKIE['DBGSESSID'])) { $browser->setCookie('DBGSESSID', $_COOKIE['DBGSESSID']); } $url = 'http://www.google.com/'; $html = $browser->get($url); // store fetched page into temporary file and display quick download link TestUtils::snapshot($html, 'google-main-page'); if ($this->assertTrue(false !== stripos($browser->getTitle(), 'google'), 'Failed loading page from ' . $url . '!')) { $keyword = 'simpletest'; // load search results for "simpletest" $browser->setField('q', $keyword); $html = $browser->clickSubmitByName('btnG'); if ($this->assertTrue(false !== strpos($browser->getTitle(), $keyword), 'Failed loading search results for ' . $keyword . '!')) { TestUtils::snapshot($html, 'google-search-results'); } } }