Commit 15d06957 authored by jhodgdon's avatar jhodgdon

Issue #2600176 by alexpott, dawehner, tim.plunkett: Step 1.875: Include the...

Issue #2600176 by alexpott, dawehner, tim.plunkett: Step 1.875: Include the PhantomJS Mink driver for real
parent a1678a2b
......@@ -2004,7 +2004,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/6bfcdcfe0aab6c11dcccfbd28dea01a592afd5b3",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/6196fdb001faf681f92db2ae10abafb5815affde",
"reference": "47bb3388cfeae41a38087ac8465a7d08fa92ea2e",
"shasum": ""
},
......@@ -2642,6 +2642,67 @@
],
"time": "2015-10-07 11:40:41"
},
{
"name": "jcalderonzumba/mink-phantomjs-driver",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/jcalderonzumba/MinkPhantomJSDriver.git",
"reference": "10d7c48c9a4129463052321b52450d98983c4332"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jcalderonzumba/MinkPhantomJSDriver/zipball/10d7c48c9a4129463052321b52450d98983c4332",
"reference": "10d7c48c9a4129463052321b52450d98983c4332",
"shasum": ""
},
"require": {
"behat/mink": "~1.6",
"jcalderonzumba/gastonjs": "~1.0",
"php": ">=5.4",
"twig/twig": "~1.8"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"silex/silex": "~1.2",
"symfony/css-selector": "~2.1",
"symfony/phpunit-bridge": "~2.7",
"symfony/process": "~2.3"
},
"type": "mink-driver",
"extra": {
"branch-alias": {
"dev-master": "0.4.x-dev"
}
},
"autoload": {
"psr-4": {
"Zumba\\Mink\\Driver\\": "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 driver for Mink framework",
"homepage": "http://mink.behat.org/",
"keywords": [
"ajax",
"browser",
"headless",
"javascript",
"phantomjs",
"testing"
],
"time": "2015-10-05 18:24:44"
},
{
"name": "mikey179/vfsStream",
"version": "v1.6.0",
......@@ -3730,6 +3791,7 @@
"behat/mink": 0,
"behat/mink-goutte-driver": 0,
"jcalderonzumba/gastonjs": 20,
"jcalderonzumba/mink-phantomjs-driver": 20,
"mikey179/vfsstream": 0,
"phpunit/phpunit": 0,
"symfony/css-selector": 0
......
......@@ -35,6 +35,7 @@
"behat/mink": "~1.6",
"behat/mink-goutte-driver": "~1.2",
"jcalderonzumba/gastonjs": "^1.1@dev",
"jcalderonzumba/mink-phantomjs-driver": "dev-master#10d7c48c9a4129463052321b52450d98983c4332",
"mikey179/vfsStream": "~1.2",
"phpunit/phpunit": "~4.8",
"symfony/css-selector": "2.7.*"
......
......@@ -31,9 +31,8 @@ class Composer {
'fabpot/goutte' => ['Goutte/Tests'],
'guzzlehttp/promises' => ['tests'],
'guzzlehttp/psr7' => ['tests'],
'jcalderonzumba/gastonjs' => ['docs'],
'jcalderonzumba/gastonjs' => ['examples'],
'jcalderonzumba/gastonjs' => ['tests'],
'jcalderonzumba/gastonjs' => ['docs', 'examples', 'tests'],
'jcalderonzumba/mink-phantomjs-driver' => ['tests'],
'masterminds/html5' => ['test'],
'mikey179/vfsStream' => ['src/test'],
'phpdocumentor/reflection-docblock' => ['tests'],
......
......@@ -6,6 +6,7 @@
$baseDir = dirname($vendorDir);
return array(
'Zumba\\Mink\\Driver\\' => array($vendorDir . '/jcalderonzumba/mink-phantomjs-driver/src'),
'Zumba\\GastonJS\\' => array($vendorDir . '/jcalderonzumba/gastonjs/src'),
'Zend\\Stdlib\\' => array($vendorDir . '/zendframework/zend-stdlib/src'),
'Zend\\Hydrator\\' => array($vendorDir . '/zendframework/zend-hydrator/src'),
......
......@@ -107,7 +107,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/6bfcdcfe0aab6c11dcccfbd28dea01a592afd5b3",
"url": "https://api.github.com/repos/wikimedia/composer-merge-plugin/zipball/6196fdb001faf681f92db2ae10abafb5815affde",
"reference": "47bb3388cfeae41a38087ac8465a7d08fa92ea2e",
"shasum": ""
},
......@@ -3816,5 +3816,68 @@
"headless",
"phantomjs"
]
},
{
"name": "jcalderonzumba/mink-phantomjs-driver",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/jcalderonzumba/MinkPhantomJSDriver.git",
"reference": "10d7c48c9a4129463052321b52450d98983c4332"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jcalderonzumba/MinkPhantomJSDriver/zipball/10d7c48c9a4129463052321b52450d98983c4332",
"reference": "10d7c48c9a4129463052321b52450d98983c4332",
"shasum": ""
},
"require": {
"behat/mink": "~1.6",
"jcalderonzumba/gastonjs": "~1.0",
"php": ">=5.4",
"twig/twig": "~1.8"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"silex/silex": "~1.2",
"symfony/css-selector": "~2.1",
"symfony/phpunit-bridge": "~2.7",
"symfony/process": "~2.3"
},
"time": "2015-10-05 18:24:44",
"type": "mink-driver",
"extra": {
"branch-alias": {
"dev-master": "0.4.x-dev"
}
},
"installation-source": "source",
"autoload": {
"psr-4": {
"Zumba\\Mink\\Driver\\": "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 driver for Mink framework",
"homepage": "http://mink.behat.org/",
"keywords": [
"ajax",
"browser",
"headless",
"javascript",
"phantomjs",
"testing"
]
}
]
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
before_script:
- mkdir -p /tmp/jcalderonzumba/phantomjs
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 {}
CHANGELOG for 0.2.x
===================
This changelog references the relevant changes (bug and security fixes) done in 0.2 minor versions.
* 0.2.3
* bug #1 set_url_blacklist was not working properly (thanks to reporter)
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.
Mink PhantomJS Driver
===========================
[![Build Status](https://travis-ci.org/jcalderonzumba/MinkPhantomJSDriver.svg?branch=master)](https://travis-ci.org/jcalderonzumba/MinkPhantomJSDriver)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jcalderonzumba/MinkPhantomJSDriver/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jcalderonzumba/MinkPhantomJSDriver/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/jcalderonzumba/mink-phantomjs-driver/v/stable)](https://packagist.org/packages/jcalderonzumba/mink-phantomjs-driver)
[![Total Downloads](https://poser.pugx.org/jcalderonzumba/mink-phantomjs-driver/downloads)](https://packagist.org/packages/jcalderonzumba/mink-phantomjs-driver)
Installation & Compatibility
----------------------------
You need a working installation of [PhantomJS](http://phantomjs.org/download.html)
This driver is tested using PhantomJS 1.9.8 but it should work with 1.9.X or latest 2.0.X versions
This driver supports **PHP 5.4 or greater**, there is NO support for PHP 5.3
Use [Composer](https://getcomposer.org/) to install all required PHP dependencies:
```bash
$ composer require --dev behat/mink jcalderonzumba/mink-phantomjs-driver
```
How to use
-------------
Extension configuration (for the moment NONE).
```yml
default:
extensions:
Zumba\PhantomJSExtension:
```
Driver specific configuration:
```yml
Behat\MinkExtension:
phantomjs:
phantom_server: "http://localhost:8510/api"
template_cache: "/tmp/pjsdrivercache/phantomjs"
```
PhantomJS browser start:
```bash
phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /tmp/gastonjs.log &
```
FAQ
---------
1. Is this a selenium based driver?:
**NO**, it has nothing to do with Selenium it's inspired on [Poltergeist](https://github.com/teampoltergeist/poltergeist)
2. What features does this driver implements?
**ALL** of the features defined in Mink DriverInterface. maximizeWindow is the only one not implemented since is a headless browser it does not make sense to implement it.
3. Do i need to modify my selenium based tests?
If you only use the standard behat driver defined methods then NO, you just have to change your default javascript driver.
Copyright
---------
Copyright (c) 2015 Juan Francisco Calderon Zumba <juanfcz@gmail.com>
#!/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 vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 &
else
phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/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
}
star_local_browser(){
CURRENT_DIR=$(pwd)
cd ${CURRENT_DIR}/vendor/behat/mink/driver-testsuite/web-fixtures
if [ "$TRAVIS" = true ]; then
echo "Starting webserver fox fixtures...."
~/.phpenv/versions/5.6/bin/php -S 127.0.0.1:6789 > /dev/null 2>&1 &
else
php -S 127.0.0.1:6789 2>&1 >> /dev/null &
fi
sleep 2
}
mkdir -p /tmp/jcalderonzumba/phantomjs
stop_services
start_browser_api
star_local_browser
cd ${CURRENT_DIR}
${CURRENT_DIR}/bin/phpunit --configuration integration_tests.xml
stop_services
start_browser_api
{
"name": "jcalderonzumba/mink-phantomjs-driver",
"description": "PhantomJS driver for Mink framework",
"keywords": [
"phantomjs",
"headless",
"javascript",
"ajax",
"testing",
"browser"
],
"homepage": "http://mink.behat.org/",
"type": "mink-driver",
"license": "MIT",
"authors": [
{
"name": "Juan Francisco Calderón Zumba",
"email": "juanfcz@gmail.com",
"homepage": "http://github.com/jcalderonzumba"
}
],
"require": {
"php": ">=5.4",
"behat/mink": "~1.6",
"twig/twig": "~1.8",
"jcalderonzumba/gastonjs": "~1.0"
},
"require-dev": {
"symfony/process": "~2.3",
"symfony/phpunit-bridge": "~2.7",
"symfony/css-selector": "~2.1",
"phpunit/phpunit": "~4.6",
"silex/silex": "~1.2"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": {
"Zumba\\Mink\\Driver\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Behat\\Mink\\Tests\\Driver\\": "tests/integration"
}
},
"extra": {
"branch-alias": {
"dev-master": "0.4.x-dev"
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="./tests/integration/bootstrap.php" stopOnFailure="true">
<testsuites>
<testsuite name="PhantomJS Driver test suite">
<directory>tests/integration</directory>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/BasicAuthTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/ContentTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/CookieTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/ErrorHandlingTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/IFrameTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/ScreenshotTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/TraversingTest.php</file>
<file>vendor/behat/mink/driver-testsuite/tests/Basic/VisibilityTest.php</file>
<directory>vendor/behat/mink/driver-testsuite/tests/Form</directory>
<directory>vendor/behat/mink/driver-testsuite/tests/Js</directory>
<!-- The following have been disabled and their respective equals added to Custom driver tests -->
<!--<directory>vendor/behat/mink/driver-testsuite/tests/Css</directory>-->
<!--<file>vendor/behat/mink/driver-testsuite/tests/Basic/StatusCodeTest.php</file>-->
<!--<file>vendor/behat/mink/driver-testsuite/tests/Basic/HeaderTest.php</file>-->
<!--<file>vendor/behat/mink/driver-testsuite/tests/Basic/NavigationTest.php</file>-->
</testsuite>
</testsuites>
<php>
<var name="driver_config_factory" value="Behat\Mink\Tests\Driver\PhantomJSConfig::getInstance"/>
<server name="WEB_FIXTURES_HOST" value="http://127.0.0.1:6789"/>
<!-- where driver will connect to -->
<server name="DRIVER_URL" value="http://127.0.0.1:8510/"/>
<server name="TEMPLATE_CACHE_DIR" value="/tmp/jcalderonzumba/phantomjs"/>
</php>
<filter>
<whitelist>
<directory>./src/Behat/Mink/Driver</directory>
</whitelist>
</filter>
</phpunit>
<?php
namespace Zumba\Mink\Driver;
use Behat\Mink\Driver\CoreDriver;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Session;
use Zumba\GastonJS\Browser\Browser;
/**
* Class BasePhantomJSDriver
* @package Zumba\Mink\Driver
*/
class BasePhantomJSDriver extends CoreDriver {
/** @var Session */
protected $session;
/** @var Browser */
protected $browser;
/** @var string */
protected $phantomHost;
/** @var \Twig_Loader_Filesystem */
protected $templateLoader;
/** @var \Twig_Environment */
protected $templateEnv;
/**
* Instantiates the driver
* @param string $phantomHost browser "api" oriented host
* @param string $templateCache where we are going to store the templates cache
*/
public function __construct($phantomHost, $templateCache = null) {
$this->phantomHost = $phantomHost;
$this->browser = new Browser($phantomHost);
$this->templateLoader = new \Twig_Loader_Filesystem(realpath(__DIR__ . '/Resources/Script'));
$this->templateEnv = new \Twig_Environment($this->templateLoader, array('cache' => $this->templateCacheSetup($templateCache), 'strict_variables' => true));
}
/**
* Sets up the cache template location for the scripts we are going to create with the driver
* @param $templateCache
* @return string
* @throws DriverException
*/
protected function templateCacheSetup($templateCache) {
$cacheDir = $templateCache;
if ($templateCache === null) {
$cacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "jcalderonzumba" . DIRECTORY_SEPARATOR . "phantomjs";
if (!file_exists($cacheDir)) {
mkdir($cacheDir, 0777, true);
}
}
if (!file_exists($cacheDir)) {
throw new DriverException("Template cache $cacheDir directory does not exist");
}
return $cacheDir;
}
/**
* Helper to find a node element given an xpath
* @param string $xpath
* @param int $max
* @returns int
* @throws DriverException
*/
protected function findElement($xpath, $max = 1) {
$elements = $this->browser->find("xpath", $xpath);
if (!isset($elements["page_id"]) || !isset($elements["ids"]) || count($elements["ids"]) !== $max) {
throw new DriverException("Failed to get elements with given $xpath");
}
return $elements;
}
/**
* {@inheritdoc}
* @param Session $session
*/
public function setSession(Session $session) {
$this->session = $session;
}
/**
* @return Browser
*/
public function getBrowser() {
return $this->browser;
}
/**
* @return \Twig_Environment
*/
public function getTemplateEnv() {
return $this->templateEnv;
}
/**
* Returns a javascript script via twig template engine
* @param $templateName
* @param $viewData
* @return string
*/
public function javascriptTemplateRender($templateName, $viewData) {
/** @var $templateEngine \Twig_Environment */
$templateEngine = $this->getTemplateEnv();
return $templateEngine->render($templateName, $viewData);
}
}
<?php
namespace Zumba\Mink\Driver;
use Zumba\GastonJS\Cookie;
/**
* Trait CookieTrait
* @package Zumba\Mink\Driver
*/
trait CookieTrait {
/**
* Sets a cookie on the browser, if null value then delete it
* @param string $name
* @param string $value
*/
public function setCookie($name, $value = null) {
if ($value === null) {
$this->browser->removeCookie($name);
}
//TODO: set the cookie with domain, not with url, meaning www.aaa.com or .aaa.com
if ($value !== null) {
$urlData = parse_url($this->getCurrentUrl());
$cookie = array("name" => $name, "value" => $value, "domain" => $urlData["host"]);
$this->browser->setCookie($cookie);
}
}
/**
* Gets a cookie by its name if exists, else it will return null
* @param string $name
* @return string
*/
public function getCookie($name) {
$cookies = $this->browser->cookies();
foreach ($cookies as $cookie) {
if ($cookie instanceof Cookie && strcmp($cookie->getName(), $name) === 0) {
return $cookie->getValue();
}
}
return null;
}
}
<?php
namespace Zumba\Mink\Driver;
use Behat\Mink\Exception\DriverException;