Skip to main content

beforeAll

Available from testplane v8.31.7

Overview​

This parameter is a hook. The function specified for this parameter will be automatically called before tests running.

The context of the function is the Testplane config. Also function receives config in arguments.

Usage Example​

Here is an example of using this hook for logging in and getting session data for use in tests.

testplane.config.ts
import { launchBrowser } from "testplane/unstable";

export default {
// ...
browsers: {
chrome: {
headless: true,
desiredCapabilities: {
webSocketUrl: true,
browserName: "chrome",
},
},
firefox: {
headless: true,
desiredCapabilities: {
webSocketUrl: true,
browserName: "firefox",
},
},
},
beforeAll: async () => {
// launch a new browser with existing config
const browser = await launchBrowser(this.config.browsers.chrome);

await browser.url("https://example.com");

// do login things, type username/password etc.

// save dump with state (cookies, localStorage) for using in tests
await browser.saveState({
path: "./dump.json",
});

await browser.deleteSession();
},
};