Issue #3240792 by justafish, alexpott, andypost, smustgrave, longwave: Use lullabot/mink-selenium2-driver and lullabot/php-webdriver for functional browser testing

(cherry picked from commit 5927d8fe07)
merge-requests/9720/head
catch 2024-03-07 15:23:16 +00:00
parent 5f208d1ba8
commit ec1aa07ac8
14 changed files with 234 additions and 152 deletions

View File

@ -14,7 +14,7 @@ variables:
POSTGRES_DB: drupaltestbot
POSTGRES_USER: drupaltestbot
POSTGRES_PASSWORD: drupaltestbotpw
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-dev-shm-usage","--disable-gpu","--headless"]}}, "http://localhost:9515"]'
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--disable-dev-shm-usage","--disable-gpu","--headless"]}}, "http://localhost:9515"]'
'🩹 Test-only changes':
stage: 🗜️ Test

View File

@ -67,7 +67,7 @@ variables:
POSTGRES_DB: drupaltestbot
POSTGRES_USER: drupaltestbot
POSTGRES_PASSWORD: drupaltestbotpw
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-dev-shm-usage","--disable-gpu","--headless","--dns-prefetch-disable"]}}, "http://localhost:9515"]'
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--disable-dev-shm-usage","--disable-gpu","--headless","--dns-prefetch-disable"]}}, "http://localhost:9515"]'
CI_PARALLEL_NODE_INDEX: $CI_NODE_INDEX
CI_PARALLEL_NODE_TOTAL: $CI_NODE_TOTAL

View File

