Commit dcdb03e5 authored by webchick's avatar webchick

Issue #2596801 by alexpott, dawehner: Step 1.75: Include the PhantomJS Mink driver

parent 63927236
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "8c9fdf621ce53640f24b24749e59717c",
"hash": "2be29019515c847055593ea41b88475d",
"content-hash": "f38613812a285c03a1a18458384fe0b1",
"packages": [
{
......@@ -2004,7 +2004,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/47bb3388cfeae41a38087ac8465a7d08fa92ea2e",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/6bfcdcfe0aab6c11dcccfbd28dea01a592afd5b3",
"reference": "47bb3388cfeae41a38087ac8465a7d08fa92ea2e",
"shasum": ""
},
......@@ -2585,6 +2585,63 @@
],
"time": "2015-08-29 16:16:56"
},
{
"name": "jcalderonzumba/gastonjs",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/jcalderonzumba/gastonjs.git",
"reference": "5e231b4df98275c404e1371fc5fadd34f6a121ad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jcalderonzumba/gastonjs/zipball/5e231b4df98275c404e1371fc5fadd34f6a121ad",
"reference": "5e231b4df98275c404e1371fc5fadd34f6a121ad",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "~5.0|~6.0",
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"silex/silex": "~1.2",
"symfony/phpunit-bridge": "~2.7",
"symfony/process": "~2.1"
},
"type": "phantomjs-api",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"Zumba\\GastonJS\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Juan Francisco Calderón Zumba",
"email": "juanfcz@gmail.com",
"homepage": "http://github.com/jcalderonzumba"
}
],
"description": "PhantomJS API based server for webpage automation",
"homepage": "https://github.com/jcalderonzumba/gastonjs",
"keywords": [
"api",
"automation",
"browser",
"headless",
"phantomjs"
],
"time": "2015-10-07 11:40:41"
},
{
"name": "mikey179/vfsStream",
"version": "v1.6.0",
......@@ -3672,6 +3729,7 @@
"composer/semver": 0,
"behat/mink": 0,
"behat/mink-goutte-driver": 0,
"jcalderonzumba/gastonjs": 20,
"mikey179/vfsstream": 0,
"phpunit/phpunit": 0,
"symfony/css-selector": 0
......
......@@ -34,6 +34,7 @@
"require-dev": {
"behat/mink": "~1.6",
"behat/mink-goutte-driver": "~1.2",
"jcalderonzumba/gastonjs": "^1.1@dev",
"mikey179/vfsStream": "~1.2",
"phpunit/phpunit": "~4.8",
"symfony/css-selector": "2.7.*"
......
......@@ -31,6 +31,9 @@ class Composer {
'fabpot/goutte' => ['Goutte/Tests'],
'guzzlehttp/promises' => ['tests'],
'guzzlehttp/psr7' => ['tests'],
'jcalderonzumba/gastonjs' => ['docs'],
'jcalderonzumba/gastonjs' => ['examples'],
'jcalderonzumba/gastonjs' => ['tests'],
'masterminds/html5' => ['test'],
'mikey179/vfsStream' => ['src/test'],
'phpdocumentor/reflection-docblock' => ['tests'],
......
......@@ -6,6 +6,7 @@
$baseDir = dirname($vendorDir);
return array(
'Zumba\\GastonJS\\' => array($vendorDir . '/jcalderonzumba/gastonjs/src'),
'Zend\\Stdlib\\' => array($vendorDir . '/zendframework/zend-stdlib/src'),
'Zend\\Hydrator\\' => array($vendorDir . '/zendframework/zend-hydrator/src'),
'Zend\\Feed\\' => array($vendorDir . '/zendframework/zend-feed/src'),
......
......@@ -107,7 +107,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/47bb3388cfeae41a38087ac8465a7d08fa92ea2e",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/6bfcdcfe0aab6c11dcccfbd28dea01a592afd5b3",
"reference": "47bb3388cfeae41a38087ac8465a7d08fa92ea2e",
"shasum": ""
},
......@@ -3757,5 +3757,64 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com"
},
{
"name": "jcalderonzumba/gastonjs",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/jcalderonzumba/gastonjs.git",
"reference": "5e231b4df98275c404e1371fc5fadd34f6a121ad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jcalderonzumba/gastonjs/zipball/5e231b4df98275c404e1371fc5fadd34f6a121ad",
"reference": "5e231b4df98275c404e1371fc5fadd34f6a121ad",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "~5.0|~6.0",
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"silex/silex": "~1.2",
"symfony/phpunit-bridge": "~2.7",
"symfony/process": "~2.1"
},
"time": "2015-10-07 11:40:41",
"type": "phantomjs-api",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"installation-source": "source",
"autoload": {
"psr-4": {
"Zumba\\GastonJS\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Juan Francisco Calderón Zumba",
"email": "juanfcz@gmail.com",
"homepage": "http://github.com/jcalderonzumba"
}
],
"description": "PhantomJS API based server for webpage automation",
"homepage": "https://github.com/jcalderonzumba/gastonjs",
"keywords": [
"api",
"automation",
"browser",
"headless",
"phantomjs"
]
}
]
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
matrix:
fast_finish: true
include:
- php: 5.4
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable' SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: DEPENDENCIES=dev
allow_failures:
- php: 7.0
- php: hhvm
cache:
directories:
- $HOME/.composer/cache/files
before_install:
- composer self-update
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
install:
- composer update $COMPOSER_FLAGS
script:
- bin/run-tests.sh
after_script:
- ps axo pid,command | grep phantomjs | grep -v grep | awk '{print $1}' | xargs -I {} kill {}
- ps axo pid,command | grep php | grep -v grep | awk '{print $1}' | xargs -I {} kill {}
The MIT License (MIT)
Copyright (c) 2015 Juan Francisco Calderón Zumba
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
GastonJS for Webpage automation
================================
[![Build Status](https://travis-ci.org/jcalderonzumba/gastonjs.svg?branch=travis_ci)](https://travis-ci.org/jcalderonzumba/gastonjs)
[![Latest Stable Version](https://poser.pugx.org/jcalderonzumba/gastonjs/v/stable)](https://packagist.org/packages/jcalderonzumba/gastonjs)
[![Total Downloads](https://poser.pugx.org/jcalderonzumba/gastonjs/downloads)](https://packagist.org/packages/jcalderonzumba/gastonjs)
For full documentation go to [GastonJS doc](http://gastonjs.readthedocs.org/en/latest/)
#!/bin/sh
set -e
start_browser_api(){
CURRENT_DIR=$(pwd)
LOCAL_PHANTOMJS="${CURRENT_DIR}/bin/phantomjs"
if [ -f ${LOCAL_PHANTOMJS} ]; then
${LOCAL_PHANTOMJS} --ssl-protocol=any --ignore-ssl-errors=true src/Client/main.js 8510 1024 768 2>&1 &
else
phantomjs --ssl-protocol=any --ignore-ssl-errors=true src/Client/main.js 8510 1024 768 2>&1 >> /dev/null &
fi
sleep 2
}
stop_services(){
ps axo pid,command | grep phantomjs | grep -v grep | awk '{print $1}' | xargs -I {} kill {}
ps axo pid,command | grep php | grep -v grep | grep -v phpstorm | awk '{print $1}' | xargs -I {} kill {}
sleep 2
}
mkdir -p /tmp/jcalderonzumba/phantomjs
stop_services
start_browser_api
CURRENT_DIR=$(pwd)
${CURRENT_DIR}/bin/phpunit --configuration unit_tests.xml
{
"name": "jcalderonzumba/gastonjs",
"description": "PhantomJS API based server for webpage automation",
"keywords": [
"phantomjs",
"headless",
"api",
"automation",
"browser"
],
"homepage": "https://github.com/jcalderonzumba/gastonjs",
"type": "phantomjs-api",
"license": "MIT",
"authors": [
{
"name": "Juan Francisco Calderón Zumba",
"email": "juanfcz@gmail.com",
"homepage": "http://github.com/jcalderonzumba"
}
],
"require": {
"php": ">=5.4",
"guzzlehttp/guzzle": "~5.0|~6.0"
},
"require-dev": {
"symfony/process": "~2.1",
"symfony/phpunit-bridge": "~2.7",
"phpunit/phpunit": "~4.6",
"silex/silex": "~1.2"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": {
"Zumba\\GastonJS\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Zumba\\GastonJS\\Tests\\": "tests/unit"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
}
}
site_name: GastonJS Documentation
pages:
- GastonJS introduction: index.md
- GastonJS API :
- 'Introduction': api/index.md
- 'Available commands': api/command-list.md
- 'Navigation commands':
- 'visit': api/commands/navigation/visit.md
- 'current_url': api/commands/navigation/current_url.md
- 'reload': api/commands/navigation/reload.md
- 'go_back': api/commands/navigation/go_back.md
- 'go_forward': api/commands/navigation/go_forward.md
- 'Header commands' :
- 'get_headers': api/commands/headers/get_headers.md
- 'response_headers': api/commands/headers/response_headers.md
- 'set_headers': api/commands/headers/set_headers.md
- 'add_headers': api/commands/headers/add_headers.md
- 'add_header': api/commands/headers/add_header.md
- 'Javascript commands' :
- 'add_extension': api/commands/javascript/add_extension.md
- 'execute': api/commands/javascript/execute.md
- 'evaluate': api/commands/javascript/evaluate.md
- 'set_js_errors': api/commands/javascript/set_js_errors.md
- 'Cookies commands' :
- 'cookies': api/commands/cookies/cookies.md
- 'clear_cookies': api/commands/cookies/clear_cookies.md
- 'cookies_enabled': api/commands/cookies/cookies_enabled.md
- 'remove_cookie': api/commands/cookies/remove_cookie.md
- 'set_cookie': api/commands/cookies/set_cookie.md
- 'Mouse commands':
- 'click': api/commands/mouse/click.md
- 'right_click': api/commands/mouse/right_click.md
- 'hover': api/commands/mouse/hover.md
- 'double_click': api/commands/mouse/double_click.md
- 'click_coordinates': api/commands/mouse/click_coordinates.md
- 'mouse_event': api/commands/mouse/mouse_event.md
- 'Render commands':
- 'render': api/commands/render/render.md
- 'render_base64': api/commands/render/render_base64.md
- GastonJS PHP client: clients/php/index.md
<?php
namespace Zumba\GastonJS\Browser;
/**
* Class Browser
* @package Zumba\GastonJS
*/
class Browser extends BrowserBase {
use BrowserAuthenticationTrait;
use BrowserConfigurationTrait;
use BrowserCookieTrait;
use BrowserFileTrait;
use BrowserFrameTrait;
use BrowserHeadersTrait;
use BrowserMouseEventTrait;
use BrowserNavigateTrait;
use BrowserNetworkTrait;
use BrowserPageElementTrait;
use BrowserPageTrait;
use BrowserRenderTrait;
use BrowserScriptTrait;
use BrowserWindowTrait;
/**
* @param string $phantomJSHost
* @param mixed $logger
*/
public function __construct($phantomJSHost, $logger = null) {
$this->phantomJSHost = $phantomJSHost;
$this->logger = $logger;
$this->debug = false;
$this->createApiClient();
}
/**
* Returns the value of a given element in a page
* @param $pageId
* @param $elementId
* @return mixed
*/
public function value($pageId, $elementId) {
return $this->command('value', $pageId, $elementId);
}
/**
* Sets a value to a given element in a given page
* @param $pageId
* @param $elementId
* @param $value
* @return mixed
*/
public function set($pageId, $elementId, $value) {
return $this->command('set', $pageId, $elementId, $value);
}
/**
* Tells whether an element on a page is visible or not
* @param $pageId
* @param $elementId
* @return bool
*/
public function isVisible($pageId, $elementId) {
return $this->command('visible', $pageId, $elementId);
}
/**
* @param $pageId
* @param $elementId
* @return bool
*/
public function isDisabled($pageId, $elementId) {
return $this->command('disabled', $pageId, $elementId);
}
/**
* Drag an element to a another in a given page
* @param $pageId
* @param $fromId
* @param $toId
* @return mixed
*/
public function drag($pageId, $fromId, $toId) {
return $this->command('drag', $pageId, $fromId, $toId);
}
/**
* Selects a value in the given element and page
* @param $pageId
* @param $elementId
* @param $value
* @return mixed
*/
public function select($pageId, $elementId, $value) {
return $this->command('select', $pageId, $elementId, $value);
}
/**
* Triggers an event to a given element on the given page
* @param $pageId
* @param $elementId
* @param $event
* @return mixed
*/
public function trigger($pageId, $elementId, $event) {
return $this->command('trigger', $pageId, $elementId, $event);
}
/**
* TODO: not sure what this does, needs to do normalizeKeys
* @param int $pageId
* @param int $elementId
* @param array $keys
* @return mixed
*/
public function sendKeys($pageId, $elementId, $keys) {
return $this->command('send_keys', $pageId, $elementId, $this->normalizeKeys($keys));
}
}
<?php
namespace Zumba\GastonJS\Browser;
/**
* Trait BrowserAuthenticationTrait
* @package Zumba\GastonJS\Browser
*/
trait BrowserAuthenticationTrait {
/**
* Sets basic HTTP authentication
* @param $user
* @param $password
* @return bool
*/
public function setHttpAuth($user, $password) {
return $this->command('set_http_auth', $user, $password);
}
}
<?php
namespace Zumba\GastonJS\Browser;
use Zumba\GastonJS\Exception\BrowserError;
use Zumba\GastonJS\Exception\DeadClient;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\ServerException;
/**
* Class BrowserBase
* @package Zumba\GastonJS\Browser
*/
class BrowserBase {
/** @var mixed */
protected $logger;
/** @var bool */
protected $debug;
/** @var string */
protected $phantomJSHost;
/** @var Client */
protected $apiClient;
/**
* Creates an http client to consume the phantomjs API
*/
protected function createApiClient() {
// Provide a BC switch between guzzle 5 and guzzle 6.
if (class_exists('GuzzleHttp\Psr7\Response')) {
$this->apiClient = new Client(array("base_uri" => $this->getPhantomJSHost()));
}
else {
$this->apiClient = new Client(array("base_url" => $this->getPhantomJSHost()));
}
}
/**
* TODO: not sure how to do the normalizeKeys stuff fix when needed
* @param $keys
* @return mixed
*/
protected function normalizeKeys($keys) {
return $keys;
}
/**
* @return Client
*/
public function getApiClient() {
return $this->apiClient;
}
/**
* @return string
*/
public function getPhantomJSHost() {
return $this->phantomJSHost;
}
/**
* @return mixed
*/
public function getLogger() {
return $this->logger;
}
/**
* Restarts the browser
*/
public function restart() {
//TODO: Do we really need to do this?, we are just a client
}
/**
* Sends a command to the browser
* @throws BrowserError
* @throws \Exception
* @return mixed
*/
public function command() {
try {
$args = func_get_args();
$commandName = $args[0];
array_shift($args);
$messageToSend = json_encode(array('name' => $commandName, 'args' => $args));
/** @var $commandResponse \GuzzleHttp\Psr7\Response|\GuzzleHttp\Message\Response */
$commandResponse = $this->getApiClient()->post("/api", array("body" => $messageToSend));
$jsonResponse = json_decode($commandResponse->getBody(), TRUE);
} catch (ServerException $e) {
$jsonResponse = json_decode($e->getResponse()->getBody()->getContents(), true);
} catch (ConnectException $e) {
throw new DeadClient($e->getMessage(), $e->getCode(), $e);
} catch (\Exception $e) {
throw $e;
}