Provide PHP helpers for Nightwatch tests to speed up routine operations

Created on 30 July 2024, 5 months ago

Problem/Motivation

Now Drupal provides some commands for Nightwatch tests like drupalInstallModule(), drupalCreateUser(), etc.

But those commands do actions pretty slowly because they make a lot of clicks in the Drupal admin panel!

For example, the drupalInstallModule() just to install a single module, does a lot of actions: logs in as admin, opens the modules form, submits, confirms, logs out.

And these commands execute multiple times each Nightwatch test, spending a lot of time in the pipeline!

Steps to reproduce

1. Execute a Nigthwatch test like this:

  browser.drupalInstall()
    .drupalInstallModule('node')
    .drupalInstallModule('media')
    .drupalInstallModule('taxonomy')
    .drupalInstallModule('layout_builder')

2. Get tired of waiting for it to end.

Proposed resolution

The idea is to speed up these standard commands by providing a helper function on the PHP side, which will do the action instantly, using a single HTTP call, without any relogins and other permission checks.

So, for example, to install a module - just call something like /api-for-browertests/install-module/node+taxonomy+media and it will install them quickly as a single call, without any confirmations.

This will be not a security breach if we provide a separate module, available to install only for tests, and preinstall it using the Nightwatch installation profile.

What do you think about this idea?

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
JavascriptΒ  β†’

Last updated 4 days ago

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @murz
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    I implemented Drupal endpoints with helper actions for Drupal Functional tests in the module Test Helpers β†’ :

    • /test-helpers-functional/create-user: Creates a new user, with optionally
      adding permissions and log-in.
    • /test-helpers-functional/login/{name}: Performs a login for the given user.
    • /test-helpers-functional/set-envs: Installs and uninstalls one or several
      modules at once, optionally with dependencies.
    • /test-helpers-functional/get-env/{name}: Sets the environment variables on
      the Drupal side.
    • /test-helpers-functional/module-installer: Gets the environment variable
      value from the Drupal side.

    And corresponding Nightwatch commands:

    • thCreateUser(): Creates a new user, with optionally adding permissions and
      log-in.
    • thLogin(): Performs a login for the given user.
    • thInstallModules(): Installs one or several modules at once, optionally with
      dependencies.
    • thUninstallModules(): Uninstalls one or several modules at once.
    • thSetEnvs(): Sets the environment variables on the Drupal side.
    • thGetEnv(): Gets the environment variable value from the Drupal side.

    Those commands perform actions on the Drupal side, and work many times faster,
    than Drupal Core alternatives (drupalInstall(),
    drupalCreateUser(), etc).

    See the usage examples in the included self-tests in the directory
    tests/modules/test_helpers_functional/tests/src/Nightwatch/Tests.

    And the results with this approach are great! The 'before()` step with them can be executed 5-10 times faster! It depends on the number of actions with installing modules, creating users, logins, etc, but in my projects I see acceleration from 20-30 seconds to 3-8 seconds, that is amazing!

    So, please review the Test Helpers implementation, and if the approach is okay, I can port them to Drupal Core.

  • Status changed to Postponed about 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    In general I'm in favour of this approach but I would prefer it was done via console commands rather than via a browser. Pretty sure that can be done with custom steps

    I think we should postpone this on πŸ“Œ Consider dropping Nightwatch in favor of Functional Javascript tests Active as there's no point spending additional effort on it if we choose a different option

Production build 0.71.5 2024