@ -17,12 +17,12 @@
"require-dev": {
"behat/mink": "^1.11",
"behat/mink-browserkit-driver": "^2.2",
"behat/mink-selenium2-driver": "^1.7",
"colinodell/psr-testlogger": "^1.2",
"composer/composer": "^2.7",
"drupal/coder": "^8.3.10",
"instaclick/php-webdriver": "^1.4.1",
"justinrainbow/json-schema": "^5.2",
"lullabot/mink-selenium2-driver": "^1.7",
"lullabot/php-webdriver": "^2.0.3",
"mglaman/phpstan-drupal": "^1.2.1",
"micheh/phpcs-gitlab": "^1.1",
"mikey179/vfsstream": "^1.6.11",

253
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9103791a18c3a090bfd3335ff65a404a",
"content-hash": "50678d888725975acfa1fb438696b593",
"packages": [
{
"name": "asm89/stack-cors",
@ -4576,76 +4576,6 @@
},
"time": "2023-12-09T11:30:50+00:00"
},
{
"name": "behat/mink-selenium2-driver",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/minkphp/MinkSelenium2Driver.git",
"reference": "4ca4083f305de7dff4434ac402dc4e3f39c0866a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/minkphp/MinkSelenium2Driver/zipball/4ca4083f305de7dff4434ac402dc4e3f39c0866a",
"reference": "4ca4083f305de7dff4434ac402dc4e3f39c0866a",
"shasum": ""
},
"require": {
"behat/mink": "^1.11@dev",
"ext-json": "*",
"instaclick/php-webdriver": "^1.4.14",
"php": ">=7.2"
},
"require-dev": {
"mink/driver-testsuite": "dev-master",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^8.5.22 || ^9.5.11",
"symfony/error-handler": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"type": "mink-driver",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Behat\\Mink\\Driver\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Pete Otaqui",
"email": "pete@otaqui.com",
"homepage": "https://github.com/pete-otaqui"
},
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
}
],
"description": "Selenium2 (WebDriver) driver for Mink framework",
"homepage": "https://mink.behat.org/",
"keywords": [
"ajax",
"browser",
"javascript",
"selenium",
"testing",
"webdriver"
],
"support": {
"issues": "https://github.com/minkphp/MinkSelenium2Driver/issues",
"source": "https://github.com/minkphp/MinkSelenium2Driver/tree/v1.7.0"
},
"time": "2023-12-09T11:58:45+00:00"
},
{
"name": "colinodell/psr-testlogger",
"version": "v1.3.0",
@ -5517,69 +5447,6 @@
},
"time": "2023-11-15T21:36:03+00:00"
},
{
"name": "instaclick/php-webdriver",
"version": "1.4.18",
"source": {
"type": "git",
"url": "https://github.com/instaclick/php-webdriver.git",
"reference": "a61a8459f86c79dd1f19934ea3929804f2e41f8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/instaclick/php-webdriver/zipball/a61a8459f86c79dd1f19934ea3929804f2e41f8c",
"reference": "a61a8459f86c79dd1f19934ea3929804f2e41f8c",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.5",
"satooshi/php-coveralls": "^1.0 || ^2.0"
},
"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"
],
"support": {
"issues": "https://github.com/instaclick/php-webdriver/issues",
"source": "https://github.com/instaclick/php-webdriver/tree/1.4.18"
},
"time": "2023-12-08T07:11:19+00:00"
},
{
"name": "justinrainbow/json-schema",
"version": "v5.2.13",
@ -5650,6 +5517,124 @@
},
"time": "2023-09-26T02:20:38+00:00"
},
{
"name": "lullabot/mink-selenium2-driver",
"version": "v1.7.2",
"source": {
"type": "git",
"url": "https://github.com/Lullabot/MinkSelenium2Driver.git",
"reference": "5f9ecc2dc329d87442843f6143a4307a62fc5f8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Lullabot/MinkSelenium2Driver/zipball/5f9ecc2dc329d87442843f6143a4307a62fc5f8c",
"reference": "5f9ecc2dc329d87442843f6143a4307a62fc5f8c",
"shasum": ""
},
"require": {
"behat/mink": "^1.11@dev",
"ext-json": "*",
"lullabot/php-webdriver": "^2.0",
"php": ">=7.2"
},
"replace": {
"behat/mink-selenium2-driver": "1.7.0"
},
"require-dev": {
"mink/driver-testsuite": "dev-master",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^8.5.22 || ^9.5.11",
"symfony/error-handler": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"type": "mink-driver",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Behat\\Mink\\Driver\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Pete Otaqui",
"email": "pete@otaqui.com",
"homepage": "https://github.com/pete-otaqui"
},
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
}
],
"description": "Selenium2 (WebDriver) driver for Mink framework",
"homepage": "https://mink.behat.org/",
"keywords": [
"ajax",
"browser",
"javascript",
"selenium",
"testing",
"webdriver"
],
"support": {
"source": "https://github.com/Lullabot/MinkSelenium2Driver/tree/v1.7.2"
},
"time": "2024-02-12T10:40:39+00:00"
},
{
"name": "lullabot/php-webdriver",
"version": "v2.0.3",
"source": {
"type": "git",
"url": "https://github.com/Lullabot/php-webdriver.git",
"reference": "ca66013201d8b0ef634ee5d1685fc7bb95c88d89"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Lullabot/php-webdriver/zipball/ca66013201d8b0ef634ee5d1685fc7bb95c88d89",
"reference": "ca66013201d8b0ef634ee5d1685fc7bb95c88d89",
"shasum": ""
},
"require": {
"ext-curl": "*"
},
"replace": {
"instaclick/php-webdriver": "1.4.16"
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.5"
},
"type": "library",
"autoload": {
"psr-0": {
"WebDriver": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "PHP WebDriver for Selenium 2",
"homepage": "https://www.lullabot.com/",
"keywords": [
"browser",
"selenium",
"webdriver",
"webtest"
],
"support": {
"source": "https://github.com/Lullabot/php-webdriver/tree/v2.0.3"
},
"time": "2024-02-20T16:25:25+00:00"
},
{
"name": "mglaman/phpstan-drupal",
"version": "1.2.4",

View File

@ -9,12 +9,12 @@
"require": {
"behat/mink": "^1.11",
"behat/mink-browserkit-driver": "^2.2",
"behat/mink-selenium2-driver": "^1.7",
"colinodell/psr-testlogger": "^1.2",
"composer/composer": "^2.7",
"drupal/coder": "^8.3.10",
"instaclick/php-webdriver": "^1.4.1",
"justinrainbow/json-schema": "^5.2",
"lullabot/mink-selenium2-driver": "^1.7",
"lullabot/php-webdriver": "^2.0.3",
"mglaman/phpstan-drupal": "^1.2.1",
"micheh/phpcs-gitlab": "^1.1",
"mikey179/vfsstream": "^1.6.11",

View File

@ -10,7 +10,6 @@
"drupal/core": "10.3.x-dev",
"behat/mink": "v1.11.0",
"behat/mink-browserkit-driver": "v2.2.0",
"behat/mink-selenium2-driver": "v1.7.0",
"colinodell/psr-testlogger": "v1.3.0",
"composer/ca-bundle": "1.3.7",
"composer/class-map-generator": "1.1.0",
@ -23,8 +22,9 @@
"doctrine/instantiator": "2.0.0",
"drupal/coder": "8.3.22",
"google/protobuf": "v3.25.1",
"instaclick/php-webdriver": "1.4.18",
"justinrainbow/json-schema": "v5.2.13",
"lullabot/mink-selenium2-driver": "v1.7.2",
"lullabot/php-webdriver": "v2.0.3",
"mglaman/phpstan-drupal": "1.2.4",
"micheh/phpcs-gitlab": "1.1.0",
"mikey179/vfsstream": "v1.6.11",

View File

@ -22,7 +22,6 @@ class Config {
protected static $defaultConfig = [
'behat/mink' => ['tests'],
'behat/mink-browserkit-driver' => ['tests'],
'behat/mink-selenium2-driver' => ['tests'],
'composer/composer' => ['bin'],
'drupal/coder' => [
'coder_sniffer/Drupal/Test',
@ -32,8 +31,9 @@ class Config {
'egulias/email-validator' => ['documentation', 'tests'],
'guzzlehttp/promises' => ['tests'],
'guzzlehttp/psr7' => ['tests'],
'instaclick/php-webdriver' => ['doc', 'test'],
'justinrainbow/json-schema' => ['demo'],
'lullabot/mink-selenium2-driver' => ['tests'],
'lullabot/php-webdriver' => ['doc', 'test'],
'masterminds/html5' => ['bin', 'test'],
'mck89/peast' => ['doc'],
'mikey179/vfsstream' => ['src/test'],

View File

@ -8,6 +8,7 @@ druplicon
drush
langcode
langcodes
lullabot
olivero
olivero's
simpletest

View File

@ -57,7 +57,7 @@
<env name="MINK_DRIVER_CLASS" value=''/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=''/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "goog:chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=''/>
</php>
<testsuites>

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Drupal\FunctionalJavascriptTests\Tests;
use Behat\Mink\Driver\Selenium2Driver;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\file\Functional\FileFieldCreationTrait;
@ -48,6 +49,9 @@ class DrupalSelenium2DriverTest extends WebDriverTestBase {
*/
public function testGetRemoteFilePath() {
$web_driver = $this->getSession()->getDriver();
$this->assertInstanceOf(Selenium2Driver::class, $web_driver);
$this->assertFalse($web_driver->isW3C(), 'Driver is not operating in W3C mode');
$file_system = \Drupal::service('file_system');
$entity = EntityTest::create();
$entity->save();

View File

@ -48,7 +48,7 @@ abstract class WebDriverTestBase extends BrowserTestBase {
if (!is_a($this->minkDefaultDriverClass, DrupalSelenium2Driver::class, TRUE)) {
throw new \UnexpectedValueException(sprintf("%s has to be an instance of %s", $this->minkDefaultDriverClass, DrupalSelenium2Driver::class));
}
$this->minkDefaultDriverArgs = ['chrome', NULL, 'http://localhost:4444'];
$this->minkDefaultDriverArgs = ['chrome', ['goog:chromeOptions' => ['w3c' => FALSE]], 'http://localhost:4444'];
try {
return parent::initMink();
@ -145,7 +145,22 @@ abstract class WebDriverTestBase extends BrowserTestBase {
*/
protected function getMinkDriverArgs() {
if ($this->minkDefaultDriverClass === DrupalSelenium2Driver::class) {
return getenv('MINK_DRIVER_ARGS_WEBDRIVER') ?: parent::getMinkDriverArgs();
$json = getenv('MINK_DRIVER_ARGS_WEBDRIVER') ?: parent::getMinkDriverArgs();
if (!($json === FALSE || $json === '')) {
$args = json_decode($json, TRUE);
if (isset($args[1]['chromeOptions'])) {
@trigger_error('The "chromeOptions" array key is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use "goog:chromeOptions instead. See https://www.drupal.org/node/3422624', E_USER_DEPRECATED);
$args[1]['goog:chromeOptions'] = $args[1]['chromeOptions'];
unset($args[1]['chromeOptions']);
}
if (isset($args[0]) && $args[0] === 'chrome' && !isset($args[1]['goog:chromeOptions']['w3c'])) {
// @todo https://www.drupal.org/project/drupal/issues/3421202
// Deprecate defaulting behavior and require w3c to be set.
$args[1]['goog:chromeOptions']['w3c'] = FALSE;
}
$json = json_encode($args);
}
return $json;
}
return parent::getMinkDriverArgs();
}

View File

@ -5,12 +5,12 @@
"content-hash": "da9910627bab73a256b39ceda83d7167",
"packages-dev": [
{
"name": "behat/mink-selenium2-driver",
"version": "dev-master",
"name": "lullabot/mink-selenium2-driver",
"version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/minkphp/MinkSelenium2Driver.git",
"reference": "0a09c4341621fca937a726827611b20ce3e2c259"
"url": "https://github.com/Lullabot/MinkSelenium2Driver.git",
"reference": "228004452354c1945fec2d273de2586da8c29213"
}
}
]

View File

@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\Core\Test;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\FunctionalJavascriptTests\WebDriverTestBase
* @group Test
* @runTestsInSeparateProcesses
*/
class WebDriverTestBaseTest extends UnitTestCase {
/**
* Tests W3C setting is added to goog:chromeOptions as expected.
*
* @testWith [false, null]
* [false, ""]
* ["", "", ""]
* ["[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"w3c\":true,\"args\":[\"--headless\"]}},\"http:\\/\\/localhost:4444\"]", "[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"w3c\":true,\"args\":[\"--headless\"]}},\"http:\\/\\/localhost:4444\"]"]
* ["[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"w3c\":false,\"args\":[\"--headless\"]}},\"http:\\/\\/localhost:4444\"]", "[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"w3c\":false,\"args\":[\"--headless\"]}},\"http:\\/\\/localhost:4444\"]"]
* ["[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"args\":[\"--headless\"],\"w3c\":false}},\"http:\\/\\/localhost:4444\"]", "[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"args\":[\"--headless\"]}},\"http:\\/\\/localhost:4444\"]"]
* ["[\"chrome\",{\"browserName\":\"chrome\",\"goog:chromeOptions\":{\"w3c\":false}},\"http:\\/\\/localhost:4444\"]", "[\"chrome\",{\"browserName\":\"chrome\"},\"http:\\/\\/localhost:4444\"]"]
*
* @covers ::getMinkDriverArgs
*/
public function testCapabilities($expected, ?string $mink_driver_args_webdriver, ?string $mink_driver_args = NULL): void {
$this->putEnv("MINK_DRIVER_ARGS_WEBDRIVER", $mink_driver_args_webdriver);
$this->putEnv("MINK_DRIVER_ARGS", $mink_driver_args);
$object = $this->getMockForAbstractClass(WebDriverTestBase::class);
$method = new \ReflectionMethod($object, 'getMinkDriverArgs');
$this->assertSame($expected, $method->invoke($object));
}
/**
* Sets or deletes an environment variable.
*
* @param string $variable
* The environment variable to set or delete.
* @param string|null $value
* The value to set the variable to. If the value is NULL then the
* environment variable will be unset.
*
* @return void
*/
private function putEnv(string $variable, ?string $value): void {
if (is_string($value)) {
putenv($variable . "=" . $value);
}
else {
putenv($variable);
}
}
/**
* Tests "chromeOptions" deprecation.
*
* @group legacy
*
* @covers ::getMinkDriverArgs
*/
public function testChromeOptions(): void {
$this->expectDeprecation('The "chromeOptions" array key is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use "goog:chromeOptions instead. See https://www.drupal.org/node/3422624');
putenv('MINK_DRIVER_ARGS_WEBDRIVER=["chrome",{"browserName":"chrome","chromeOptions":{"args":["--headless"]}},"http://localhost:4444"]');
$object = $this->getMockForAbstractClass(WebDriverTestBase::class);
$method = new \ReflectionMethod($object, 'getMinkDriverArgs');
$this->assertSame('["chrome",{"browserName":"chrome","goog:chromeOptions":{"args":["--headless"],"w3c":false}},"http:\\/\\/localhost:4444"]', $method->invoke($object));
}
}

View File

@ -75,7 +75,9 @@ trait PerformanceTestTrait {
'performance' => 'ALL',
'performanceTimeline' => 'ALL',
];
$driver_args[1]['chromeOptions']['perfLoggingPrefs'] = [
// Support legacy key.
$chrome_options_key = isset($driver_args[1]['chromeOptions']) ? 'chromeOptions' : 'goog:chromeOptions';
$driver_args[1][$chrome_options_key]['perfLoggingPrefs'] = [
'traceCategories' => 'timeline,devtools.timeline,browser',
];