Problem/Motivation

This is a follow-on from #3240792: Use lullabot/mink-selenium2-driver and lullabot/php-webdriver for functional browser testing. This issue enables W3C-compliant webdriver testing, thereby allowing Drupal's core tests, contrib module tests and custom tests to be run against modern browsers using selenium.

Proposed resolution

  • Fix Drupal code that uses non-W3C commands to use work on both W3C and non-W3C webdrivers.
  • Test against both W3C and non-W3C

Remaining tasks

  • Decide what mix of W3C and non-W3C tests we need to run.
    All nightwatch and functional JS tests to using selenium/standalone-chrome:latest - this is inline with our browser support policy and if it becomes an issue we will pin it to a verion.
  • Decide whether to add a manual job to run tests against Firefox
    This has to be a follow-up there are issues we need to resolve.
  • Decide whether to run W3C tests using drupalci/chromedriver or selenium/chromium. Our chromedriver image gets out of date and unmaintained quickly. This would help ensure Drupal is being tested on up-to-date browsers. The Selenium image also drops jsonwire support, which chromedriver still directly supports. This would force us to use the W3C standard, and allow us to test on other browsers in future.
    Using selenium/standalone-chrome:latest is inline with our browser support policy and we no longer have to maintain an image that gets out of date as quickly as we update it.
  • Decide what to run Performance tests and Test-only changes jobs using
    Moved to W3C / selenium

Followups:

User interface changes

None

API changes

\Drupal\FunctionalJavascriptTests\WebDriverCurlService is deprecated. This was added in #2942900-50: Convert JavascriptTestBase Tests to use DrupalSelenium2Driver. @longwave is pretty sure this has been fixed by https://issues.chromium.org/issues/42321790

Data model changes

None

Release notes snippet

Drupal core now tests using selenium/standalone-chrome:latest via a W3C compliant webdriver. To enable W3C mode in WebDriverTestBase tests, the MINK_DRIVER_ARGS_WEBDRIVER environment variable must pass "w3c": true in the options. To enable W3C mode in Nightwatch tests, the DRUPAL_TEST_WEBDRIVER_W3C environment variable must to be set to true.

Issue fork drupal-3421202

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review

Crediting @justafish as a tonne of the effort here is theirs.

smustgrave’s picture

Can you rerun the javascript tests? Want to make sure they aren't random but even I request access I can't rerun.

alexpott’s picture

@smustgrave it's definitely not random.

smustgrave’s picture

Status: Needs review » Needs work

Glad I asked!

justafish’s picture

Issue summary: View changes
catch’s picture

I've started using/recommending this locally too fwiw - a lot of people (more than 2-3 I could name) have trouble with the drupalci one which they don't run into with the selenium one.

andypost’s picture

justafish’s picture

I've split the part about upgrading the tests to https://www.drupal.org/project/drupal/issues/3432099 as we can test this is working using geckodriver

catch’s picture

After #3240792: Use lullabot/mink-selenium2-driver and lullabot/php-webdriver for functional browser testing I wasn't able run test locally with selenium/standalone-chrome, which I'd otherwise been using successfully for months, gave up trying to debug it and went back to the drupalci image (which has been working OK). I haven't seen anyone else run into issues since that commit, but presumably people will start to switch over if we switch gitlab, so just making a note here in case other people do indeed run into issues down the line.

andyf’s picture

Just to chime in re #12 I was seeing exactly the same thing (see https://github.com/ddev/ddev-selenium-standalone-chrome/issues/41). It appears that \WebDriver\WebDriver::session() is checking for the w3c flag one level higher up than where it's being set. I'm not sure if the issue should be fixed in lullabot/php-webdriver or by changing the capabilities we're passing. Locally I've just changed the capabilities, but I've seen plenty of examples on Stack Exchange etc. of the w3c flag being within goog:chromeOptions and I can't find a canonical reference on the matter.

tinto’s picture

I was seeing the same problem as #12, running test on my local machine with Drupal 11.x-dev.

I fixed it by implementing the workaround posted in #13 - I simply replaced line 15 in config.selenium-standalone-chrome.yaml to this:

