Skip to content

Latest commit

 

History

History
132 lines (85 loc) · 6.54 KB

TESTING.md

File metadata and controls

132 lines (85 loc) · 6.54 KB

Testing

An overview of testing within CHT-CORE. Check out the Gruntfile for all the tests you can run.

Unit tests

They live in the tests directories of each app. Run them with grunt: grunt unit.

Integration tests

They are located in tests/integration. Run them with grunt: grunt e2e-integration

Continuous integration

We use Github Actions which runs grunt ci every time some new code is pushed to GitHub.

End to End Testing

Stack overview

Requirements

  1. Follow the guide DEVELOPMENT.md
  2. JDK installed for Selenium.
  3. Docker to run couchdb.

Local Run

grunt e2e installs and runs chromedriver, starts couchdb in docker, pushes the compiled app to couchdb, starts api, starts sentinel, and then runs protractor tests against your local environment.

WebdriverIO

Run locally

  1. Run npm ci
  2. Run grunt
  3. Run npm run wdio-local
  4. Run npx allure open to view the test reports

View the CI report

  1. Download the CI run artifact zip file
  2. Extract it anyhere
  3. From your cht-core directory, run npx allure open <path>/allure-report/.

GitHub Actions Protractor Run

The build process compiles our application. Then installs horticulturalist to run the app. This puts us closer to production. Executes grunt ci-e2e. Which then installs and runs chromedriver. Runs the protractor tests against the installed app version. Currently there are 3 jobs that execute in the supported node environments.

WebdriverIO GitHub Actions Run

The main difference now is that grunt ci-webdriver is executed now instead of ci-e2e. This executes the Webdriver IO tests.

Tips to write automated tests

Please read the style guide for automated tests which provides editorial guidelines for anyone creating new automated test cases for CHT-Core.

Debugging

Documented here are two ways to run individual tests and have your IDE break on the specific test.

When debugging it can be helpful to disable the headless browser mode so that you can see the browser window as the tests run. To do this, remove --headless from the tests/conf.js file for the Protractor tests and the tests/e2e/default/wdio.conf.js file for the WebdriverID tests.

WebdriverIO

To run just a single test file in WebdriverIO, update the specs config in the wdio.confi.js to refer to the desired test file.

IntelliJ Based

  1. In a terminal, run grunt
  2. In Intellij, open the package.json file
  3. Scroll to the scripts section and click the ▶ button next to wdio-local
  4. Select Debug 'wdio-local'

Protractor

Visual Studio Code

Setting up Vscode for e2e debugging.
  1. This assumes you have gone through the development setup guide.
  2. Copy the vscode launch.json and tasks.json files from this location.
  3. Paste those files into a directory called .vscode within your cht-core repo.
  4. Click the debug icon on the left tool bar.
  5. Select launch e2e.
  6. This will now run as if you ran the command grunt e2e-deploy and start the tests/scripts/e2e-servers script. Then launch protractor to debug the test(s).
Debugging a single test by using the "grep" feature.
  1. Open launch.json.
  2. Update the grep argument with the name of your test to the args array. Note: if you have defined specs or suites that do not include the spec.js. It will not find the test to run.
    EX: ["${workspaceRoot}/tests/conf.js","--grep=should show the correct privacy policy on login"]
  3. Click the debug icon on the left tool bar.
  4. Select launch e2e.

IntelliJ Based

  1. Click the run menu across the top.
  2. Click Edit Configurations.
  3. Click the plus to add a configuration.
  4. Select Protractor.
  5. Set the configuration file to the path of <cht-core-repo>/tests/conf.js.
  6. Set Node Interpreter is set to your node install.
  7. Set Protractor package is set to the <cht-core-repo>/node_modules/protractor.
  8. Optionally set the Protractor options to --capabilities.chromeOptions.args=start-maximized --jasmine.DEFAULT_TIMEOUT_INTERVAL=120000.
  9. Select the radio button for Test.
  10. Enter the path to the Test file Ex: <cht-core-repo>/tests/e2e/protractor/sms/send-message.js.
  11. Enter the test name. This is a bit of a chore. IntelliJ will automatically add the regex flags for begins(^) of line and end of line($). Protractor presents the name for matching as the Describe description followed by the It description. To run the pregnancy test for should have a title you would need to put this as your matcher. Send message : should have a title. An alternative would be to select Test File and run the entire file. You can add an x in front of it to disable the ones you do not need. EX: xit('should send a message').
  12. Click ok.
  13. Click the run configuration dropdown and select the protractor config.
  14. In a terminal run grunt e2e-deploy NOTE: This has to happen each time you run.
  15. Click debug button in IntelliJ.

Migration To Webdriver IO

Treat the migration as if you were writing a brand new e2e suite. Not everything we have in the protractor suite needs a 1 to 1 migration. The implicit waits seem to work better in wdio

Each spec file runs independently. There is no need to manage browser state between spec files.

Saving artifacts

GitHub actions will artifact all files in tests/logs. This is the directory any logs, results, images, etc... should save to if you want to review them if a build fails.

Test Architecture

Our GitHub actions spin up an ubuntu-22.04 machine. Installs software and then launches Couchdb and Horticulturalist in a docker container. This is needed to run our applications in the specific node versions we support while allowing our test code to run in versions of node it they support. This creates a paradigm to keep in mind when writing tests. Tests run on the ubuntu machine. Any test code that starts a server or runs an executable is running outside of the horti container. The ports are exposed for all our services and horti has access to the cht-core root via a volume. Horti can also talk to the host by getting the gateway of the docker network.

Glossary

wdio = WebdriverIo