diff --git a/README.md b/README.md index 4e0fb95..f21ee3c 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,23 @@ WDIO tests against an environment, github workflow or locally. > DO NOT DEPLOY THESE TESTS TO AN CDP ENVIRONMENT AT THE MOMENT! > Contains non-ephemeral flows. -- [Related Tests](#related-tests) -- [Local](#local) +- [Local Development](#local-development) - [Requirements](#requirements) - [Node.js](#nodejs) - [Setup](#setup) - - [Running local tests](#running-local-tests) - - [Debugging local tests](#debugging-local-tests) + - [Running](#running) + - [Local](#local) + - [Local with debug](#local-with-debug) + - [GitHub](#github) + - [Debugging](#debugging) + - [WebdriverIO Plugin](#webdriverio-plugin) + - [Setup in IntelliJ/Webstorm](#setup-in-intellijwebstorm) + - [Debug environment variable](#debug-environment-variable) + - [WebdriverIO debug command](#webdriverio-debug-command) - [Production](#production) - - [Debugging tests](#debugging-tests) + - [Running the tests](#running-the-tests) +- [Requirements of CDP Environment Tests](#requirements-of-cdp-environment-tests) +- [Running on GitHub](#running-on-github) - [Licence](#licence) - [About the licence](#about-the-licence) @@ -43,35 +51,106 @@ Install application dependencies: npm install ``` -### Running local tests +### Running -1. Edit [wdio.local.conf.js](wdio.local.conf.js) and set `baseUrl` to your service under test. +#### Local -1. Start application you are testing on the url specified in `baseUrl` +To run against portal running locally on `http://localhost:3000`: ```bash npm run test:local ``` -### Debugging local tests +#### Local with debug + +To debug a local version of the portal running on `http://localhost:3000`: ```bash npm run test:local:debug ``` +#### GitHub + +To mimic the GitHub workflow locally. Start up the docker compose: + +```bash +docker compose up --wait-timeout 300 -d --quiet-pull --force-recreate +``` + +Then run the following command: + +```bash +npm run test:github +``` + +### Debugging + +#### WebdriverIO Plugin + +In IntelliJ and Webstorm use the [WebdriverIO Plugin](https://plugins.jetbrains.com/plugin/16147-webdriverio). This +provides full run, debug and breakpoint capabilities in your WebDriverIO tests. + +#### Setup in IntelliJ/Webstorm + +1. Add a `WebdriverIO` configuration template +1. `Run -> Edit configurations` +1. `Edit configuration templates -> WebdriverIO` +1. Add the following values to the `WebdriverIO` configuration template: + ![WebDriverIO configuration template](docs/webdriverio-plugin/webdriverio-configuration-template.png) +1. Add an `All tests configuration` +1. `Run -> Edit configurations` +1. `Add new configuration -> WebdriverIO` +1. `Add the values shown in the following image`: + ![WebDriverIO all tests configuration](docs/webdriverio-plugin/all-tests.png) +1. You can now run and debug your tests in IntelliJ/Webstorm: + ![WebDriverIO with test controls](docs/webdriverio-plugin/with-test-controls.png) + +> [!NOTE] +> If you wish to run against cdp-local-environment, you will need to set the `Wdio config file` to point at `wdio. +docker.conf.js` in the `WebdriverIO` configuration template: + +#### Debug environment variable + +You can also set the following env: + +> This provides debug config in the [wdio.local.conf.js](./wdio.local.conf.js) file + +```bash +DEBUG=true +``` + +Or use the npm script: + +> This script automatically sets the debug environment variable + +```bash +npm run test-local:debug +``` + +#### WebdriverIO debug command + +Use the following command in code: + +```javascript +browser.debug() +``` + ## Production ### Running the tests -Tests are run from the CDP-Portal under the Test Suites section. Before any changes can be run, a new docker image must be built, this will happen automatically when a pull request is merged into the `main` branch. -You can check the progress of the build under the actions section of this repository. Builds typically take around 1-2 minutes. +Tests are run from the CDP-Portal under the Test Suites section. Before any changes can be run, a new docker image must +be built, this will happen automatically when a pull request is merged into the `main` branch. +You can check the progress of the build under the actions section of this repository. Builds typically take around 1-2 +minutes. The results of the test run are made available in the portal. ## Requirements of CDP Environment Tests 1. Your service builds as a docker container using the `.github/workflows/publish.yml` - The workflow tags the docker images allowing the CDP Portal to identify how the container should be run on the platform. + The workflow tags the docker images allowing the CDP Portal to identify how the container should be run on the + platform. It also ensures its published to the correct docker repository. 2. The Dockerfile's entrypoint script should return exit code of 0 if the test suite passes or 1/>0 if it fails @@ -81,8 +160,10 @@ The results of the test run are made available in the portal. ## Running on GitHub Alternatively you can run the test suite as a GitHub workflow. -Test runs on GitHub are not able to connect to the CDP Test environments. Instead, they run the tests agains a version of the services running in docker. -A docker compose `compose.yml` is included as a starting point, which includes the databases (mongodb, redis) and infrastructure (localstack) pre-setup. +Test runs on GitHub are not able to connect to the CDP Test environments. Instead, they run the tests agains a version +of the services running in docker. +A docker compose `compose.yml` is included as a starting point, which includes the databases (mongodb, redis) and +infrastructure (localstack) pre-setup. Steps: @@ -93,7 +174,8 @@ Steps: By default, the provided workflow will run when triggered manually from GitHub or when triggered by another workflow. -If you want to use the repository exclusively for running docker composed based test suites consider displaying the publish.yml workflow. +If you want to use the repository exclusively for running docker composed based test suites consider displaying the +publish.yml workflow. ## Licence diff --git a/compose.yml b/compose.yml index d175fa3..c7c93c5 100644 --- a/compose.yml +++ b/compose.yml @@ -23,10 +23,7 @@ services: # Headless browser, used by the test suite to actually run the tests against the # containers. selenium-chrome: - - # Run locally on a mac - image: selenium/standalone-chrome:119.0 -# image: selenium/standalone-chrome:latest + image: selenium/standalone-chrome:123.0 ports: - 4444:4444 environment: diff --git a/docs/webdriverio-plugin/all-tests.png b/docs/webdriverio-plugin/all-tests.png new file mode 100644 index 0000000..2786633 Binary files /dev/null and b/docs/webdriverio-plugin/all-tests.png differ diff --git a/docs/webdriverio-plugin/webdriverio-configuration-template.png b/docs/webdriverio-plugin/webdriverio-configuration-template.png new file mode 100644 index 0000000..9cf4d6e Binary files /dev/null and b/docs/webdriverio-plugin/webdriverio-configuration-template.png differ diff --git a/docs/webdriverio-plugin/with-test-controls.png b/docs/webdriverio-plugin/with-test-controls.png new file mode 100644 index 0000000..f100a06 Binary files /dev/null and b/docs/webdriverio-plugin/with-test-controls.png differ diff --git a/package.json b/package.json index c4e0b57..d2caebe 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,8 @@ "scripts": { "clean": "rm -rf allure-results && rm -rf allure-report", "test": "npm run clean && wdio run wdio.conf.js", - "test:local": "npm run clean && BASE_URL=\"http://localhost:3000\" wdio run wdio.local.conf.js", - "test:local:debug": "npm run clean && DEBUG=true BASE_URL=\"http://localhost:3000\" wdio run wdio.local.conf.js", - "test:docker": "npm run clean && BASE_URL=\"http://cdp.127.0.0.1.sslip.io:3333\" wdio run wdio.local.conf.js", + "test:local": "npm run clean && wdio run wdio.local.conf.js", + "test:local:debug": "npm run clean && DEBUG=true wdio run wdio.local.conf.js", "test:github": "npm run clean && wdio run wdio.github.conf.js", "format": "prettier --write 'test/**/*.js' '**/*.{cjs,js,md,json,config.js}'", "format:check": "prettier --check 'test/**/*.js' '**/*.{js,md,json,config.js}'", diff --git a/wdio.local.conf.js b/wdio.local.conf.js index 249688f..91191b8 100644 --- a/wdio.local.conf.js +++ b/wdio.local.conf.js @@ -1,7 +1,6 @@ import allure from 'allure-commandline' const debug = process.env.DEBUG -const baseUrl = process.env.BASE_URL const oneMinute = 60 * 1000 const oneHour = 60 * 60 * 1000 @@ -23,7 +22,7 @@ export const config = { // with `/`, the base url gets prepended, not including the path portion of your baseUrl. // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url // gets prepended directly. - baseUrl, + baseUrl: 'http://localhost:3000', // Tests to run specs: ['./test/specs/**/*.js'],