/** * Performs an HTTP request to the Selenium 2 server. * * @param string $method 'GET'|'POST'|'DELETE'|... * @param string $url * @param array $params JSON parameters for POST requests */ public function curl($http_method, PHPUnit_Extensions_Selenium2TestCase_URL $url, $params = NULL) { $curl = curl_init($url->getValue()); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_HTTPHEADER, array('application/json;charset=UTF-8')); if ($http_method === 'POST') { curl_setopt($curl, CURLOPT_POST, TRUE); if ($params && is_array($params)) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); } else { if ($http_method == 'DELETE') { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); } } $rawResponse = trim(curl_exec($curl)); $info = curl_getinfo($curl); if ($info['http_code'] == 404) { if ($this->isNotAnAndroidDriverErrorToWorkAround($info)) { throw new BadMethodCallException("The command {$url} is not recognized by the server."); } } curl_close($curl); $content = json_decode($rawResponse, TRUE); return new PHPUnit_Extensions_Selenium2TestCase_Response($content, $info); }
/** * @return \self * @throws InvalidArgumentException */ public static function fromResponseValue(array $value, PHPUnit_Extensions_Selenium2TestCase_URL $parentFolder, PHPUnit_Extensions_Selenium2TestCase_Driver $driver) { if (!isset($value['ELEMENT'])) { throw new InvalidArgumentException('Element not found.'); } $url = $parentFolder->descend($value['ELEMENT']); return new self($driver, $url); }
/** * @param array $parameter */ public function __construct($parameter, PHPUnit_Extensions_Selenium2TestCase_URL $equalsResourceBaseUrl) { $this->jsonParameters = array(); if (!$parameter instanceof PHPUnit_Extensions_Selenium2TestCase_Element) { throw new InvalidArgumentException("Elements can only test equality with other Element instances."); } $this->url = $equalsResourceBaseUrl->descend($parameter->getId()); }
public function __construct($url, $commandUrl, PHPUnit_Extensions_Selenium2TestCase_URL $baseUrl) { if ($url !== NULL) { $absoluteLocation = $baseUrl->jump($url)->getValue(); $jsonParameters = array('url' => $absoluteLocation); } else { $jsonParameters = NULL; } parent::__construct($jsonParameters, $commandUrl); }
/** * Performs an HTTP request to the Selenium 2 server. * * @param string $method 'GET'|'POST'|'DELETE'|... * @param string $url * @param array $params JSON parameters for POST requests */ public function curl($http_method, PHPUnit_Extensions_Selenium2TestCase_URL $url, $params = NULL) { $curl = curl_init($url->getValue()); curl_setopt($curl, CURLOPT_TIMEOUT, $this->seleniumServerRequestsTimeout); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json;charset=UTF-8', 'Accept: application/json;charset=UTF-8')); if ($http_method === 'POST') { file_put_contents('E:/realpost', "####url#####" . $url->getValue() . "###param###" . json_encode($params) . "######" . PHP_EOL, FILE_APPEND); curl_setopt($curl, CURLOPT_POST, TRUE); if ($params && is_array($params)) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } else { curl_setopt($curl, CURLOPT_POSTFIELDS, ''); } curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); } else { if ($http_method == 'DELETE') { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); } } $rawResponse = trim(curl_exec($curl)); if (curl_errno($curl)) { throw new PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException('Error connection[' . curl_errno($curl) . '] to ' . $url->getValue() . ': ' . curl_error($curl)); } $info = curl_getinfo($curl); if ($info['http_code'] == 0) { throw new PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException(); } if ($info['http_code'] == 404) { throw new BadMethodCallException("The command {$url} is not recognized by the server."); } if ($info['http_code'] >= 400 && $info['http_code'] < 500) { throw new BadMethodCallException("Something unexpected happened: '{$rawResponse}'"); } curl_close($curl); $content = json_decode($rawResponse, TRUE); if ($content === null && json_last_error() !== JSON_ERROR_NONE) { throw new PHPUnit_Extensions_Selenium2TestCase_Exception(sprintf("JSON decoding of remote response failed.\n" . "Error code: %d\n" . "The response: '%s'\n", json_last_error(), $rawResponse)); } $value = null; if (is_array($content) && array_key_exists('value', $content)) { $value = $content['value']; } $message = null; if (is_array($value) && array_key_exists('message', $value)) { $message = $value['message']; } $status = isset($content['status']) ? $content['status'] : 0; if ($status !== PHPUnit_Extensions_Selenium2TestCase_WebDriverException::Success) { throw new PHPUnit_Extensions_Selenium2TestCase_WebDriverException($message, $status); } return new PHPUnit_Extensions_Selenium2TestCase_Response($content, $info); }
/** * @param \Nette\DI\Container $context */ public function __construct(\Nette\DI\Container $context) { $this->context = $context; $seleniumServerUrl = new \PHPUnit_Extensions_Selenium2TestCase_URL($context->parameters['selenium']['seleniumServer']); $driver = new \PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl); $sessionCreationApiUrl = $seleniumServerUrl->descend("/wd/hub/session"); $sessionCreationResponse = $driver->curl('POST', $sessionCreationApiUrl, array('desiredCapabilities' => $context->parameters['selenium']['desiredCapabilities'])); $sessionApiUrl = $sessionCreationResponse->getUrl(); $baseUrl = new \PHPUnit_Extensions_Selenium2TestCase_URL($context->parameters['selenium']['baseUrl']); $timeouts = new \PHPUnit_Extensions_Selenium2TestCase_Session_Timeouts($driver, $sessionApiUrl->descend('timeouts'), 60 * 1000); parent::__construct($driver, $sessionApiUrl, $baseUrl, $timeouts); }
public function session(array $parameters) { $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($parameters['host'], $parameters['port']); $driver = new PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl); $session = $driver->startSession($parameters['browser'], $parameters['browserUrl']); return $session; }
public function session(array $parameters) { $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($parameters['host'], $parameters['port']); $driver = new PHPUnit_Extensions_AppiumTestCase_Driver($seleniumServerUrl, $parameters['seleniumServerRequestsTimeout']); $capabilities = array_merge($parameters['desiredCapabilities'], array('browserName' => $parameters['browserName'])); $session = $driver->startSession($capabilities, $parameters['browserUrl']); return $session; }
/** * Performs an HTTP request to the Selenium 2 server. * * @param string $method 'GET'|'POST'|'DELETE'|... * @param string $url * @param array $params JSON parameters for POST requests */ public function curl($http_method, PHPUnit_Extensions_Selenium2TestCase_URL $url, $params = NULL) { $curl = curl_init($url->getValue()); curl_setopt($curl, CURLOPT_TIMEOUT, $this->seleniumServerRequestsTimeout); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json;charset=UTF-8', 'Accept: application/json;charset=UTF-8')); if ($http_method === 'POST') { curl_setopt($curl, CURLOPT_POST, TRUE); if ($params && is_array($params)) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } else { curl_setopt($curl, CURLOPT_POSTFIELDS, ''); } curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); } else { if ($http_method == 'DELETE') { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); } } $rawResponse = trim(curl_exec($curl)); if (curl_errno($curl)) { throw new PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException('Error connection[' . curl_errno($curl) . '] to ' . $url->getValue() . ': ' . curl_error($curl)); } $info = curl_getinfo($curl); if ($info['http_code'] == 0) { throw new PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException(); } if ($info['http_code'] == 404) { throw new BadMethodCallException("The command {$url} is not recognized by the server."); } curl_close($curl); $content = json_decode($rawResponse, TRUE); if ($info['http_code'] == 500) { $message = ''; if (isset($content['value']['message'])) { $message .= $content['value']['message']; } else { $message .= "Internal server error while executing {$http_method} request at {$url}. Response: " . var_export($content, TRUE); } if (isset($content['value']['class'])) { $message .= PHP_EOL . $content['value']['class']; } throw new PHPUnit_Extensions_Selenium2TestCase_WebDriverException($message, isset($content['status']) ? $content['status'] : 13); } return new PHPUnit_Extensions_Selenium2TestCase_Response($content, $info); }
public function byCssSelector($selector) { $this->elementsChecked[] = $selector; if (in_array($selector, $this->elements)) { $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort('www.dummy.com', 80); $driver = new PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl); return new PHPUnit_Extensions_Selenium2TestCase_Element($driver, $seleniumServerUrl); } else { throw new PHPUnit_Framework_ExpectationFailedException('Element with CSS selector ' . $selector . ' does not exist'); } }
/** * @param array $parameters * @return BrowserSession */ public function create(array $parameters = array()) { $parameters += $this->defaults; $seleniumServerUrl = \PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($parameters['host'], $parameters['port']); $driver = new \PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl, $parameters['seleniumServerRequestsTimeout']); $capabilities = array_merge($parameters['desiredCapabilities'], array('browserName' => $parameters['browserName'])); $sessionCreation = $seleniumServerUrl->descend("/wd/hub/session"); $response = $driver->curl('POST', $sessionCreation, array('desiredCapabilities' => $capabilities)); $sessionPrefix = $response->getURL(); $timeouts = new \PHPUnit_Extensions_Selenium2TestCase_Session_Timeouts($driver, $sessionPrefix->descend('timeouts'), $parameters['seleniumServerRequestsTimeout'] * 1000); return new BrowserSession($this->sl, $driver, $sessionPrefix, $parameters, $timeouts); }
/** * @param array $propertyName */ public function __construct($propertyName, PHPUnit_Extensions_Selenium2TestCase_URL $cssResourceBaseUrl) { $this->jsonParameters = array(); $this->url = $cssResourceBaseUrl->descend($propertyName); }
/** * @param array $parameter */ public function __construct($parameter, PHPUnit_Extensions_Selenium2TestCase_URL $attributeResourceBaseUrl) { $this->jsonParameters = array(); $this->url = $attributeResourceBaseUrl->descend($parameter); }
/** * @return string */ public function start() { if ($this->browserUrl == NULL) { throw new PHPUnit_Framework_Exception('setBrowserUrl() needs to be called before start().'); } if ($this->webDriverCapabilities !== NULL) { $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($this->host, $this->port); $driver = new PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl); $session = $driver->startSession($this->webDriverCapabilities, new PHPUnit_Extensions_Selenium2TestCase_URL($this->browserUrl)); $webDriverSessionId = $session->id(); $this->sessionId = $this->getString('getNewBrowserSession', array($this->browser, $this->browserUrl, '', "webdriver.remote.sessionid={$webDriverSessionId}")); $this->doCommand('setTimeout', array($this->seleniumTimeout * 1000)); } if (!isset($this->sessionId)) { $this->sessionId = $this->getString('getNewBrowserSession', array($this->browser, $this->browserUrl)); $this->doCommand('setTimeout', array($this->seleniumTimeout * 1000)); } return $this->sessionId; }
private function getDriver() { $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($this->host, $this->port); return new PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl); }