- MINK_DRIVER_ARGS_WEBDRIVER=[\"chrome\", {\"browserName\":\"chrome\",\"w3c\":false,\"goog:chromeOptions\":{\"args\":[\"--disable-gpu\",\"--headless\", \"--no-sandbox\", \"--disable-dev-shm-usage\"]}}, \"http://selenium-chrome:4444/wd/hub\"]

Thank you @AndyF!

longwave made their first commit to this issue’s fork.

longwave’s picture

Status: Needs work » Needs review
Issue tags: +Needs change record

The change record needs to be written but otherwise the tests are green so marking NR, hopefully someone else familiar with Chrome testing can take a look.

We still need to decide how to deprecate non-W3C mode and what to do about tests in that time, do we run them in both modes or for core do we just switch to W3C mode only?

alexpott’s picture

My plan was to run a limited subset tests using non-W3C mode. while we still support it - i.e. until Drupal 12 and then in Drupal 12 we should only support W3C testing.

I think we should also add a manual job to run tests using Firefox.

andypost’s picture

I think we should also add a manual job to run tests using Firefox.

nice idea, there's selenium/standalone-firefox image

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes

alexpott changed the visibility of the branch 3421202-use-seleniumstandalone-chrome-instead to hidden.

andypost’s picture

Locally in docker I got few tests running fine using Firefox image with following arguments
MINK_DRIVER_ARGS_WEBDRIVER: '["firefox", {"browserName":"fixrefox","moz:firefoxOptions":{"args":["--headless"]}}, "http://browser:4444"]'

alexpott’s picture

Title: Use selenium/standalone-chrome instead of our chromedriver image » Enable W3C-compliant webdriver testing
Issue summary: View changes

Fixed up issue summary and title to be inline with current MR. Also added more to remaining tasks for things that we need to decide.

alexpott’s picture

Issue tags: -Needs change record
alexpott’s picture

Issue summary: View changes
andypost’s picture

Somehow FIrefox tests are x2 faster then selenium jobs

alexpott’s picture

@andypost that's not the case... they were skipping every test :D we should fail instead of skip when a WebDriverTestBase test fails to connect to a browser. Once I fixed the webdriver json string we can see that the tests are about the same speed - see https://git.drupalcode.org/project/drupal/-/pipelines/227038

Also Firefox has a different approach when elements are not in the viewport and you do a click - see https://stackoverflow.com/questions/44777053/selenium-movetargetoutofbou... - I think we should address this in our webdriver in the same way that webdriver-classic-driver does - see https://github.com/minkphp/webdriver-classic-driver/blob/73ad0b6ce21cf69...

alexpott’s picture

Lolz previous me pointed out that PHPUnit would skip if something required by the test is not available - see #3187577-11: FunctionalJavascript tests should fail when ChromeDriver is not running - I guess that comment is still correct. But it would be great if somehow the reason things are skipped was actually listed in the test output.

alexpott’s picture

To be fair you can see the skipped tests in the report on gitlab - see https://git.drupalcode.org/project/drupal/-/pipelines/227006/test_report

andypost’s picture

Thanks! it explains difference (all skipped for ff)

btw performance metrics also could be collected from FF, at least it has tracing out of box and allows to enable dev-tools (even via remote somehow) and get better details... for follow-up

andypost’s picture

Moreover it makes sense to explore optimizations related to --headless mode in browsers

alexpott changed the visibility of the branch 3421202-on-top-of-3240792 to hidden.

alexpott’s picture

Issue summary: View changes

Answered questions in the issue summary and update MR to reflect the answers.

alexpott’s picture

Issue summary: View changes

Created the follow-ups.

I think this is ready for review.

alexpott’s picture

One thing for reviewers to not is the move from 2 runners to 4 runners for the JS testing job. This is because testing on selenium is slower. There is not much we can do about this as far as I can see and the benefits of actually testing against current browsers and not maintaining our own chromedriver image are large.

catch’s picture

An interesting thing with the four vs. two javascript runners is that overall time still seems to be constrained by the slowest individual tests (either Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest or Drupal\Tests\ckeditor5\FunctionalJavascript\SourceEditingTest seem to be the longest running) and overall run duration is also similar to what it is now. I would kind of have expected the bottleneck to shift to the number of http requests away from installing Drupal, although maybe those tests also do loads of http requests too.

I wonder if we're hitting concurrency/cpu limits. However anything like that we can explore in a follow-up - four runners seems fine and there's no overall regression in the pipeline feedback.

longwave’s picture

If we're just moving Nightwatch entirely to w3c mode then we can drop the separate selenium environment and just turn on the w3c switch in the default environment.

longwave’s picture

Status: Needs review » Needs work

Added some nits/comments to the MR.

alexpott’s picture

Status: Needs work » Needs review

I've run core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php --filter testMultipleReplacements on both old chromedriver and selenium and the test fails with 2000 and the fix from #3390178: big_pipe sometimes fails to load blocks reverted so reducing to 2000 seems fine and we don't need a comment. That was useful to explain why we have reduced it but will be meaningless in the future.

I've answered the rest of @longwave's feedback on the MR - but back to needs review. I think we need to add a nightwatch section to the MR.

longwave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record updates, +Needs followup

Let's update the CR for Nightwatch and also add a followup to investigate Selenium switches, otherwise this is ready to go.

alexpott’s picture

Issue summary: View changes

Added testing performance follow-up as requested.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record updates, -Needs followup

I've tweaked the way W3C mode is set in nightwatch to negate the need for an extra environment. I realised that the selenium environment was missing the merge of chrome args etc... and changing how this is set up seemed best.

I've also update the Cr to reflect the test configuration changes someone would need to make to use W3C compliant browser testing.

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Alright, let's ship this - tests are green, and the test and configuration changes are the minimum required to enable W3C mode. This then unlocks some future improvements including hopefully being able to upgrade Nightwatch to a more recent version.

  • catch committed 9eb4cb9d on 11.x
    Issue #3421202 by alexpott, longwave, andypost, justafish: Enable W3C-...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

If this does indeed make functional js tests a lot slower, it may break the performance tests dashboard. I've opened #3463351: Consolidate Umami performance tests which should cover that.

Alongside that, I also opened #3463456: Consolidate ckeditor5's FunctionalJavascript tests for core's other longest running functional js tests.

I think we should open a follow-up to revisit concurrency once those two issues are in, since they may be enough to lower it again, I'll open it postponed now.

I am assuming that we don't want to try to backport this to 10.4.x, but if we do, please re-open with a backport MR.

edit: #3463286: Fix selenium performance/stampede issues in gitlab config and BrowserTestBase covers the concurrency follow-up.

alexpott’s picture

I think we do want to get this in 10.4.x and maybe even get the test base class changes into 10.3.x and 11.x so that projects can move to W3C driver testing early. I'll open when I get round to making the MR for 10.4.x

catch’s picture

Status: Fixed » Patch (to be ported)

Performance test job is broken since this went in #3463534: Performance test gitlab job is broken - revert to use chromedriver.

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Patch (to be ported) » Needs review

Created two MRs - one for 11.0.x and one for 10.4.x (and 10.3.x) so we can backport this so that projects can start the process of testing on modern browsers...

andypost’s picture

The only question is deprecation message, let's update it to "deprecated in 10.0.4 and removed in 12.0.0"

alexpott’s picture

@andypost - ah the best thing to do here is to remove the deprecation... makes core/tests/Drupal/Tests/Core/Test/PhpUnitCliTest.php pass on 10.x without modification which is nice.

longwave’s picture

Status: Needs review » Needs work

Added some comments about being slightly more conservative in the 11.0/10.4 backports. Should this also go back to 10.3 to keep in sync?

alexpott’s picture

It'd be great if this went into 10.3 too.

alexpott’s picture

Status: Needs work » Needs review

Great review point @longwave - I've addressed them on both 10.4.x and 11.0.x branches. The 10.4.x also works on 10.3.x

longwave’s picture

Status: Needs review » Needs work

Various tests are broken.

alexpott’s picture

Status: Needs work » Needs review

Superfluous dump() doh!

longwave’s picture

Status: Needs review » Needs work

#3463286: Fix selenium performance/stampede issues in gitlab config and BrowserTestBase landed so that change needs to be incorporated here now.

Unit tests also failed on 10.4.x in WebAssertTest.

wim leers’s picture

What's the status of this? #47 landed, but then this issue was reopened, without a revert. The two change records are still draft.

EDIT: ah I guess #3463534: Performance test gitlab job is broken - revert to use chromedriver is the partial revert?

Can contrib follow core's example/lead? Should it?

catch’s picture

@Wim This was re-opened for backport, not due to regressions.

However #3463286: Fix selenium performance/stampede issues in gitlab config and BrowserTestBase landed in 11.x, and needs to be incorporated into the backport here to avoid serious performance/instability issues on pipelines. The gitlab YAML files have diverged quite a lot between branches so it is a real backport not just a cherry-pick unfortunately.

Contrib w3c testing is happening in #3463894: Update templates so 11.0 is the default/current branch.

chr.fritsch made their first commit to this issue’s fork.

andypost’s picture

Version: 10.3.x-dev » 10.5.x-dev

It looks like a blocker for deprecation #3462682: Deprecate non-W3C compliant testing

PS: not clear state of w3c testing in contrib as it reported blocked too #3462681: Add W3C compliant JS testing

longwave’s picture

Version: 10.5.x-dev » 11.x-dev
Status: Needs work » Fixed

We never finished the backport, I think it's too late to bother with that now. Let's just keep both sets of tests in 11 and then remove non-w3c testing in 12.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

quietone’s picture

Version: 11.x-dev » 11.1.x-dev

This was released with 11.1

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.