-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PHPUnit invalid cookie domain and failing Nightwatch test #76
Fix PHPUnit invalid cookie domain and failing Nightwatch test #76
Conversation
I had updated |
.lando.yml
Outdated
@@ -21,7 +21,7 @@ services: | |||
SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite" | |||
BROWSERTEST_OUTPUT_DIRECTORY: '/app/web/sites/simpletest/browser_output' | |||
BROWSERTEST_OUTPUT_BASE_URL: 'https://drupal-contributions.lndo.site' | |||
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox"]}}, "http://chrome:9515"]' | |||
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chromedriver:9515"]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't DRUPAL_TEST_WEBDRIVER_HOSTNAME
be changed too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the change from http://chrome:9515 to http://chromedriver:9515 you mean? It might not be correct ... I just assumed that since the tests worked, this was the right set up.
But what would you suggest to update it to? Do you ask because you tried the patch and it didn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong.
With the given configuration, the DRUPAL_TEST_WEBDRIVER_HOSTNAME
value is the right one because the chrome driver container is reachable using the chrome
hostname. This value is used for nightwatch tests which seem to ignore cookie domain issues.
The real problem is that the WebDriverTestBase
tests are still not working because they cannot find the chromedriver service at the http://chromedriver:9515
URL. That's why they appear as skipped
in the PHPUnit report.
So, if we use http://chromedriver:9515
the test is skipped because it cannot reach the driver and if we use http://chrome:9515
which is the appropriate URL with the current lando configuration, the test fails because of the cookie domain error...
When trying to understand what's happening inside the chromedriver service, I can see the following trace (in /tmp/chromedriver.log
):
[1668781158.148][INFO]: [fe198b47912849d98bcf4c66f13b4b93] RESPONSE GetUrl "https://drupal-contributions.lndo.site/"
[1668781158.148][INFO]: [fe198b47912849d98bcf4c66f13b4b93] COMMAND AddCookie {
"cookie": {
"domain": "drupal-contributions.lndo.site",
"expires": 1668861158,
"name": "SIMPLETEST_USER_AGENT",
"secure": false,
"value": "simpletest20588224%3A1668781158%3A63779466232a65.73180091%3ABGYNVRC51qyN8Ch_xyVlXDJwHb1XmKrfcCbgQWiUsa4"
}
}
That helped me to understand that we are requesting https but the cookie is set with "secure": false
so that means that somehow Drupal doesn't understand he is serving secure content.
If we replace SIMPLETEST_BASE_URL
by an http
URL, the tests are working again!... but most of them are failing T_T
I had to dig a lot more to understand why the chromedriver was crashing despite the --no-sandbox
option you added. As usual, the answer came from stackoverflow and was talking about the /dev/shm
partition size. The easiest way to fix it seem to be mounting it as a volume linked to the host machine partition.
In the end I finally found a way to run the tests with the following changes only:
- changing both
SIMPLETEST_BASE_URL
andBROWSERTEST_OUTPUT_BASE_URL
to http
SIMPLETEST_BASE_URL: "http://drupal-contributions.lndo.site/"
...
BROWSERTEST_OUTPUT_BASE_URL: 'http://drupal-contributions.lndo.site'
- adding a volume on the
chrome
service:
chrome:
type: compose
app_mount: false
services:
image: drupalci/webdriver-chromedriver:production
volumes:
- /dev/shm:/dev/shm
command: chromedriver --log-path=/tmp/chromedriver.log --allowed-origins=* --verbose --whitelisted-ips=
Now, all tests are working \o/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the chromedriver
hosts are because that's what I named my service but drupal-contributions uses chrome
for the service so they should be converted.
As far as the sandbox stuff, that's interesting. I wonder if its environment specific because I was getting similar errors with --no-sandbox
being needed but not solving the whole shared memory thing but the SO search ended with me adding the seccomp:unconfined
line which fixed it on my machine. I guess you may need one of the other depending on system configuration but I can't see a problem with adding both. Well, other then the fact both are turning off container protections but I think that's going to be the price of doing business with chrome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great detective work @DuaelFr, and thanks for chiming in @neclimdul.
It would be great if you two could work out the best solution, and eventually share the optimal .lando.yml here, so that I can update the MR with that set up.
For what it's worth, I had to work through this problem to get a FunctionalJavascript test working this week - this thread was really helpful - and ultimately came up with the following changes that I had to make... An explanation of the changes:
The following patch is based on commit 701faff i.e.: the HEAD of the diff --git a/.gitignore b/.gitignore
index fe2a948..12fac38 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ node_modules
*.sql
*.sql.gz
*.gz
+/.phpunit.result.cache
diff --git a/.lando.yml b/.lando.yml
index 004f09b..b43e149 100644
--- a/.lando.yml
+++ b/.lando.yml
@@ -5,6 +5,7 @@ config:
services:
appserver:
+ composer_version: '2.3.6'
build_as_root:
# Note that you will want to use the script for the major version of node you want to install
# See: https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
@@ -17,11 +18,11 @@ services:
- yarn install --non-interactive --cwd /app/web/core
overrides:
environment:
- SIMPLETEST_BASE_URL: "https://drupal-contributions.lndo.site/"
+ SIMPLETEST_BASE_URL: "http://drupal-contributions.lndo.site/"
SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite"
BROWSERTEST_OUTPUT_DIRECTORY: '/app/web/sites/simpletest/browser_output'
- BROWSERTEST_OUTPUT_BASE_URL: 'https://drupal-contributions.lndo.site'
- MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox"]}}, "http://chrome:9515"]'
+ BROWSERTEST_OUTPUT_BASE_URL: 'http://drupal-contributions.lndo.site'
+ MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'
# Nightwatch
DRUPAL_TEST_BASE_URL: 'http://appserver'
DRUPAL_TEST_DB_URL: 'mysql://drupal10:drupal10@database:3306/drupal10'
@@ -33,10 +34,18 @@ services:
DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES: node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest
chrome:
type: compose
+ scanner: false
app_mount: false
services:
- image: drupalci/webdriver-chromedriver:production
- command: chromedriver --log-path=/tmp/chromedriver.log --allowed-origins=* --verbose --whitelisted-ips=
+ image: drupalci/chromedriver:production
+ expose:
+ - "9515"
+ - "4444"
+ volumes:
+ - /dev/shm:/dev/shm
+ security_opt:
+ - seccomp:unconfined
+ command: ["chromedriver", "--log-path=/tmp/chromedriver.log", "--verbose", "--allowed-ips=", "--allowed-origins=*", "--whitelisted-ips="]
tooling:
drush: |
It seems this gets it closer on the M1 based Mac but still doesn't work for M1 Apple devices. Exciting to see it inch closer. Glad it is working on other devices. Here is the output: lando nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js
The HTML file it wrote has the following in the raw log:
|
Thanks @neclimdul, @DuaelFr and @mparker17, your suggested solution works well, and I have updated the MR. Some Nightwatch tests were working well, such as tests/Drupal/Nightwatch/Tests/exampleTest.js, but running @mparker17: Possibly use |
Hey @gitressa, thanks for this PR, some feedback on it. Is Nitpick: I don't think b9a8b06 belongs in this PR. |
I tested with this set of changes using The I'm not sure if Github lets me propose changes to your PR so I'm just pasting the diff here to show :) diff --git a/.lando.yml b/.lando.yml
index 473b225..e5b0c42 100644
--- a/.lando.yml
+++ b/.lando.yml
@@ -1,5 +1,5 @@
name: drupal-contributions
-recipe: drupal9
+recipe: drupal10
config:
webroot: web
@@ -12,18 +12,19 @@ services:
- apt-get install -y nodejs
- npm install --global yarn
run:
+ - composer self-update
- cd /app/web && composer require drush/drush && composer install
- mkdir -p private/browsertest_output
- yarn install --non-interactive --cwd /app/web/core
overrides:
environment:
- SIMPLETEST_BASE_URL: "https://drupal-contributions.lndo.site/"
+ SIMPLETEST_BASE_URL: "http://drupal-contributions.lndo.site/"
SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite"
BROWSERTEST_OUTPUT_DIRECTORY: '/app/web/sites/simpletest/browser_output'
- BROWSERTEST_OUTPUT_BASE_URL: 'https://drupal-contributions.lndo.site'
- MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox"]}}, "http://chrome:9515"]'
+ BROWSERTEST_OUTPUT_BASE_URL: 'http://drupal-contributions.lndo.site'
+ MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'
# Nightwatch
- DRUPAL_TEST_BASE_URL: 'http://appserver'
+ DRUPAL_TEST_BASE_URL: 'http://drupal-contributions.lndo.site'
DRUPAL_TEST_DB_URL: 'mysql://drupal9:drupal9@database:3306/drupal9'
DRUPAL_TEST_WEBDRIVER_HOSTNAME: chrome
DRUPAL_TEST_WEBDRIVER_PORT: 9515
@@ -35,14 +36,17 @@ services:
type: compose
app_mount: false
services:
- image: drupalci/webdriver-chromedriver:production
- command: chromedriver --log-path=/tmp/chromedriver.log --allowed-origins=* --verbose --whitelisted-ips=
+ image: drupalci/chromedriver:production
+ expose:
+ - "9515"
+ - "4444"
+ command: ["chromedriver", "--allowed-ips=", "--allowed-origins=*", "--whitelisted-ips=", "--disable-dev-shm-usage"]
tooling:
drush:
service: appserver
cmd:
- web/vendor/drush/drush/drush --root=/app/web --uri=https://drupal-contributions.lndo.site
+ web/vendor/drush/drush/drush --root=/app/web --uri=http://drupal-contributions.lndo.site
si:
service: appserver
description: Install Drupal
I tried removing the https => http change but that didn't fly for me. |
Thanks xurizaemon. I am merely copy-pasting suggestions at this point, so about About b9a8b06: Yes, I have removed it. I see you use I'll try your suggestion later, and see if it works in Linux. |
That was just me being lazy! I think your proposed fix in #78 is better.
FWIW I'm testing in Linux. |
Ah, thanks for clearing that up :) I tried the changes, and these tests work (Ubuntu 20.04):
The Olivero test works with the current patch, but fails with your updates:
Maybe you can check if the Olivero test works for you? |
Like @theMusician, I have struggled to get tests running on an M1 chip-powered mac. I found a solution, but I don’t know what the correct way to implement it is. Searching for diff --git a/.lando.yml b/.lando.yml
index 004f09b..265f40b 100644
--- a/.lando.yml
+++ b/.lando.yml
@@ -35,8 +35,17 @@ services:
type: compose
app_mount: false
services:
- image: drupalci/webdriver-chromedriver:production
- command: chromedriver --log-path=/tmp/chromedriver.log --allowed-origins=* --verbose --whitelisted-ips=
+ image: seleniarm/standalone-chromium:102.0.5005.61
+ environment:
+ START_XVFB: 'false'
+ SE_NODE_MAX_SESSIONS: 5
+ JAVA_OPTS: "-XX:ActiveProcessorCount=5"
+ SE_NODE_OVERRIDE_MAX_SESSIONS: 5
+ expose:
+ - 9515
+ - 4444
+ command: ["chromedriver", "--allowed-ips=", "--allowed-origins=*", "--whitelisted-ips=", "--disable-dev-shm-usage"]
+
tooling:
drush: Here’s a diff of my diff --git a/.lando.yml b/.lando.yml
index 004f09b..313cb21 100644
--- a/.lando.yml
+++ b/.lando.yml
@@ -5,6 +5,7 @@ config:
services:
appserver:
+ composer_version: 2-latest
build_as_root:
# Note that you will want to use the script for the major version of node you want to install
# See: https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
@@ -17,11 +18,11 @@ services:
- yarn install --non-interactive --cwd /app/web/core
overrides:
environment:
- SIMPLETEST_BASE_URL: "https://drupal-contributions.lndo.site/"
+ SIMPLETEST_BASE_URL: "http://drupal-contributions.lndo.site/"
SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite"
BROWSERTEST_OUTPUT_DIRECTORY: '/app/web/sites/simpletest/browser_output'
- BROWSERTEST_OUTPUT_BASE_URL: 'https://drupal-contributions.lndo.site'
- MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox"]}}, "http://chrome:9515"]'
+ BROWSERTEST_OUTPUT_BASE_URL: 'http://drupal-contributions.lndo.site'
+ MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'
# Nightwatch
DRUPAL_TEST_BASE_URL: 'http://appserver'
DRUPAL_TEST_DB_URL: 'mysql://drupal10:drupal10@database:3306/drupal10'
@@ -35,14 +36,23 @@ services:
type: compose
app_mount: false
services:
- image: drupalci/webdriver-chromedriver:production
- command: chromedriver --log-path=/tmp/chromedriver.log --allowed-origins=* --verbose --whitelisted-ips=
+ image: seleniarm/standalone-chromium:102.0.5005.61
+ environment:
+ START_XVFB: 'false'
+ SE_NODE_MAX_SESSIONS: 5
+ JAVA_OPTS: "-XX:ActiveProcessorCount=5"
+ SE_NODE_OVERRIDE_MAX_SESSIONS: 5
+ expose:
+ - 9515
+ - 4444
+ command: ["chromedriver", "--allowed-ips=", "--allowed-origins=*", "--whitelisted-ips=", "--disable-dev-shm-usage"]
+
tooling:
drush:
service: appserver
cmd:
- web/vendor/drush/drush/drush --root=/app/web --uri=https://drupal-contributions.lndo.site
+ web/vendor/drush/drush/drush --root=/app/web --uri=http://drupal-contributions.lndo.site
si:
service: appserver
description: Install Drupal I hope this helps anyone trying to run tests against the 10.x branch via Lando on an M1-powered mac. |
Thank you for posting @agarzola. I'll give this a try with the latest Lando release in the near future. Very exciting to hear you got it running. An image that works with this Apple Silicon seems to be the missing piece. Thank you to you and Reddit! |
@agarzola - your changes worked for me on an M1 as well. Nightwatch, PHP unit, hooray! Tests also seem to run faster than ever. I am still using v3.6.4 of Lando. |
I had to change DRUPAL_TEST_BASE_URL to http://drupal-contributions.lndo.site, and set composer_version: 2-latest. |
- Updates `DRUPAL_TEST_BASE_URL` to http://drupal-contributions.lndo.site. - Adds `composer_version: 2-latest` to get the latest Composer version for Drupal 10 support.
Thanks @mortona42 I have updated the merge request, and both PHPUnit and NightWatch tests work well. There's already #78 (fixes #69), but having a single patch here, which makes tests work in Drupal 10 is easier. |
Fixes: #70. Issue with failing test and
WebDriver\Exception\InvalidCookieDomain: invalid cookie domain message
error message. This update looks like it makes both PHPUnit and Nightwatch work.New configuration kindly shared by @neclimdul in lando/lando#3411 (comment).
After the update
PHPUnit Olivero test
PHPUnit Password Hashing test
Nightwatch example test
Nightwatch Olivero test