Skip to main content

testplane-global-hook

Overview

Use the testplane-global-hook plugin to bring out the common logic from your tests into special handlers for beforeEach and afterEach hooks.

Often, before running the next Testplane test, you need to do some preliminary setup, for example:

  • clear all cookies;
  • clean up your local storage;
  • initialize some test's common variable.

In order not to repeat these actions in each test, you can describe them in the plugin settings as an async-function for the beforeEach hook.

Similarly, after completing the basic checks in the Testplane test, you may want to always check for errors in the client code, the triggering of the necessary metrics, etc.

In order not to repeat these actions in each test, you can describe them in the plugin settings as an async-function for the afterEach hook.

Install

npm install -D testplane-global-hook

Setup

Add the plugin to the plugins section of the testplane config:

module.exports = {
plugins: {
"testplane-global-hook": {
beforeEach: async function () {
await this.browser.deleteCookie(); // Say, we want to always clear cookies before running a test
},
afterEach: async function () {
await this.browser.execute(function () {
try {
localStorage.clear(); // And always clean up the localStorage after the test is completed
} catch (e) {}
});
},
},

// other Testplane plugins...
},

// other Testplane settings...
};

Description of configuration parameters

ParameterTypeDefault valueDescription
enabledBooleantrueEnable / disable the plugin.
beforeEachFunctionnullAsynchronous function that will be executed before running each test.
afterEachFunctionnullAsynchronous function that will be executed after each test is completed.