Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/newrelic-experimental/nr-scripted-browser-framework
A scripted browser framework that allows you to author and maintain multiple steps of a journey.
https://github.com/newrelic-experimental/nr-scripted-browser-framework
emeafet nrlabs
Last synced: about 2 months ago
JSON representation
A scripted browser framework that allows you to author and maintain multiple steps of a journey.
- Host: GitHub
- URL: https://github.com/newrelic-experimental/nr-scripted-browser-framework
- Owner: newrelic-experimental
- License: apache-2.0
- Created: 2023-01-09T18:55:53.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-16T08:39:50.000Z (5 months ago)
- Last Synced: 2024-08-16T09:55:45.306Z (5 months ago)
- Topics: emeafet, nrlabs
- Language: JavaScript
- Homepage:
- Size: 76.2 KB
- Stars: 1
- Watchers: 8
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# New Relic Scripted Browser Framework
This scripted browser framework boilerplate allows you to author multiple steps of a journey and record the timings and better manage the effect of failures of each step. Each set of steps can be grouped into re-usable categories. Steps can be set to fail the script immediately or defer failure until the script completes. This allows scripted browser journeys to continue even if failures are detected, ensureing as much of your journey is tested as possible before failures are reported.Steps can be:
- 'hard' steps that stop the script when they fail. If one of thes steps fails the journey ceases.
- 'soft' steps that will fail the journey but the failure is deferred to allow other steps to complete. Failed soft steps will be listed when the script ends.
- 'optional' steps which are allowed to fail without failing the script. They can be used for optional steps such as hiding adverts or cookie banners.## Simulator
This project includes the [simulator](simulator/simulator.js) borrowed from the [Synthetics Workspace](https://github.com/tanben/generator-nrsynthetics-workspace) project.This allows you to run the journey locally.
To install the dependencies for local testing make sure the chromedriver version in package.json matches your currently installed version of chrome (you will almost c ertianly have to bump it up!) and then run npm install:
```
npm install
```To run the example script:
```
cd journeys
node example.js
```## Usage
The intention of the boilerplate framework is to simplify the creation of multi step journeys, providing a comprehensive logging framework that shows how long steps take to complete and identifies locations of failure. Journeys are made up of individual steps which are then optionally grouped into categories for tidiness. You wrap each step in a timedStep() wrapper function which runs the step and logs the timing information for that step. It also deals with failure conditions.### Journey Category
A category runs multiple steps to achieve a purpose. For instance a category might be "Window setup" or "Login" or "Search for product". You can chain categories together. This allows you to build a re-usable set of categories.Each category is a function, follow the format by setting the `category` and `description` variables. Then add the steps as required
```
const JRN_YourCategoryName = async ()=> {
const category="Category name here"
const description="Some explanation of what this category does here"startCategory(category,description)
//Add your steps here, e.g.:
//step 1
await timedStep(STEP_TYPE.HARD, "Open Start URL", category, async () => {
return $webDriver.get("https://newrelic.com");
});
//step 2
await timedStep(STEP_TYPE.HARD, "Set Window Size", category, async () => {
return $webDriver
.manage()
.window()
.setRect({ x: 0, y: 0, width: 2328, height: 1667 });
});
//step 3... etc
}
```### Steps
Each step should await a call to `timedStep()`.The `timedStep()` function takes the following parameters:
1: Step type, one of: `STEP_TYPE.HARD`, `STEP_TYPE.SOFT`, `STEP_TYPE.OPTIONAL`
2: Title/description of the step
3: Category (use the variable as defined in the category setup)
4: Wrapped selenium promise function e.g. `()=> { return $webDriver.get(startURL); }`
See example.js for examples.### Execution Flow
The script starts by checking for browser capabilities then initiating a promise chain. Simply add your journey set categories in turn, following the pattern laid out.Once the journey steps have all been run the script ends, logging our any final data and error summary.
### Selenium IDE Formatter conversion
You may have steps generated with the selenium ide formatter [extension](https://chrome.google.com/webstore/detail/synthetics-formatter-for/agedeoibceidbaeajbehgiejlekicbfd). If so then the steps can be converted into the boilerplate format manually.