コード例 #1
0
 protected function getDriver(array $browser)
 {
     $local = isset($browser['local']) && $browser['local'];
     $this->is_local_test = $local;
     if (!$local) {
         SauceTestCommon::RequireSauceConfig();
         $build = SauceConfig::GetBuild();
     } else {
         unset($browser['local']);
     }
     $defaults = array('browser' => 'firefox', 'browserVersion' => '11', 'os' => 'Windows 2008', 'timeout' => 60, 'httpTimeout' => 45, 'host' => 'ondemand.saucelabs.com', 'port' => 80, 'name' => get_called_class() . '::' . $this->getName(), 'record-video' => true, 'video-upload-on-pass' => true);
     $local_defaults = array('browser' => 'firefox', 'timeout' => 30, 'httpTimeout' => 45, 'host' => 'localhost', 'port' => 4444, 'name' => get_called_class() . '::' . $this->getName());
     if ($local) {
         $browser = array_merge($local_defaults, $browser);
     } else {
         $browser = array_merge($defaults, $browser);
     }
     $checks = array('name' => 'string', 'browser' => 'string', 'browserVersion' => 'string', 'timeout' => 'int', 'httpTimeout' => 'int', 'os' => 'string');
     if ($local) {
         unset($checks['browserVersion']);
         unset($checks['os']);
     }
     foreach ($checks as $key => $type) {
         $func = 'is_' . $type;
         if (!$func($browser[$key])) {
             throw new InvalidArgumentException('Array element "' . $key . '" is no ' . $type . '.');
         }
     }
     if ($local) {
         $driver = new \PHPUnit_Extensions_SeleniumTestCase_Driver();
     } else {
         $driver = new SeleniumRCDriver();
     }
     if (!$local) {
         $driver->setUsername(SAUCE_USERNAME);
         $driver->setAccessKey(SAUCE_ACCESS_KEY);
         $driver->setOs($browser['os']);
         $driver->setBrowserVersion($browser['browserVersion']);
         $driver->setRecordVideo($browser['record-video']);
         $driver->setUploadVideoOnPass($browser['video-upload-on-pass']);
         $build = isset($browser['build']) ? $browser['build'] : $build;
         if ($build) {
             $this->build = $build;
         }
     }
     $driver->setHost($browser['host']);
     $driver->setPort($browser['port']);
     $driver->setName($browser['name']);
     $driver->setBrowser($browser['browser']);
     $driver->setTimeout($browser['timeout']);
     $driver->setHttpTimeout($browser['httpTimeout']);
     $driver->setTestCase($this);
     $driver->setTestId($this->testId);
     $this->drivers[0] = $driver;
     return $driver;
 }
コード例 #2
0
ファイル: TestCase.php プロジェクト: scottdixon/sausage
 public function setupSpecificBrowser($params)
 {
     // Setting 'local' gives us nice defaults of localhost:4444
     $local = isset($params['local']) && $params['local'];
     $this->is_local_test = $local;
     if (!$local) {
         SauceTestCommon::RequireSauceConfig();
     }
     // Give some nice defaults
     if (!isset($params['seleniumServerRequestsTimeout'])) {
         $params['seleniumServerRequestsTimeout'] = 60;
     }
     if (!isset($params['browserName'])) {
         $params['browserName'] = 'chrome';
         $params['desiredCapabilities'] = array('version' => '', 'platform' => 'VISTA');
     }
     // Set up host
     $host = isset($params['host']) ? $params['host'] : false;
     if ($local) {
         $this->setHost($host ? $host : 'localhost');
     } else {
         $sauce_host = SAUCE_USERNAME . ':' . SAUCE_ACCESS_KEY . '@ondemand.saucelabs.com';
         $this->setHost($host ? $host : $sauce_host);
     }
     // Set up port
     $port = isset($params['port']) ? $params['port'] : false;
     $this->setPort($port ? $port : ($local ? 4444 : 80));
     // Set up other params
     $this->setBrowser($params['browserName']);
     $caps = isset($params['desiredCapabilities']) ? $params['desiredCapabilities'] : array();
     $this->setSeleniumServerRequestsTimeout($params['seleniumServerRequestsTimeout']);
     $build = isset($params['build']) ? $params['build'] : SauceConfig::GetBuild();
     if ($build && !isset($caps['build'])) {
         $caps['build'] = $build;
     }
     $this->setDesiredCapabilities($caps);
     // If we're using Sauce, make sure we don't try to share browsers
     if (!$local && !$host && isset($params['sessionStrategy'])) {
         $params['sessionStrategy'] = 'isolated';
     }
     $this->setUpSessionStrategy($params);
 }