🛠️ Configure QA Wolf

TL;DR
  • If you haven't already, run the following to create a qawolf.config.js file in your project:
npm init qawolf

QA Wolf provides several options for you to configure your experience.

The qawolf.config.js file

Your configuration for QA Wolf lives in the qawolf.config.js file at the root of your project. This file is created for you when you run the following command:

npm init qawolf

Here is a full qawolf.config.js file. Note that only some of these settings are specified in the default generated file.

module.exports = {
// element attributes to use in selectors whenever possible
attribute: 'data-cy,data-e2e,data-qa,data-test,data-testid,/^qa-.*/',
// set jest config
config: 'node_modules/qawolf/js-jest.config.json',
createTemplate: ({ name, url }) => {
// returns test template as a string
},
// where tests are created
rootDir: '.qawolf',
// function to generate custom test template
// default timeout of a test in milliseconds
testTimeout: 60000,
// generate .ts files
useTypeScript: false
};

Below we go through the values that can be configured. Each of them is optional.

attribute

The attribute key in qawolf.config.json allows you to choose which attributes to prefer in the generated test code. QA Wolf will generate CSS selectors targeting these attributes whenever possible.

Default: 'data-cy,data-e2e,data-qa,data-test,data-testid,/^qa-.*/'

See the guide on using custom selectors to learn more.

config

Specifies which config is passed to Jest when running your tests:

jest --config='node_modules/qawolf/js-jest.config.json'

If the config is set to null or undefined, nothing will be passed to Jest.

Default: 'node_modules/qawolf/js-jest.config.json'. If TypeScript is detected: 'node_modules/qawolf/ts-jest.config.json'.

See Jest documentation to learn more.

createTemplate

A function that takes the options passed to the npx qawolf create command and returns the test template as a string. The function can be synchronous or asynchronous.

Default: Specified in QA Wolf source code.

Arguments

[device] (string): The Playwright device to emulate.

name (string): The name of the test.

[statePath] (string): The path where the user state is saved.

url (string): Visit this URL to begin the test.

[useTypeScript] (boolean): Whether the test should be in TypeScript.

Returns

(string | Promise<string>): The template to write to the test file.

Examples

The function below creates a test template based on the name and URL passed to npx qawolf create. Make sure to include the qawolf.create method where you want new code to be inserted.

const createTemplate = (options) => {
const { name, url } = options;
const code = `const qawolf = require("qawolf");
let browser;
let page;
beforeAll(async () => {
browser = await qawolf.launch();
const context = await browser.newContext();
await qawolf.register(context);
page = await context.newPage();
});
afterAll(async () => {
await qawolf.stopVideos();
await browser.close();
});
test('${name}', async () => {
await page.goto("${url}");
await qawolf.create();
});`;
return code;
};

rootDir

The diretory where tests will be created. For example, a test with the name myTest will be saved in a file called ${rootDir}/myTest.test.js.

Default: '.qawolf'

testTimeout

Default timeout of a test in milliseconds. This value is passed to Jest when running your tests:

jest --testTimeout=60000

Default: 60000

See Jest documentation to learn more.

useTypeScript

Whether to use TypeScript. If set to true, tests will be created in TypeScript and saved with the .ts file extension.

When you run npm init qawolf or yarn create qawolf, QA Wolf looks for a tsconfig.json to detect TypeScript.

If a tsconfig.json file is found, these additional dependencies will be installed: npm i -D @types/debug @types/jest @types/node ts-jest. The qawolf.config.js file will also be updated with the following properties:

module.exports = {
config: 'node_modules/qawolf/ts-jest.config.json',
// ...
useTypeScript: true,
};

If you prefer, you can set up TypeScript manually by setting the above properties in qawolf.config.js and installing the necessary dependencies (npm i -D @types/debug @types/jest @types/node ts-jest).

Default: false