Add End to End (e2e) testing

Created on 8 October 2024, 2 months ago

Problem/Motivation

We should provide a framework for testing the of the user interface as this is a user-centric product. The two most popular e2e frameworks are currently Cypress and Playwright. Cypress is more established and has been chosen by the Experience Builder team as part of their local development tooling.

Proposed resolution

Add Cypress to DDEV
Add Cypress to Gitlab

Remaining tasks

Add Cypress to DDEV
Add Cypress to Gitlab

User interface changes

N/A

API changes

N/A

Data model changes

N/A

✨ Feature request
Status

Active

Component

Infrastructure

Created by

πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

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

Merge Requests

Comments & Activities

  • Issue created by @thejimbirch
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Great choice, Cypress is a joy to use and very easy to get started with. I asked about testing last year in the Drupal Forum, and @jaypan kindly made me aware of Cypress β†’ and how it works. Together, we created Browser testing using Cypress β†’ .

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I support this, and it's definitely within my domain, so self-assigning.

    I experimented with this a bit and I found Cypress is very complicated to set up within DDEV if you want to see the tests actually executing in front of your eyes. It has to be able to talk to an X11 server running on the host machine, which has to be set up in a particular way and...sheesh. And that was just on a Mac. I don't know how onerous it would be on Windows.

    So I think we might want to set some realistic expectations here. Testing on Cypress in CI is probably within reach; adding it to our local development is also reachable but having the tests be visible while they run is tricky at best, and I'm not sure we'll be able to make it non-tricky.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    @phenaproxima not sure if that helps, but here is a snippet from our docker compose config, that we generate automatically with a composer plugin so that this works for each local dev project easily. These projects are not on DDEV, but in a docker compose project with Traefik as the frontend which routes the domain to the right container.

      cypress:
        image: 'cypress:latest'
        environment:
          - CYPRESS_baseUrl=https://eca.dev.jurgenhaas.de
          - CYPRESS_mailpitUrl=https://mailpit-eca.dev.jurgenhaas.de
          - PHP_CONTAINER=prjname-php-1
          - DISPLAY=:0
        network_mode: host
        working_dir: '/e2e'
        volumes:
          - /etc/timezone:/etc/timezone:ro
          - /etc/localtime:/etc/localtime:ro
          - /var/run/docker.sock:/var/run/docker.sock
          - /var/www/drupal/projects/prhname/tests/:/e2e
          - ~/.Xauthority:/root/.Xauthority:ro
        entrypoint: cypress open --project /e2e
        user: '1000:997'
    
  • Merge request !118Install tyler36/ddev-cypress β†’ (Merged) created by phenaproxima
  • Pipeline finished with Failed
    2 months ago
    Total: 707s
    #304361
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    @phenaproxima: As I wrote, it was easy to get Cypress up and running in Debian 12 (my OS) and see the tests run, following the simple steps in https://www.drupal.org/docs/develop/automated-testing/browser-testing-us... β†’ ... There were no extra set up.

    Perhaps it's because I am using Debian, and not Mac? I created https://github.com/tyler36/ddev-cypress/issues/43 to clarify this.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    I don't think Cypress is more established. One caveat to Cypress over Playwright is that you write less "normal" scripting in your tests and are tied to their plugin and locator system. Playwright has more straightforward locators built in, such as getByLabel, getByTitle, getByRole.

  • Pipeline finished with Success
    2 months ago
    Total: 614s
    #304500
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    Note: I don't mean to say "don't use it", I just wanted to at least share my opinion.

  • Pipeline finished with Success
    2 months ago
    Total: 590s
    #304560
  • Pipeline finished with Canceled
    2 months ago
    Total: 125s
    #304572
  • Pipeline finished with Canceled
    2 months ago
    Total: 256s
    #304578
  • Pipeline finished with Canceled
    2 months ago
    Total: 323s
    #304585
  • Pipeline finished with Failed
    2 months ago
    Total: 554s
    #304589
  • Pipeline finished with Failed
    2 months ago
    Total: 588s
    #304596
  • Pipeline finished with Failed
    2 months ago
    Total: 539s
    #304602
  • Pipeline finished with Failed
    2 months ago
    Total: 535s
    #304606
  • Pipeline finished with Failed
    2 months ago
    Total: 457s
    #304608
  • Pipeline finished with Failed
    2 months ago
    Total: 288s
    #304613
  • Pipeline finished with Failed
    2 months ago
    Total: 312s
    #304615
  • Pipeline finished with Canceled
    2 months ago
    Total: 579s
    #304620
  • Pipeline finished with Failed
    2 months ago
    Total: 541s
    #304622
  • Pipeline finished with Failed
    2 months ago
    Total: 218s
    #304624
  • Pipeline finished with Canceled
    2 months ago
    Total: 278s
    #304626
  • Pipeline finished with Canceled
    2 months ago
    Total: 62s
    #304628
  • Pipeline finished with Failed
    2 months ago
    Total: 446s
    #304632
  • Pipeline finished with Failed
    2 months ago
    Total: 326s
    #304635
  • Pipeline finished with Success
    2 months ago
    Total: 621s
    #304642
  • Pipeline finished with Success
    2 months ago
    Total: 618s
    #304649
  • Pipeline finished with Success
    2 months ago
    Total: 648s
    #304666
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Welp. That took some doing, but I have the basic infrastructure for Cypress set up:

    • It's now a dev dependency of the project. It gets automatically installed, if needed, when DDEV is started.
    • The DDEV web container now includes Chromium and Firefox. Regular Chrome turned out to be a big pain in the ass to install, so I figured Chromium was close enough.
    • I'm not using Cypress' Docker images because I was advised by members of the Experience Builder team that it doesn't work for our kinds of tests. They went down that road and it leads straight to hell.
    • Cypress config and support code will be kept at the top level of the project (for now, anyway); tests should go in the individual recipes, like drupal_cms_blog/tests/e2e/something.cy.js. There's only one test right now and it's pretty useless, but it at least proves that Cypress runs properly.
    • To run the Cypress tests in DDEV, it's ddev exec npx cypress run. You can also do it via the UI, as long as you've got an X11 server running on the host machine (such as XQuartz).
    • I also now have a GitLab CI job specifically to run Cypress tests.

    With this change, I think the decision is clear that we won't do end-to-end testing in PHP. At all. And it's just as well -- functional JS tests in PHP are flaky and tricky to write.

    So, you wanna do non-JS functional testing, or testing things at the Drupal API level? PHPUnit is perfectly fine; we have functional, unit, and kernel tests. But for end-to-end stuff, Cypress is the way.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Success
    2 months ago
    Total: 587s
    #304672
  • Pipeline finished with Skipped
    2 months ago
    #304676
  • Pipeline finished with Skipped
    2 months ago
    #304678
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    And, merged. Thanks, folks! This is one of those merge requests where every line was hard-won, but I think this will be worth it in the long run. The fact that we can collaborate with Experience Builder to build a great Drupal-specific framework for end-to-end testing in Cypress is just more evidence of how awesome the collaboration has been in the Starshot initiative. Onward!

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    This is great!

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

  • πŸ‡¨πŸ‡¦Canada Jaypan

    As a huge proponent of Cypress, I am very happy to see this. I, without any knowledge of this action, put forth a a presentation proposal for Drupalcon 2025 to present Cypress and Drupal, so if my presentation is accepted, this will be excellent information to also relay as part of the presentation.

  • πŸ‡¨πŸ‡¦Canada Jaypan

    I experimented with this a bit and I found Cypress is very complicated to set up within DDEV if you want to see the tests actually executing in front of your eyes. It has to be able to talk to an X11 server running on the host machine, which has to be set up in a particular way and...sheesh. And that was just on a Mac. I don't know how onerous it would be on Windows.

    I set up Cypress to use 'ddev drush' as the Drush command, and it has worked well.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    That sound great @jaypan, I very much hope your Drupalcon 2025 presentation proposal gets accepted.

    You could also consider making a "Using Cypress in Drupal" YouTube channel, going through the basic steps of setting Cypress up in Drupal with DDEV, and some short examples. I would certainly be watching the videos!

    I asked Is it possible to clarify the benefits? #43 of the DDEV-cypress plugin originally used in this MR. @tyler36 confirmed that MacOS and Windows can have a hard time with X11, as can be seen in the work-in-progress README from Clarify benefits and use cases in README.md #44 , which will probably soon be committed.

Production build 0.71.5 2024