Problem/Motivation

Similar to Functional(Javascript)Tests, Nightwatch test have an custom API call for enabling modules (.drupalInstallModule()).

When not specifically testing the enabling/disabling of modules we should use that instead of clicking around in /admin/modules

Steps to reproduce

Proposed resolution

- Go through all Nightwatch tests, check if they are enabling/disabling modules by clicking around.
- If they do and the test is not specifically testing the enabling/disabling of modules, replace the clicking with .drupalInstallModule().

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#24 3413665-nr-bot.txt1.7 KBneeds-review-queue-bot

Issue fork drupal-3413665

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

Spokje created an issue. See original summary.

spokje’s picture

Issue summary: View changes

spokje’s picture

Assigned: spokje » Unassigned
Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change seems good.

Searched for .drupalRelativeURL('/admin/modules') and saw the 2 instances were updated.

Hopefully this helps move nightwatch tests to be more useable.

longwave’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Good idea, we have the API so let's use it! Backported to 10.2.x to keep tests in sync.

Committed and pushed a2f51b88d5 to 11.x and 977e680afb to 10.2.x. Thanks!

  • longwave committed 977e680a on 10.2.x
    Issue #3413665 by Spokje: Enable modules through Nightwatch API when not...

  • longwave committed a2f51b88 on 11.x
    Issue #3413665 by Spokje: Enable modules through Nightwatch API when not...

  • alexpott committed 3d2f1509 on 10.2.x
    Revert "Issue #3413665 by Spokje: Enable modules through Nightwatch API...

  • alexpott committed 34258c08 on 11.x
    Revert "Issue #3413665 by Spokje: Enable modules through Nightwatch API...

andypost credited alexpott.

andypost’s picture

Status: Fixed » Needs work

reverted

alexpott’s picture

Unfortunately this resulted in a flood of Nightwatch errors in modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5CodeSyntaxTest.js - I could not get this to pass locally without reverting this.

I suspect this is due to async and perform doing a retry and things getting very broken.

longwave changed the visibility of the branch 3413665-enable-modules-through to active.

longwave’s picture

Status: Needs work » Needs review

Modified drupalInstallModule() so it can install more than one module at a time.

longwave’s picture

I don't even think the test needs Field UI, we could just remove that, but we should probably fix the multiple-install issue while we are here?

alexpott’s picture

Yeah swapping the order of the modules being installed in before(browser) { completely breaks the modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5CodeSyntaxTest.js locally.

Also what is super fun is that core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js does not fail :) It tries to enable 2 modules… and again because the test does not actually need field ui it is fine. But

    // Set fixed (desktop-ish) size to ensure a maximum viewport.
    browser.resizeWindow(1920, 1080);

somehow makes it pass.

We need to do here is add a test for enabling multiple modules via something like

    browser
      .drupalInstall({ installProfile: 'minimal' })
      .drupalInstallModule('ckeditor5', true)
      .drupalInstallModule('field_ui');

in the before section and then go to the module screen and see if they are installed. Because drupalInstallModule should be chainable.

longwave’s picture

Seems to be because drupalInstallModule() does not wait for anything. If you remove this:

  .perform(() => {
    if (typeof callback === 'function') {
      callback.call(self);
    }
  })

then field_ui is installed *after* the test runs!

If I add .waitForElementPresent('body') before or after .perform() then it seems to pass consistently.

spokje’s picture

Fun stuff, I've been working with Nightwatch a bit lately, and honestly I don't see an added value for it in the Drupal sphere.

It's great when you don't have FunctionalJavascriptTest, but we _do_ have that.

For me it's buggy, and not well documented nor maintained.

The only plus sides of it I can think of is that it works in JavaScript and we have the a11y tests in there.
Downsides of those are that we don't have a vast user/contributor base of JavaScript savy people and most of the a11y tests in Nightwatch are commented out, waiting for someone to fix them. Not much traction on that, or I am looking in the wrong issues.

I seriously think we might want to consider if we want to put any more effort into it, any version higher then we're using now locks up when using multiple workers. Not something I look forward to solve...

It might be time to consider if we want to convert every Nightwatch test to a FunctionalJavascriptTest and move away from it.

Disclaimer: n=1, I am not a JavaScript developer, etc. etc.

smustgrave’s picture

To add to that, think why a lot of people probably don't contribute it's very difficult to get running locally.

spokje’s picture

Back to the MR:

I think we're missing converting core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js to the new installing-multiple-modules-in-one-go?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.7 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

catch’s picture

Fun stuff, I've been working with Nightwatch a bit lately, and honestly I don't see an added value for it in the Drupal sphere.

I am wondering when the last time was we added any test coverage vs. dealing with nightwatch failures. Should probably open a new issue to discuss whether we want to think about removing it.

spokje’s picture

I am wondering when the last time was we added any test coverage vs. dealing with nightwatch failures.

I know @WimLeers uses Nightwatch frequently both in core ckeditor5 and some of "his" contrib modules.

Besides that: Not much traction I can see.

Should probably open a new issue to discuss whether we want to think about removing it.

Even when the outcome is "We need it, don't remove it!", we at the very least have an indication that it's used (and loved) and maybe even the amount of users/lovers.

I really believe Nightwatch is great if you don't have any FE-testing in place, but IMHO it's on all fronts outclassed by our FunctionalJavascript test suite.

TLDR; O yes, please open such an issue.

alexpott’s picture

Re removing Nightwatch - it is doing somethings our PHP based JS testing framework cannot do.

  • usability testing use Axe - see core/tests/Drupal/Nightwatch/Tests/a11yTestDefault.js
  • JS unit testing - see core/modules/ckeditor5/tests/src/Nightwatch/Tests/drupalHtmlBuilderTest.js
spokje’s picture

Thanks @alexpott.

I'll happily work around it :)

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

murz’s picture

In the scope of the Test Helpers module, I implemented a Nightwatch command thInstallModules() that installs one or even several modules at once on the Drupal side without any click in the browser - it works 1000 times quicker than clicking in the browser (log in as admin, go to modules, etc.), cus does just one GET request in the background and that's it. Here it is: https://git.drupalcode.org/project/test_helpers/-/blob/1.5.x/tests/modul...

Via the same way, we can optimize any other popular actions for tests, so I already implemented more Nightwatch commands too:
thDrupalFetchURL(), thInstallModules(array) thSetConfig(), thLogout(), etc.

You can look at the usage examples in the Commercetools module's Nightwatch tests.

So, maybe let's implement the same functions, but in Drupal Core?

murz’s picture

Another way to speed up installing and enabling modules is creating test profiles, where just list all required modules. Also, we can deploy the required configuration from this test profile. And even more, using the install hook, we can add more backend PHP magic there, that is needed for tests.

See https://git.drupalcode.org/project/commercetools/-/blob/2.0.x/modules/co...
and https://git.drupalcode.org/project/commercetools/-/blob/2.0.x/tests/prof... as examples.

murz’s picture

By the way, here #3464642: [PP-1] Provide PHP helpers for Nightwatch tests to speed up routine operations is a more general issue about such Nightwatch helpers.

catch’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.