• Development

    Using Data Providers in PHPUnit Tests

    This is the before code, where a single test is run, and each scenario I’m testing could be influenced by the previous scenario (not a good thing, unless that was my goal, which it was not).

    This is the after code, where three tests are run. Unfortunately this takes 3x longer to execute. The upside is that each scenario cannot affect the others and it’s perhaps more readable and easier to add additional scenarios.

     

  • Development

    Simple OAuth Token Handling with Cypress

    Here’s a quick (and dirty?) way to handle requesting an access token and using it in a subsequent request.

    You should probably pull the client_secret from an environment variable (not shown below).

    commands.js

     

    some-tests.spec.js

     

  • Development

    NightwatchJS Command to Repeat a Keystroke

    Here’s a simple custom command that lets you repeat a specific key (single or combo) N number of times.

    In the Drupal world you want to place this in your “Commands” directory (as defined in DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY in web/core/.env).

    You’d want to change “sitename” to be your site’s name (so it feels namespaced).

    /tests/Nightwatch/Commands/sitenameRepeatKeystroke.js

     

    Using this in /tests/Nightwatch/Tests/misc.js with a 1000ms pause between each keystroke: