Scripts
It is possible to execute user-defined scripts within tests. Script files should be located in the testabulous/scripts
folder and use the .mjs
file extension.
It's easy to execute a script simply do Run the script create_test_user.mjs
.
Script files should export a single function called execute()
which takes a single paramter, the test context, and returns a new Promise object.
export default async function execute(ctx) {
console.log('Creating test user...')
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Test user created!')
resolve({ result: "pass" })
}, 1000)
})
}
The test context is a Typescript object.
export type TestContextMetadata = Record<string, any>
export interface TestContext {
scriptsDir: string
browser: WebDriver
metadata: TestContextMetadata
timeout: number
testRunId: string
}
Test variables are stored in the context metadata
property.