コード例 #1
1
 public static function Curl($http_type, $full_url, $payload = null, $escape_payload = true)
 {
     $curl = curl_init($full_url);
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $http_type);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_HEADER, TRUE);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
     curl_setopt($curl, CURLOPT_TIMEOUT, 120);
     // No single operation should take longer than 2 minutes
     if ($payload !== null && json_decode($payload) !== null) {
         curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
     }
     if (($http_type === "POST" || $http_type === "PUT") && $payload !== null) {
         if ($escape_payload && (is_array($payload) || is_object($payload))) {
             $payload = http_build_query($payload);
         }
         curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
     }
     WebDriver::LogDebug($http_type, $full_url, $payload);
     $full_response = curl_exec($curl);
     WebDriver::LogDebug($full_response);
     WebDriver::LogDebug("=====");
     $error = curl_error($curl);
     PHPUnit_Framework_Assert::assertEquals("", $error, "Curl error: {$error}\nMethod: {$http_type}\nURL: {$full_url}\n" . print_r($payload, true));
     curl_close($curl);
     $response_parts = explode("\r\n\r\n", $full_response, 2);
     $response['header'] = $response_parts[0];
     if (!empty($response_parts[1])) {
         $response['body'] = $response_parts[1];
     }
     return $response;
 }
コード例 #2
1
 /**
  * Initializes the module setting the properties values.
  * @return void
  */
 public function _initialize()
 {
     parent::_initialize();
     $this->loginUrl = str_replace('wp-admin', 'wp-login.php', $this->config['adminUrl']);
     $this->adminUrl = rtrim($this->config['adminUrl'], '/');
     $this->pluginsUrl = $this->adminUrl . '/plugins.php';
 }
コード例 #3
0
 public function __construct(WebDriver $driver)
 {
     $this->driver = $driver;
     $this->keyboard = $driver->getKeyboard();
     $this->mouse = $driver->getMouse();
     $this->action = new WebDriverCompositeAction();
 }
コード例 #4
0
 /**
  * Attempt to connect to Selenium server
  * @return bool TRUE if web driver succesfully initiated
  */
 protected function connect($browser = 'firefox', $host = '127.0.0.1', $port = 4444)
 {
     $this->host = $host;
     $this->port = $port;
     // initiate web driver PHP bindings
     require_once DIR_FRAMEWORK . '/extensions/seleniumWebDriverBindings/phpwebdriver/WebDriver.php';
     // initatie browser
     $this->driver = new WebDriver($this->host, $this->port);
     $this->driver->connect($browser);
     return !empty($this->driver);
 }
コード例 #5
0
ファイル: UITestCase.php プロジェクト: ekowabaka/cfx
 protected function onNotSuccessfulTest(\Exception $e)
 {
     if (is_object($this->driver)) {
         $this->driver->takeScreenshot("screenshots/" . uniqid() . ".png");
     }
     parent::onNotSuccessfulTest($e);
 }
コード例 #6
0
 /**
  * Get the element on the page that currently has focus.
  *
  * @return WebDriverElement
  */
 public function getActiveElement() {
   try {
     return $this->driver->getActiveElement();
   } catch (WebDriverException $exception) {
     $this->dispatchOnException($exception);
   }
 }
コード例 #7
0
 public function execute($name, $params)
 {
     try {
         return $this->driver->execute($name, $params);
     } catch (WebDriverException $exception) {
         $this->dispatchOnException($exception);
     }
 }
