diff --git a/composer.json b/composer.json index 38078d6b06..9353634f92 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "license": "GPL-2.0+", "require": { "composer/installers": "^1.0.24", - "wikimedia/composer-merge-plugin": "~1.4" + "wikimedia/composer-merge-plugin": "~1.4", + "behat/mink-selenium2-driver": "^1.3" }, "replace": { "drupal/core": "~8.4" diff --git a/composer.lock b/composer.lock index d7c3a26a81..82b52be1f3 100644 --- a/composer.lock +++ b/composer.lock @@ -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" ], - "content-hash": "5264cac45d935c61a1d48a32b71c9f15", + "content-hash": "b0f00c5a52b66261ff16d3f444e5fb9f", "packages": [ { "name": "asm89/stack-cors", @@ -59,6 +59,125 @@ "time": "2017-04-11T20:03:41+00:00" }, { + "name": "behat/mink", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/minkphp/Mink.git", + "reference": "9ea1cebe3dc529ba3861d87c818f045362c40484" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/Mink/zipball/9ea1cebe3dc529ba3861d87c818f045362c40484", + "reference": "9ea1cebe3dc529ba3861d87c818f045362c40484", + "shasum": "" + }, + "require": { + "php": ">=5.3.1", + "symfony/css-selector": "~2.1|~3.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7|~3.0" + }, + "suggest": { + "behat/mink-browserkit-driver": "extremely fast headless driver for Symfony\\Kernel-based apps (Sf2, Silex)", + "behat/mink-goutte-driver": "fast headless driver for any app without JS emulation", + "behat/mink-selenium2-driver": "slow, but JS-enabled driver for any app (requires Selenium2)", + "behat/mink-zombie-driver": "fast and JS-enabled headless driver for any app (requires node.js)" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Browser controller/emulator abstraction for PHP", + "homepage": "http://mink.behat.org/", + "keywords": [ + "browser", + "testing", + "web" + ], + "time": "2017-02-06T09:59:54+00:00" + }, + { + "name": "behat/mink-selenium2-driver", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/minkphp/MinkSelenium2Driver.git", + "reference": "473a9f3ebe0c134ee1e623ce8a9c852832020288" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/MinkSelenium2Driver/zipball/473a9f3ebe0c134ee1e623ce8a9c852832020288", + "reference": "473a9f3ebe0c134ee1e623ce8a9c852832020288", + "shasum": "" + }, + "require": { + "behat/mink": "~1.7@dev", + "instaclick/php-webdriver": "~1.1", + "php": ">=5.3.1" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "mink-driver", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\Driver\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Pete Otaqui", + "email": "pete@otaqui.com", + "homepage": "https://github.com/pete-otaqui" + } + ], + "description": "Selenium2 (WebDriver) driver for Mink framework", + "homepage": "http://mink.behat.org/", + "keywords": [ + "ajax", + "browser", + "javascript", + "selenium", + "testing", + "webdriver" + ], + "time": "2016-03-05T09:10:18+00:00" + }, + { "name": "composer/installers", "version": "v1.2.0", "source": { @@ -918,6 +1037,64 @@ "time": "2017-03-20T17:10:46+00:00" }, { + "name": "instaclick/php-webdriver", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/instaclick/php-webdriver.git", + "reference": "0c20707dcf30a32728fd6bdeeab996c887fdb2fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/instaclick/php-webdriver/zipball/0c20707dcf30a32728fd6bdeeab996c887fdb2fb", + "reference": "0c20707dcf30a32728fd6bdeeab996c887fdb2fb", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=5.3.2" + }, + "require-dev": { + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "WebDriver": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Justin Bishop", + "email": "jubishop@gmail.com", + "role": "Developer" + }, + { + "name": "Anthon Pang", + "email": "apang@softwaredevelopment.ca", + "role": "Fork maintainer" + } + ], + "description": "PHP WebDriver for Selenium 2", + "homepage": "http://instaclick.com/", + "keywords": [ + "browser", + "selenium", + "webdriver", + "webtest" + ], + "time": "2015-06-15T20:19:33+00:00" + }, + { "name": "masterminds/html5", "version": "2.2.2", "source": { @@ -1355,6 +1532,59 @@ "time": "2017-04-26T01:39:17+00:00" }, { + "name": "symfony/css-selector", + "version": "v3.2.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "02983c144038e697c959e6b06ef6666de759ccbc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/02983c144038e697c959e6b06ef6666de759ccbc", + "reference": "02983c144038e697c959e6b06ef6666de759ccbc", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "https://symfony.com", + "time": "2017-05-01T14:55:58+00:00" + }, + { "name": "symfony/debug", "version": "v3.2.8", "source": { @@ -2558,64 +2788,6 @@ ], "packages-dev": [ { - "name": "behat/mink", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/minkphp/Mink.git", - "reference": "9ea1cebe3dc529ba3861d87c818f045362c40484" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/minkphp/Mink/zipball/9ea1cebe3dc529ba3861d87c818f045362c40484", - "reference": "9ea1cebe3dc529ba3861d87c818f045362c40484", - "shasum": "" - }, - "require": { - "php": ">=5.3.1", - "symfony/css-selector": "~2.1|~3.0" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7|~3.0" - }, - "suggest": { - "behat/mink-browserkit-driver": "extremely fast headless driver for Symfony\\Kernel-based apps (Sf2, Silex)", - "behat/mink-goutte-driver": "fast headless driver for any app without JS emulation", - "behat/mink-selenium2-driver": "slow, but JS-enabled driver for any app (requires Selenium2)", - "behat/mink-zombie-driver": "fast and JS-enabled headless driver for any app (requires node.js)" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.7.x-dev" - } - }, - "autoload": { - "psr-4": { - "Behat\\Mink\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - } - ], - "description": "Browser controller/emulator abstraction for PHP", - "homepage": "http://mink.behat.org/", - "keywords": [ - "browser", - "testing", - "web" - ], - "time": "2017-02-06T09:59:54+00:00" - }, - { "name": "behat/mink-browserkit-driver", "version": "v1.3.2", "source": { @@ -4068,59 +4240,6 @@ "time": "2017-04-12T14:13:17+00:00" }, { - "name": "symfony/css-selector", - "version": "v3.2.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/css-selector.git", - "reference": "02983c144038e697c959e6b06ef6666de759ccbc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/02983c144038e697c959e6b06ef6666de759ccbc", - "reference": "02983c144038e697c959e6b06ef6666de759ccbc", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\CssSelector\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jean-François Simon", - "email": "jeanfrancois.simon@sensiolabs.com" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony CssSelector Component", - "homepage": "https://symfony.com", - "time": "2017-05-01T14:55:58+00:00" - }, - { "name": "symfony/dom-crawler", "version": "v3.2.8", "source": { diff --git a/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php new file mode 100644 index 0000000000..13d1f4e38a --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php @@ -0,0 +1,32 @@ +getWebDriverSession()->deleteCookie($name); + return; + } + + $cookieArray = [ + 'name' => $name, + 'value' => urlencode($value), + 'secure' => FALSE, + 'domain' => parse_url($this->getWebDriverSession()->url(), PHP_URL_HOST), + 'expires' => time() + 80000, + ]; + + $this->getWebDriverSession()->setCookie($cookieArray); + } + +} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php index 81d379f915..fe7692a66a 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php @@ -366,4 +366,26 @@ function t(r, lx, ly) { return $this->session->evaluateScript($full_javascript_visibility_test); } + /** + * Overrides statusCodeEquals function. Use Functional tests for status code validation + * + * @param int $code + * + */ + public function statusCodeEquals($code) + { + // should we throw an error? + } + + /** + * Overrides statusCodeEquals function. Use Functional tests for status code validation + * + * @param int $code + * + */ + public function statusCodeNotEquals($code) + { + // should we throw an error? + } + } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php index d5156eeb5c..2de9c67251 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php @@ -2,9 +2,9 @@ namespace Drupal\FunctionalJavascriptTests; +use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; +use Behat\Mink\Exception\DriverException; use Drupal\Tests\BrowserTestBase; -use Zumba\GastonJS\Exception\DeadClient; -use Zumba\Mink\Driver\PhantomJSDriver; /** * Runs a browser test using PhantomJS. @@ -16,27 +16,19 @@ /** * {@inheritdoc} */ - protected $minkDefaultDriverClass = PhantomJSDriver::class; + protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; /** * {@inheritdoc} */ protected function initMink() { - // Set up the template cache used by the PhantomJS mink driver. - $path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache'; - $this->minkDefaultDriverArgs = [ - 'http://127.0.0.1:8510', - $path, - ]; - if (!file_exists($path)) { - mkdir($path); - } + $this->minkDefaultDriverArgs = ['phantomjs']; try { return parent::initMink(); } - catch (DeadClient $e) { - $this->markTestSkipped('PhantomJS is either not installed or not running. Start it via phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&'); + catch (DriverException $e) { + $this->markTestSkipped($e->getMessage()); } catch (\Exception $e) { $this->markTestSkipped('An unexpected error occurred while starting Mink: ' . $e->getMessage()); @@ -169,4 +161,12 @@ protected function getDrupalSettings() { return $this->getSession()->evaluateScript($script) ?: []; } + /** + * {@inheritdoc} + */ + protected function getHtmlOutputHeaders() { + // No headers on the selenium driver, nothing to show. + return ''; + } + } diff --git a/core/tests/README.md b/core/tests/README.md index 5dd6cc6394..a6258b9378 100644 --- a/core/tests/README.md +++ b/core/tests/README.md @@ -2,16 +2,11 @@ ## Functional tests -* Start PhantomJS: - ``` - phantomjs --ssl-protocol=any --ignore-ssl-errors=true ./vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null & - ``` * Run the functional tests: ``` export SIMPLETEST_DB='mysql://root@localhost/dev_d8' export SIMPLETEST_BASE_URL='http://d8.dev' ./vendor/bin/phpunit -c core --testsuite functional - ./vendor/bin/phpunit -c core --testsuite functional-javascript ``` Note: functional tests have to be invoked with a user in the same group as the @@ -46,3 +41,30 @@ export SIMPLETEST_BASE_URL='http://d8.dev' sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional-javascript ``` + +## Functional javascript tests + +* Start PhantomJS: + ``` + phantomjs --webdriver=4444 + ``` + +* Run the functional javascript tests: + +``` + ./vendor/bin/phpunit -c core --testsuite functional-javascript +``` + +* Alternative to use phantomjs you can also use a real browser like + firefox/chrome too actually see what the test is doing. + +* Install and start selenium, see http://mink.behat.org/en/latest/drivers/selenium2.html + +* Set an additional environment parameter to tell the test to use firefox: +``` +export MINK_DRIVER_ARGS='["firefox", null, "http://localhost:4444/wd/hub"]' +``` +* Run the tests as before, now a firefox window should appear. +``` + ./vendor/bin/phpunit -c core --testsuite functional-javascript +```