@prestashopcorp/tests-framework
v4.1.0
Published
Base framework for new tests project
Downloads
874
Readme
Tests Base Framework
This repository has the role of a base framework to use on all tests projects.
Stack
- Playwright as a node library to automate interaction with Chromium, Firefox and WebKit.
Browser Helper
Used as a wrapper for Playwright functions, it aims to simplify launching browsers, context and opening new tabs using environment parameters.
Here are some functions wrapped on this helper :
getBrowserOptions
: Each browser type use different options to start, this function use the env varBROWSER
to select the options to use.createBrowser
: When the browser type is chosen and its options are defined, this function attempt to launch the browser 3 times before throwing an error. Sometimes the browser fail or crash when started, that's why multiple attempts are done.closeBrowser
: After finishing the run, this function is called to destroy all browser instances or temporary files used on the run.createContext
: A browser could have different contexts depending on the platform to test on, this function simplify the use.closeContext
: After finishing a scenario, this function is called to destroy all instances created by the context.addTab
: To test on a browser instance, we need a tab to perform action on, this function add a new tab and return it on the test.closeTab
: After finishing work on a tab (and we have more than one tab), this function could used to close it.
Environment parameters
To properly use the helper, you should use the environment parameters to set the global ones.
Browser options
| Parameter | Description |
|---------------------|----------------------------------------------------- |
| PLATFORM | Platform to run tests on desktop or mobile (default to desktop
) |
| BROWSER | Specific browser to launch for tests (default to chromium
) |
| HEADLESS | Boolean to run tests in headless mode or not (default to true
) |
| SLOW_MO | Integer to slow down Playwright operations by the specified amount of milliseconds (default to 5 milliseconds
) |
| ACCEPT_DOWNLOADS | Boolean to accept downloads on a run (default to true
) |
Context options
| Parameter | Description |
|---------------------|----------------------------------------------------- |
| WIDTH | Width size of the browser interface to open (default to 1680
) |
| HEIGHT | Height size of the browser interface to open (default to 900
) |
| LOCALE | Specific language of the browser language (default to fr-FR
) |
| DEVICE | Device to run test on if using mobile platform (default to null
) |
Tests parameters
| Parameter | Description |
|---------------------|----------------------------------------------------- |
| URL | Url to open for tests (default to null
) |
Examples
A small example was done to test the browser helper, the scenario of the test is:
- Go to Addons page
- Go to First Visit page using the menu
Before running examples, dependencies must be installed.
npm ci
To run tests :
npm run example