Exemple #1
0
 static function start($browser)
 {
     $seleniumHost = "http://" . Config::get("SELENIUM_HOST") . ":" . Config::get("SELENIUM_PORT") . "/wd/hub";
     switch ($browser) {
         case "chrome":
             putenv("webdriver.chrome.driver=" . Config::get("CHROME_WEBDRIVER_PATH"));
             $capabilities = \DesiredCapabilities::chrome();
             $options = new \ChromeOptions();
             $options->addArguments(array("--start-maximized"));
             $options->addArguments(array("applicationCacheEnabled=1"));
             $capabilities->setCapability(\ChromeOptions::CAPABILITY, $options);
             break;
         case "ie":
             $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => "Internet Explorer");
             break;
         case "firefox_with_firebug":
             $profile = new \FirefoxProfile();
             $profile->setPreference('extensions.firebug.currentVersion', Config::get("FIREBUG_VERSION"));
             $profile->setPreference("extensions.firebug.allPagesActivation", "on");
             $profile->setPreference("extensions.firebug.defaultPanelName", "net");
             $profile->setPreference("extensions.firebug.net.enableSites", true);
             // Set default NetExport preferences
             $profile->setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
             $profile->setPreference("extensions.firebug.netexport.defaultLogDir", Config::get("LOG_PATH"));
             $profile->setPreference("extensions.firebug.netexport.showPreview", false);
             $profile->setPreference("extensions.firebug.netexport.autoExportToFile", true);
             $profile->setPreference("extensions.firebug.netexport.autoExportToServer", false);
             $profile->setPreference("extensions.firebug.netexport.includeResponseBodies", true);
             //$profile->setPreference("extensions.firebug.netexport.pageLoadedTimeout", 5000);
             $profile->addExtension(Config::get("FIREBUG_XPI_PATH"))->addExtension(Config::get("NET_EXPORT_XPI_PATH"));
             $capabilities = \DesiredCapabilities::firefox();
             $capabilities->setCapability(\FirefoxDriver::PROFILE, $profile);
             break;
         case "chrome_default_profile":
             putenv("webdriver.chrome.driver=" . Config::get("CHROME_WEBDRIVER_PATH"));
             $capabilities = \DesiredCapabilities::chrome();
             $options = new \ChromeOptions();
             $options->addArguments(array("start-maximized"));
             $options->addArguments(array("applicationCacheEnabled=1"));
             $options->addArguments(array("user-data-dir=" . Config::get("BROWSER_DATA_DIR")));
             $capabilities->setCapability(\ChromeOptions::CAPABILITY, $options);
             break;
         case "firefox_default_profile":
             // TODO: not working correctly. Need fix
             putenv("webdriver.firefox.profile=default");
             $profile = new \FirefoxProfile();
             $profile->setPreference("webdriver.firefox.profile", "default");
             //$profile->setPreference("webdriver.load.strategy", "unstable");
             $capabilities = \DesiredCapabilities::firefox();
             $capabilities->setCapability(\FirefoxDriver::PROFILE, $profile);
             break;
         default:
             // firefox by default
             $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => "firefox");
     }
     self::$driver = \RemoteWebDriver::create($seleniumHost, $capabilities, 90000, 90000);
 }
 public static function setUpBeforeClass()
 {
     InterfaceTest::$process = proc_open("java \"-Dwebdriver.chrome.driver=res/chromedriver.exe\" -jar res/selenium-server-standalone-2.48.2.jar", [["pipe", "r"], ["pipe", "w"]], $pipe);
     if (InterfaceTest::$process === false) {
         throw new Exception("Failed to start selenium server");
     }
     //loads a verified user 'testuser' with blid '4833' and email 'email@email.com` and password 'asdf'
     TestManager::loadBasicDummyData();
     InterfaceTest::$webDriver = RemoteWebDriver::create("http://localhost:4444/wd/hub", DesiredCapabilities::chrome());
 }
Exemple #3
0
 public static function start(DesiredCapabilities $desired_capabilities = null)
 {
     if ($desired_capabilities === null) {
         $desired_capabilities = DesiredCapabilities::chrome();
     }
     $service = ChromeDriverService::createDefaultService();
     $executor = new DriverCommandExecutor($service);
     $driver = new static();
     $driver->setCommandExecutor($executor)->startSession($desired_capabilities);
     return $driver;
 }
Exemple #4
0
 private function _initDriver()
 {
     $host = 'http://' . $this->_seleniumHost() . ':' . $this->_seleniumPort() . '/wd/hub';
     $driverName = $this->_seleniumDriver();
     if ($driverName === 'firefox') {
         $capabilities = \DesiredCapabilities::firefox();
     } elseif ($driverName === 'chrome') {
         $capabilities = \DesiredCapabilities::chrome();
     } else {
         throw new Exception("Invalid driver name {$driverName}");
     }
     $this->_driver = \RemoteWebDriver::create($host, $capabilities, $this->_seleniumTimeout());
 }
 /**
  * Get desired capabilities from config
  * @return DesiredCapabilities|null
  * @throws error browser type not supported
  */
 public function _getCapabilities()
 {
     $capabilities = null;
     switch ($this->_browser['type']) {
         default:
             $this->_error('ERROR Sorry this browser type is not supported.');
             break;
         case 'firefox':
             $profile = new FirefoxProfile();
             $capabilities = DesiredCapabilities::firefox();
             if (isset($this->_browser['extensions'])) {
                 foreach ($this->_browser['extensions'] as $i => $ext_path) {
                     if (!is_file($ext_path)) {
                         $this->_error('ERROR The extension file was not found: ' . $ext_path);
                     }
                     $profile->addExtension($ext_path);
                 }
             }
             // Set download preferences for the browser.
             $profile->setPreference("browser.download.folderList", 2);
             $profile->setPreference("xpinstall.signatures.required", false);
             $capabilities->setCapability(FirefoxDriver::PROFILE, $profile);
             break;
         case 'chrome':
             $options = new ChromeOptions();
             $capabilities = DesiredCapabilities::chrome();
             if (isset($this->_browser['extensions'])) {
                 foreach ($this->_browser['extensions'] as $i => $ext_path) {
                     if (!is_file($ext_path)) {
                         $this->_error('ERROR The extension file was not found: ' . $ext_path);
                     }
                     $options->addExtensions($this->_browser['extensions']);
                 }
             }
             // TODO: set options for auto-download if required. (check firefox preferences above).
             $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
             break;
     }
     return $capabilities;
 }
 /**
  * @return DesiredCapabilities The DesiredCapabilities for Chrome with this
  *                             options.
  */
 public function toCapabilities()
 {
     $capabilities = DesiredCapabilities::chrome();
     $capabilities->setCapability(self::CAPABILITY, $this);
     return $capabilities;
 }