UNPKG

@openfin/automation-cli

Version:

CLI for running automation tests within the OpenFin ecosystem

302 lines (226 loc) • 11.1 kB
# Automation CLI This package contains a command line application that can be used to run automation tests within the OpenFin ecosystem. The CLI is run by providing the location of the OpenFin application manifest and a set of test files. During the execution of the CLI it will retrieve the required OpenFin runtimes as well as the correct version of the chromedriver to use with the runtime. The CLI can also run in offline more where the OpenFin runtimes and chromedriver are already expected to be available locally. An `offline-versions.json` file is also expected to exist in the storage folder to define the real version numbers for labelled runtimes (see example below) Currently Jasmine, Mocha and Jest are provided as in-built test runners. When the test frameworks run they will automatically determine if your tests are written with JavaScript and TypeScript and behave accordingly. The CLI process will exit with code 1 if any of the tests failed. ## Installation Run `npm i @openfin/automation-cli`. ## Command Line Options ```shell šŸš€ OpenFin Automation v1.2.0 Usage: of-automation [options] <manifestUrl <string>> <testGlobs <string>> Run Automation Tests using Chrome Driver with an OpenFin UI Arguments: manifestUrl <string> The url of the manifest to load, can be http|https|file|none testGlobs <string> Globs pointing to the tests to run, semi-colon separate for additional folders Options: -V, --version output the version number --logLevel <level> The log level for the webdriver (choices: "debug", "silent", default: "silent") --devToolsPort <number> The port to run the dev tools on (default: 9090) --chromeDriverPort <number> The port to run the chromedriver on (default: 4444) --storageFolder <path> The path to store any downloaded or offline data (default: "./storage/") --offline In offline mode no resources are retrieved, they are expected to be in the storageFolder --testTimeout <number> The timeout in seconds for running tests (default: 120) --testFailCount <number> Will exit the tests after given number of failures, 0 will allow all failures (default: 0) --defaultRuntimeVersion <string> The OpenFin runtime version to use if not specified in manifest (default: "stable") --framework <mocha> The test framework to run the tests with (choices: "mocha", "jasmine", "jest", default: "mocha") --reporter <file.json> Additional runner config to be passed to frameworks --driver <node> The webdriver used to access the runtime (choices: "node", "selenium", default: "node") --workspace <version> The workspace version to use e.g. 9.2.5 for the DOS settings (default: "stable") --notifications <version> The notifications version to use e.g. 1.20.2 for the DOS settings (default: "stable") --chromeDriverOverride <version> Override the version of chromedriver e.g. 113 --closeRuntime <mode> When to close OpenFin runtimes in the workflow (choices: "never", "start", "end", "both", default: "both") --dos <file.json> Provide a custom DOS file to use when running tests --screenshotFolder <path> The path to store any screen shots that have been taken (default: "./reports/screenshots/") --verbosity <mode> What to display from the runner output (choices: "all", "none", "results", default: "all") --hooks <file> A file which contains global setup and teardown hooks (default: "./automation-hooks.{js,ts}") -h, --help display help for command ``` ## Helper packages Any tests that you write can make use of two helper packages [@openfin/automation-helpers](https://www.npmjs.com/package/@openfin/automation-helpers) and [@openfin/automation-native](https://www.npmjs.com/package/@openfin/automation-native) which provide features to aid in interacting with OpenFin. ## Example tests There are JavaScript/TypeScript examples in the [Workspace Starter repo](https://github.com/built-on-openfin/workspace-starter/tree/main/how-to/automation-testing/README.md) There are .NET examples in the [C# Starter repo](https://github.com/built-on-openfin/csharp-starter/tree/main/how-to/automation-testing/README.md) ## CI Environments The CLI can be used to run tests in a headless CI environment such as GitHub Actions, it requires a `windows` platform to be executed on. ## Reporter config To provide an additional reporter output for a test framework you can specify a reporter config file e.g. `--reporter mocha.reporter.json`. You must install the necessary npm package in the node_modules where you are running the tests from. Some examples for each framework are. ### Mocha ```shell npm install mochawesome ``` ```json { "reporter": "mochawesome", "options": { "reportDir": "./reports/mocha/", "reportFilename": "report.html", "html": true, "json": false } } ``` ### Jasmine ```shell npm install jasmine-pretty-html-reporter ``` ```json { "reporter": "Reporter", "module": "jasmine-pretty-html-reporter", "options": { "path": "./reports/jasmine" } } ``` ### Jest ```shell npm install jest-html-reporters ``` ```json { "reporter": "jest-html-reporters", "options": { "publicPath": "./reports/jest", "filename": "report.html" } } ``` ## Execution example Assuming your manifest is already being served at `http://localhost:8080/manifest.fin.json` and your files are stored in `./tests`. ```shell of-automation http://localhost:8080/manifest.fin.json ./tests/**/*.spec.js ``` You should see a summary similar to that shown below: <details> <summary>CLI Output</summary> ```shell šŸš€ OpenFin Automation v1.2.0 āš™ļø Manifest Url http://localhost:8080/manifest.fin.json āš™ļø Test Glob Path ./tests/**/*.spec.js āš™ļø Log Level silent āš™ļø Dev Tools Port 9090 āš™ļø Chrome Driver Port 4444 āš™ļø Test Framework mocha āš™ļø Test Timeout 120 āš™ļø Default Runtime Version stable āš™ļø Storage Folder ./storage/ āš™ļø Offline false _______________________________________________________ āž”ļø Loading manifest http://localhost:8080/manifest.fin.json āœ… Manifest loaded _______________________________________________________ āž”ļø Resolving OpenFin runtime version Version 32.114.76.20 āœ… Final Runtime version 32.114.76.20 _______________________________________________________ āž”ļø Get Chrome Driver Version 114 āœ… Chrome Driver already exists .\storage\chromedriver\114\chromedriver.exe _______________________________________________________ āž”ļø Creating temp profile directory .\tmp\\openfin-test-1651745687443 āœ… Directory created _______________________________________________________ āž”ļø Cleaning up OpenFin instances āœ… Cleanup instances complete _______________________________________________________ āž”ļø Querying Desktop Owner Settings āœ… Writing Temporary Desktop Owner Settings .\tmp\\openfin-dos-1651745687531.json āœ… Setting Desktop Owner Setting file:\\\.\tmp\\openfin-dos-1651745687531.json āœ… Current Desktop Owner Setting http://localhost:5081/api/dos/openfin _______________________________________________________ āž”ļø Running OpenFin C:\Users\marty\AppData\Local\OpenFin\OpenFinRVM.exe āœ… Args --config=http://localhost:8080/manifest.fin.json,--working-dir="C:\Users\user\AppData\Local\OpenFin",--runtime-arguments="--remote-debugging-port=9090" āœ… OpenFinRVM Process 22084 _______________________________________________________ āž”ļø Starting Chrome Driver .\storage\chromedriver\96\chromedriver.exe port 4444 āœ… Chrome Driver Process 20880 āœ… Waiting for Chrome Driver to be ready Starting ChromeDriver 114.0.5615.49 (bd2a7bcb881c11e8cfe3078709382934e3916914-refs/branch-heads/5615@{#936}) on port 4444 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully. _______________________________________________________ āž”ļø Running Tests using Mocha Version 10.2.0 Register with Home āœ” The title should be set āœ” The runtime version should be set āœ” Can open the home window (7263ms) āœ” Can search in the home window (1392ms) āœ” Can select entries in the home window by index (2077ms) āœ” Can select entries in the home window by id (2045ms) āœ” Can open the home window filters āœ” Can get the filter ids āœ” Set a filter by index āœ” Set a filter by id āœ” Can close the home window filters (3035ms) āœ” Can check selected entry content āœ” Can open an entry in the home window (1036ms) āœ” Can clear entries in the home window (1670ms) āœ” Can close the home window (640ms) āœ” Can perform operation in the interop window (2069ms) 16 passing (21s) _______________________________________________________ āž”ļø Cleaning Up āœ… Closing Chrome Driver āœ… Restoring DOS āœ… Setting Desktop Owner Setting http://localhost:5081/api/dos/openfin āœ… Removing temporary DOS Settings āœ… Cleaning up OpenFin instances āœ… Cleanup instances complete āœ… Removing temp data directory .\tmp\\openfin-test-1651745687443 _______________________________________________________ šŸ˜€ Successfully ran the tests ``` </details> ### offline-versions.json Example file for `offline-versions.json` required if running in offline mode. ```json { "stable": "32.114.76.10", "release-candidate": "32.114.76.10", "beta": "32.114.76.10", "canary": "34.116.78.17", "stable-v32": "32.114.76.10", "stable-v31": "31.112.75.7", "stable-v30": "30.110.74.16", "stable-v29": "29.108.73.19", "stable-v28": "28.106.72.17", "stable-v27": "27.104.71.29", "stable-v26": "26.102.71.10", "stable-v25": "25.100.70.4", "stable-v24": "24.98.69.10", "stable-v23": "23.96.68.7", "stable-v22": "22.94.67.8", "stable-v21": "21.93.65.4", "stable-v20": "20.91.64.4", "stable-v19": "19.89.61.8", "stable-v18": "18.87.57.42", "stable-v17": "17.85.55.40", "stable-v16": "16.83.53.27", "stable-v15": "15.80.50.34", "stable-v14": "14.78.48.16", "stable-v13": "13.76.45.15", "stable-v12": "12.69.43.22", "stable-v11": "11.69.42.29", "stable-v10": "10.66.41.18", "stable-v9": "9.61.38.43", "stable-v8": "8.56.30.71", "stable-v7": "7.53.23.23", "stable-v6": "6.49.21.24" } ``` ## OpenFin Debugging For more information on debugging in OpenFin see [https://developers.openfin.co/of-docs/docs/debugging](https://developers.openfin.co/of-docs/docs/debugging) ## Related Packages - [@openfin/automation-helpers](https://www.npmjs.com/package/@openfin/automation-helpers) - [@openfin/automation-native](https://www.npmjs.com/package/@openfin/automation-native)