示例#1
0
 /**
  * Execute Sauce Labs REST API command
  *
  * @param string $requestMethod HTTP request method
  * @param string $url           URL
  * @param mixed  $parameters    Parameters
  *
  * @return mixed
  *
  * @see http://saucelabs.com/docs/saucerest
  */
 protected function execute($requestMethod, $url, $parameters = null)
 {
     $extraOptions = array(CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => $this->userId . ':' . $this->accessKey, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => array('Expect:'));
     $url = 'https://saucelabs.com/rest/v1/' . $url;
     list($rawResult, $info) = ServiceFactory::getInstance()->getService('service.curl')->execute($requestMethod, $url, $parameters, $extraOptions);
     return json_decode($rawResult, true);
 }
 /**
  * Loads a specific configuration.
  *
  * @param array $config Extension configuration hash (from behat.yml)
  * @param ContainerBuilder $container ContainerBuilder instance
  *
  * @throws \RuntimeException
  */
 public function load(array $config, ContainerBuilder $container)
 {
     /** @var \WebDriver\Service\CurlService $service */
     $f = ServiceFactory::getInstance();
     $f->setServiceClass('service.curl', '\\Selendroid\\Service\\CurlService');
     $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/services'));
     //        $loader->load('core.xml');
     if (isset($config['selendroid'])) {
         if (!class_exists('Selendroid\\Driver\\SelendroidDriver')) {
             throw new \RuntimeException('Install SelendroidDriver in order to activate selendroid session.');
         }
         $loader->load('sessions/selendroid.xml');
     }
     $minkParameters = array();
     foreach ($config as $ns => $tlValue) {
         if (!is_array($tlValue)) {
             $minkParameters[$ns] = $tlValue;
         } else {
             foreach ($tlValue as $name => $value) {
                 if ('guzzle_parameters' === $name) {
                     $value['redirect.disable'] = true;
                 }
                 $container->setParameter("behat.mink.{$ns}.{$name}", $value);
             }
         }
     }
     $container->setParameter('behat.mink.parameters', $minkParameters);
     if (isset($config['base_url'])) {
         $container->setParameter('behat.mink.base_url', $config['base_url']);
     }
     $container->setParameter('behat.mink.default_session', $config['default_session']);
     $container->setParameter('behat.mink.javascript_session', $config['javascript_session']);
     $container->setParameter('behat.mink.browser_name', $config['browser_name']);
     $minkReflection = new \ReflectionClass('Behat\\Mink\\Mink');
     $minkLibPath = realpath(dirname($minkReflection->getFilename()) . '/../../../');
     $container->setParameter('mink.paths.lib', $minkLibPath);
     if ($config['show_auto']) {
         $loader->load('failure_show_listener.xml');
     }
 }
 /**
  * Curl request to webdriver server.
  *
  * @param string $requestMethod HTTP request method, e.g., 'GET', 'POST', or 'DELETE'
  * @param string $command       If not defined in methods() this function will throw.
  * @param array  $parameters    If an array(), they will be posted as JSON parameters
  *                              If a number or string, "/$params" is appended to url
  * @param array  $extraOptions  key=>value pairs of curl options to pass to curl_setopt()
  *
  * @return array array('value' => ..., 'info' => ...)
  *
  * @throws \WebDriver\Exception if error
  */
 protected function curl($requestMethod, $command, $parameters = null, $extraOptions = array())
 {
     if ($parameters && is_array($parameters) && $requestMethod !== 'POST') {
         throw WebDriverException::factory(WebDriverException::NO_PARAMETERS_EXPECTED, sprintf('The http request method called for %s is %s but it has to be POST if you want to pass the JSON parameters %s', $command, $requestMethod, json_encode($parameters)));
     }
     $url = sprintf('%s%s', $this->url, $command);
     if ($parameters && (is_int($parameters) || is_string($parameters))) {
         $url .= '/' . $parameters;
     }
     list($rawResults, $info) = ServiceFactory::getInstance()->getService('service.curl')->execute($requestMethod, $url, $parameters, $extraOptions);
     $results = json_decode($rawResults, true);
     $value = null;
     if (is_array($results) && array_key_exists('value', $results)) {
         $value = $results['value'];
     }
     $message = null;
     if (is_array($value) && array_key_exists('message', $value)) {
         $message = $value['message'];
     }
     // if not success, throw exception
     if ((int) $results['status'] !== 0) {
         throw WebDriverException::factory($results['status'], $message);
     }
     $sessionId = isset($results['sessionId']) ? $results['sessionId'] : (isset($value['webdriver.remote.sessionid']) ? $value['webdriver.remote.sessionid'] : null);
     return array('value' => $value, 'info' => $info, 'sessionId' => $sessionId, 'sessionUrl' => $sessionId ? $this->url . '/session/' . $sessionId : $info['url']);
 }
 /**
  * Returns API class for service interaction.
  *
  * @return IAPIClient
  */
 public function getAPIClient()
 {
     return new BrowserStackAPIClient($this->getApiUsername(), $this->getApiKey(), ServiceFactory::getInstance()->getService('service.curl'));
 }
 /**
  * Creates API client.
  *
  * @param BrowserConfiguration $browser Browser configuration.
  *
  * @return IAPIClient
  * @throws \LogicException When unsupported browser configuration given.
  */
 public function createAPIClient(BrowserConfiguration $browser)
 {
     if ($browser instanceof SauceLabsBrowserConfiguration) {
         $sauce_rest = new SauceRest($browser->getApiUsername(), $browser->getApiKey());
         return new SauceLabsAPIClient($sauce_rest);
     } elseif ($browser instanceof BrowserStackBrowserConfiguration) {
         return new BrowserStackAPIClient($browser->getApiUsername(), $browser->getApiKey(), ServiceFactory::getInstance()->getService('service.curl'));
     }
     throw new \LogicException('Unsupported browser configuration given');
 }