コード例 #8
0
ファイル: WebDriver.php プロジェクト: AoJ/WebDriver-PHP
 public static function Curl($http_type, $full_url, $payload = null, $escape_payload = true, $cookies = array())
 {
     if (!self::$curl) {
         self::$curl = curl_init();
     }
     curl_setopt(self::$curl, CURLOPT_URL, $full_url);
     curl_setopt(self::$curl, CURLOPT_CUSTOMREQUEST, $http_type);
     curl_setopt(self::$curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt(self::$curl, CURLINFO_HEADER_OUT, TRUE);
     curl_setopt(self::$curl, CURLOPT_HEADER, TRUE);
     curl_setopt(self::$curl, CURLOPT_CONNECTTIMEOUT, WebDriver::$CurlConnectTimeoutSec);
     curl_setopt(self::$curl, CURLOPT_TIMEOUT, WebDriver::$CurlTimeoutSec);
     if (($http_type === "POST" || $http_type === "PUT") && $payload !== null) {
         if ($escape_payload && (is_array($payload) || is_object($payload))) {
             $payload = http_build_query($payload);
         }
         curl_setopt(self::$curl, CURLOPT_POSTFIELDS, $payload);
     }
     $headers = array('Expect:', 'Accept: application/json');
     if ($payload !== null && is_string($payload) && json_decode($payload) !== null) {
         $headers[] = 'Content-Type: application/json; charset=utf-8';
     }
     if (is_string($payload)) {
         $headers[] = 'Content-Length: ' . strlen($payload);
     }
     curl_setopt(self::$curl, CURLOPT_HTTPHEADER, $headers);
     if (!empty($cookies)) {
         $cookie_string = http_build_query($cookies, '', '; ');
         curl_setopt(self::$curl, CURLOPT_COOKIE, $cookie_string);
     }
     $full_response = curl_exec(self::$curl);
     $request_header = curl_getinfo(self::$curl, CURLINFO_HEADER_OUT);
     WebDriver::LogDebug($request_header);
     WebDriver::LogDebug($payload);
     WebDriver::LogDebug("-");
     WebDriver::LogDebug($full_response);
     WebDriver::LogDebug("=====");
     $error = curl_error(self::$curl);
     PHPUnit_Framework_Assert::assertEquals("", $error, "Curl error: {$error}\nMethod: {$http_type}\nURL: {$full_url}\n" . print_r($payload, true));
     $response_parts = explode("\r\n\r\n", $full_response, 2);
     $response['header'] = $response_parts[0];
     if (!empty($response_parts[1])) {
         $response['body'] = $response_parts[1];
     }
     return $response;
 }
コード例 #9
0
 /**
  *
  * @param type $strategy
  * @param type $name
  * @param boolean $failIfNotExists whether should fail test if element not exists
  * @return WebElement
  */
 public function getElement($strategy, $name, $failIfNotExists = true)
 {
     $i = 0;
     do {
         try {
             $element = $this->webdriver->findElementBy($strategy, $name);
         } catch (NoSuchElementException $e) {
             print_r("\nWaiting for \"" . $name . "\" element to appear...\n");
             sleep(self::STEP_WAITING_TIME);
             $i += self::STEP_WAITING_TIME;
         }
     } while (!isset($element) && $i <= self::MAX_WAITING_TIME);
     if (!isset($element) && $failIfNotExists) {
         $this->fail("Element has not appeared after " . self::MAX_WAITING_TIME . " seconds.");
     }
     return $element;
 }
コード例 #10
0
ファイル: WebDriverFactory.php プロジェクト: magium/magium
 public static function create($url = 'http://localhost:4444/wd/hub', $desired_capabilities = null, $connection_timeout_in_ms = null, $request_timeout_in_ms = null, $http_proxy = null, $http_proxy_port = null)
 {
     return WebDriver::create($url, $desired_capabilities, $connection_timeout_in_ms, $request_timeout_in_ms, $http_proxy, $http_proxy_port);
 }
コード例 #11
0
ファイル: WebElement.php プロジェクト: sgml/WebDriver-PHP
 public function assert_selected_count($expected_count)
 {
     $count = WebDriver::WaitUntil(array($this, 'get_selected_count'), array(), $expected_count);
     PHPUnit_Framework_Assert::assertEquals($expected_count, $count, "Failed asserting that <{$this->locator}> contains {$expected_count} selected options.");
 }
コード例 #12
0
ファイル: Driver.php プロジェクト: sgml/WebDriver-PHP
 public function assert_alert_text($expected_text)
 {
     $text = WebDriver::WaitUntil(array($this, 'get_alert_text'), array(), $expected_text);
     PHPUnit_Framework_Assert::assertEquals($expected_text, $text, "Failed asserting that alert text is <{$expected_text}>.");
 }
コード例 #13
0
<?php

/*
Copyright 2011 3e software house & interactive agency

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("internet explorer");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
if ($element) {
    $element->sendKeys(array("php webdriver"));
    $element->submit();
}
$webdriver->close();
コード例 #14
0
<?php

require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect();
$webdriver->get("http://shoppbagg.com");
sleep(5);
$webdriver->getScreenshotAndSaveToFile("shoppbagg.png");
$webdriver->close();
コード例 #15
0
ファイル: test-mouse.php プロジェクト: trianglestrip/tquery
<?php

require 'vendor/php-webdriver-master/__init__.php';
$webdriver = new WebDriver();
$session = $webdriver->session('firefox', array());
$url = "http://127.0.0.1:8000/tmp/selenium/php/test-mouse.html";
// open the page
$session->open($url);
$title = $session->title();
$size = $session->window()->size();
$url = $session->url();
var_dump($size);
var_dump($url);
var_dump($title);
//$session->click();
$session->element('css selector', 'body')->click();
// $session->element('css selector','body')->click();
// $session->element('css selector','body')->click();
//$session->element('css selector','body')->moveto();
//$session->element('css selector','body')->click();
//$session->window()->click();
//$session->moveto(array('xoffset' => 3, 'yoffset' => 300));
$session->moveto(array('xoffset' => 10, 'yoffset' => 0));
$session->moveto(array('xoffset' => 10, 'yoffset' => 0));
//$session->moveto(array('element' => $session->element('css selector','body')));
//sleep(4);
// $sScriptResult = $session->execute(array(
// 	'script'	=> 'return window.document.location.hostname',
// 	'args'		=> array(),
// ));
// $sScriptResult = $session->execute(array(
コード例 #16
0
<?php

// Sample WebDriver code - search Google for "Selenium is awesome" and take
// a screenshot.
// You need three things to run this code:
// 1. A copy of chromedriver (from the Selenium downloads.)
// 2. The standalone Selenium server v2.0 running with
//    -Dwebdriver.chrome.driver=${PATH_TO_CHROMEDRIVER}
// 3. A copy of http://code.google.com/p/php-webdriver-bindings/ checked out.
//require_once "..phpwebdriver/WebDriver.php";
require_once "phpwebdriver/WebDriver.php";
$timestamp = time();
//$browsers = array("chrome", "firefox");
//foreach($browsers as $browser) {
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect();
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium is awesome"));
$element->submit();
sleep(2);
$webdriver->getScreenshotAndSaveToFile("the_google_{$browser}_{$timestamp}.png");
$webdriver->close();
//}
コード例 #17
0
ファイル: Driver.php プロジェクト: robinhood-zz/WebDriver-PHP
 public function set_sauce_context($field, $value)
 {
     if ($this->running_at_sauce()) {
         $payload = json_encode(array($field => $value));
         $url_parts = parse_url($this->server_url);
         WebDriver::Curl("PUT", "http://" . $url_parts['user'] . ":" . $url_parts['pass'] . "@saucelabs.com/rest/v1/" . $url_parts['user'] . "/jobs/" . $this->session_id, $payload);
     }
 }
コード例 #18
0
 /**
  * @dataProvider invalid_selectors
  * @expectedException Exception
  */
 public function test_invalid_selectors($input)
 {
     WebDriver::ParseLocator($input);
 }
コード例 #19
0
ファイル: snapshots.php プロジェクト: kwadwo/crawlexa
<?php

if (!isset($file)) {
    $file = 'results/rolling_output.csv';
}
echo "Generating snapshots...\n (This process will take a long time. In case of failure make sure you have Mozilla Firefox browser installed on your system and Selenium server installed, properly set up and running on localhost:4444, and check Selenium log file for more info.)\n";
/**
 * Include selenium php webdriver bindings for website snapshot
 */
require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$fh = fopen($file, 'r');
while (!feof($fh)) {
    $line = fgetcsv($fh, 0, ',', '"');
    if (isset($line[1]) && $line[1] !== '') {
        $webdriver->get("http://" . preg_replace('@http[s]?://@i', '', $line[1]));
        $webdriver->getScreenshotAndSaveToFile("results/snapshots/{$line[0]}.png");
    }
}
$webdriver->close();
コード例 #20
0
 /**
  * @dataProvider data
  */
 public function test($text)
 {
     $xml = simplexml_load_string('<tag>' . $text . '</tag>');
     $result = $xml->xpath('//tag[text()=' . WebDriver::QuoteXPath($text) . ']');
     $this->assertEquals(count($result), 1);
 }
コード例 #21
0
<?php

/*
Copyright 2011 3e software house & interactive agency

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver("localhost", 4444);
$ffprofile = $webdriver->prepareBrowserProfile("pathToYourFFProfileDirectory");
$webdriver->connect("firefox", "15", array('firefox_profile' => $ffprofile));
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
if ($element) {
    $element->sendKeys(array("php webdriver"));
    $element->submit();
}
$webdriver->close();
コード例 #22
0
<?php

/*
Copyright 2011 3e software house & interactive agency

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver('your-username-string:your-access-key-string@ondemand.saucelabs.com', 80);
$webdriver->connect("firefox", "15", array('name' => 'Running a test with php-webdriver-bindings on SauceLabs'));
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
if ($element) {
    $element->sendKeys(array("php webdriver"));
    $element->submit();
}
$webdriver->close();
コード例 #23
0
ファイル: WPWebDriver.php プロジェクト: lucatume/wp-browser
 protected function validateConfig()
 {
     $this->configBackCompat();
     parent::validateConfig();
 }
コード例 #24
0
<?php

require 'vendor/php-webdriver-master/__init__.php';
$webdriver = new WebDriver();
$session = $webdriver->session('chrome', array());
// $session->open("http://google.com");
// $url		= "http://google.com";
// $url		= "http://127.0.0.1:8000/plugins/minecraft/examples/index.html";
// $session->open($url);
// $content_b64	= $session->screenshot();
// $imgData	= base64_decode($content_b64);
// $filename	= "/tmp/screenshot.png";
// file_put_contents($filename, $imgData);
$url = "http://google.com";
$url = "http://127.0.0.1:8000/plugins/minecraft/examples/index.html";
$filename = "/tmp/screenshot.png";
saveCapture($session, $url, $filename);
$session->close();
/**
 * Save a capture of the screen
 */
function saveCapture($session, $url, $filename)
{
    // open the page
    $session->open($url);
    // get the screenshort
    $contentBase64 = $session->screenshot();
    $contentRaw = base64_decode($contentBase64);
    // save it in a file
    file_put_contents($filename, $contentRaw);
}
コード例 #25
0
<?php

/*
Copyright 2011 3e software house & interactive agency

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// XAMPP NOTE: First please download Selenium RC (*.jar) from here : http://seleniumhq.org/download/
// XAMPP NOTE: Start the Selenium RC Server via cmd with: java -jar selenium-server-standalone-2.25.0.jar
// XAMPP NOTE: Then start this script with the cmd from here: .\php.exe  -f webdriver-test-example.php
// XAMPP NOTE: This example uses php-webdriver-bindings-0.9.0 (see the folder xampp\pear\phpwebdriver)
require_once "phpwebdriver/WebDriver.php";
require_once "phpwebdriver/LocatorStrategy.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium google code"));
$element->submit();
$webdriver->close();
コード例 #26
0
 public function assert_css_value($property_name, $expected_value, $canonicalize_colors = true)
 {
     $actual_value = $this->get_css_value($property_name);
     if (strpos($property_name, 'color') !== false && $canonicalize_colors) {
         $canonical_expected = WebDriver::CanonicalizeCSSColor($expected_value);
         $canonical_actual = WebDriver::CanonicalizeCSSColor($actual_value);
         PHPUnit_Framework_Assert::assertEquals($canonical_expected, $canonical_actual, "Failed asserting that <{$this->locator}>'s <{$property_name}> is <{$canonical_expected}> after canonicalization.\nExpected: {$expected_value} -> {$canonical_expected}\nActual: {$actual_value} -> {$canonical_actual}");
     } else {
         PHPUnit_Framework_Assert::assertEquals($expected_value, $actual_value, "Failed asserting that <{$this->locator}>'s <{$property_name}> is <{$expected_value}>.");
     }
 }
コード例 #27
0
ファイル: selenium.php プロジェクト: habari/tests
 /**
  * @Then /I should see the text "(.+)"$/
  */
 function i_should_see_the_text($text)
 {
     $this->init_webdriver();
     $source = $this->webdriver->getPageSource();
     $this->assert_true(strpos($source, $text) !== false, '{step}');
 }
コード例 #28
0
 /**
  * @dataProvider invalid_colors
  * @expectedException Exception
  */
 public function test_invalid_colors($input)
 {
     WebDriver::CanonicalizeCSSColor($input);
 }
コード例 #29
0
ファイル: WebDriverNot.php プロジェクト: itillawarra/cmfive
 protected function matches($nodes)
 {
     return !parent::matches($nodes);
 }
コード例 #30
0
 /** 
  * Tear Down.
  *
  */
 public function tearDown()
 {
     $this->driver->quit();
     parent::tearDown();
 }