Example #1
0
 /**
  * Initialize a new webdriver connection if needed
  *
  * @access public
  */
 public static function get_webdriver()
 {
     if (self::$my_webdriver === null) {
         $capabilities = DesiredCapabilities::chrome();
         $driver = RemoteWebDriver::create(Config::$selenium_hub, $capabilities);
         self::$my_webdriver = $driver;
         self::$my_webdriver->manage()->timeouts()->implicitlyWait(5);
     }
     return self::$my_webdriver;
 }
Example #2
0
 /**
  * Get custom window size
  */
 public function testGetCustomWindowSize()
 {
     $capabilities = [WebDriverCapabilityType::BROWSER_NAME => 'firefox'];
     $this->webDriver = RemoteWebDriver::create('http://' . self::HOST . '/wd/hub', $capabilities);
     $this->webDriver->manage()->window()->setSize(new WebDriverDimension(640, 900));
     $this->webDriver->get('http://whatsmy.browsersize.com/');
     $foundWidth = $this->webDriver->findElement(WebDriverBy::id('info_ww'))->getText();
     self::assertTrue($foundWidth == 640 || $foundWidth == 632, $foundWidth);
     $this->webDriver->quit();
 }
Example #3
0
 public function testSaveSessionSnapshotsExcludeInvalidCookieDomains()
 {
     $this->notForPhantomJS();
     $fakeWdOptions = Stub::make('\\Facebook\\WebDriver\\WebDriverOptions', ['getCookies' => Stub::atLeastOnce(function () {
         return [['name' => 'PHPSESSID', 'value' => '123456', 'path' => '/'], ['name' => '3rdParty', 'value' => '_value_', 'path' => '/', 'domain' => '.3rd-party.net']];
     })]);
     $fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['manage' => Stub::atLeastOnce(function () use($fakeWdOptions) {
         return $fakeWdOptions;
     })]);
     // Mock the WebDriverOptions::getCookies() method on the first call to introduce a 3rd-party cookie
     // which has to be ignored when saving a snapshot.
     $originalWebDriver = $this->module->webDriver;
     $this->module->webDriver = $fakeWd;
     $this->module->seeCookie('PHPSESSID');
     $this->module->seeCookie('3rdParty');
     $this->module->saveSessionSnapshot('login');
     // Restore the original WebDriver
     $this->module->webDriver = $originalWebDriver;
     $this->webDriver->manage()->deleteAllCookies();
     $this->module->dontSeeCookie('PHPSESSID');
     $this->module->dontSeeCookie('3rdParty');
     $this->module->loadSessionSnapshot('login');
     $this->module->seeCookie('PHPSESSID');
     $this->module->dontSeeCookie('3rdParty');
 }
Example #4
0
	protected function login($username = '******')
	{
		$this->add_lang('ucp');

		$this->visit('ucp.php');
		$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource());

		self::$webDriver->manage()->deleteAllCookies();

		self::find_element('cssSelector', 'input[name=username]')->sendKeys($username);
		self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username);
		self::find_element('cssSelector', 'input[name=login]')->click();
		$this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText());

		$cookies = self::$webDriver->manage()->getCookies();

		// The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
		foreach ($cookies as $cookie)
		{
			if (substr($cookie['name'], -4) == '_sid')
			{
				$this->sid = $cookie['value'];
			}
		}

		$this->assertNotEmpty($this->sid);
	}
Example #5
0
 public function testSessionSnapshots()
 {
     $this->module->amOnPage('/');
     $this->module->setCookie('PHPSESSID', '123456', ['path' => '/']);
     $this->module->saveSessionSnapshot('login');
     $this->module->seeCookie('PHPSESSID');
     $this->webDriver->manage()->deleteAllCookies();
     $this->module->dontSeeCookie('PHPSESSID');
     $this->module->loadSessionSnapshot('login');
     $this->module->seeCookie('PHPSESSID');
 }
Example #6
0
 /**
  * @param string $name
  * @return bool
  */
 public function loadSessionSnapshot($name)
 {
     if (!isset($this->sessionSnapshots[$name])) {
         return false;
     }
     foreach ($this->sessionSnapshots[$name] as $cookie) {
         $this->webDriver->manage()->addCookie($cookie);
     }
     $this->debugSection('Snapshot', "Restored \"{$name}\" session snapshot");
     return true;
 }
Example #7
0
 /**
  * Sleep (implicit wait) for some seconds.
  *
  * @param $seconds
  *
  * @return $this
  */
 protected function sleep($seconds)
 {
     $this->driver->manage()->timeouts()->implicitlyWait($seconds);
     return $this;
 }