diff --git a/composer.lock b/composer.lock index a8e3057..2f479e1 100644 --- a/composer.lock +++ b/composer.lock @@ -1099,12 +1099,12 @@ "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "reference": "1.0.0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/php-fig/log/zipball/1.0.0", + "reference": "1.0.0", "shasum": "" }, "type": "library", @@ -2988,6 +2988,67 @@ "time": "2016-03-05T09:04:22+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": "doctrine/instantiator", "version": "1.0.5", "source": { @@ -3128,6 +3189,64 @@ "time": "2015-11-05T12:58:44+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": "jcalderonzumba/gastonjs", "version": "v1.0.2", "source": { diff --git a/core/composer.json b/core/composer.json index b1dd8cf..6848049 100644 --- a/core/composer.json +++ b/core/composer.json @@ -38,6 +38,7 @@ "require-dev": { "behat/mink": "1.7.x-dev", "behat/mink-goutte-driver": "~1.2", + "behat/mink-selenium2-driver": "~1.3", "drupal/coder": "8.2.10", "jcalderonzumba/gastonjs": "~1.0.2", "jcalderonzumba/mink-phantomjs-driver": "~0.3.1", diff --git a/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php new file mode 100644 index 0000000..8e247eb --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php @@ -0,0 +1,36 @@ +getWebDriverSession()->deleteCookie($name); + + return; + } + + $cookieArray = array( + 'name' => $name, + 'value' => urlencode($value), + 'secure' => false, // thanks, chibimagic! + 'domain' => parse_url($this->getWebDriverSession()->url(), PHP_URL_HOST), // drupal-fixes: phantomjs hack + 'expiry' => time() + 80000, + ); + + try { + $this->getWebDriverSession()->setCookie($cookieArray); + } catch (\Exception $e) {} + + } +} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php index 815a26b..d78ce03 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 d5156ee..2de9c67 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 566fa23..3c38201 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,29 @@ 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 +```