Skip to main content
Version: 2x

@qavajs/playwright

qavajs implementation on top of playwright runner

Demo projects:

Installation​

npm init playwright
npm install @qavajs/playwright

Configuration​

qavajs.config.ts

import { defineConfig } from '@qavajs/playwright';
import Memory from './memory';
import App from './page_object';

export default defineConfig({
paths: ['features/*.feature'],
require: [
'node_modules/@qavajs/playwright/steps.js', // package steps
'step_definitions/*.ts' // custom step definitions
],
memory: new Memory(),
pageObject: new App()
});

playwright.config.ts

import { defineConfig } from '@playwright/test';

export default defineConfig({
testMatch: 'qavajs.config.ts',
...
});
note

Requires Node.js 22 or later. Only @qavajs/playwright, @qavajs/playwright/steps.js and @qavajs/playwright/lib/electron.js entry points can be imported.

Page Object​

import { locator } from '@qavajs/playwright';

class LoginPage {
UsernameInput = locator('#username');
// template selector - argument is passed via 'ElementName(arg)' syntax in steps
RowByText = locator.template((text: string) => `tr:has-text("${text}")`);
// native playwright locator
ActiveTab = locator.native(({ page }) => page.locator('.tab.active'));
}

export default class App {
LoginPage = locator('#login').as(LoginPage);
}

More details in page object section.

Parameter Types​

typedescription
{value}quoted string resolved via memory
{locator}quoted page object alias resolved to playwright locator
{validation}validation (e.g. to equal, not to contain, to softly match) (validation)
{state}element state: present, clickable, visible, invisible, enabled, disabled, in viewport (e.g. to be visible, not to be softly present)
{mouseButton}left, right or middle
{browserButton}back or forward
{storageType}local or session
{bodyParsingType}json, text or buffer
{gqlRequestProperty}query or variables

Custom Steps​

Custom steps are defined with Given/When/Then exported from @qavajs/playwright and can reuse built-in parameter types and world helpers

World memberDescription
this.page, this.context, this.browser, this.requestPlaywright objects of current scenario
this.element(path)Resolve page object path to Locator
this.value(expression)Resolve memory expression ('$user', '$js(1 + 1)')
this.setValue(key, value)Save value to memory
this.expectPlaywright expect extended with qavajs matchers
this.waitForDialog()Get open dialog or wait for next one
this.log(data), this.attach(data, details)Add log or attachment to report
import { When, Then, type QavajsPlaywrightWorld, type MemoryValue, type Validation } from '@qavajs/playwright';
import type { Locator } from '@playwright/test';

When('I log in as {value}', async function (this: QavajsPlaywrightWorld, user: MemoryValue) {
const { username, password } = await user.value();
await this.element('LoginPage > UsernameInput').fill(username);
await this.element('LoginPage > PasswordInput').fill(password);
});

Then('I expect placeholder of {locator} {validation} {value}', async function (
this: QavajsPlaywrightWorld,
locator: Locator,
validation: Validation,
expected: MemoryValue
) {
// poll retries until validation passes or expect timeout is reached
await validation.poll(() => locator.getAttribute('placeholder'), await expected.value());
});

Action Steps​

I open {string} url​

Opens provided url

paramtypedescription
urlstringurl to navigate
When I open 'https://google.com' url

I type {string} (in)to {string}​

Type text to element

paramtypedescription
aliasstringelement to type
valuestringvalue to type
When I type 'wikipedia' to 'Google Input'
When I type 'wikipedia' into 'Google Input'

I type {string} chars (in)to {string}​

Type text to element sending fine-grained keyboard events

paramtypedescription
aliasstringelement to type
valuestringvalue to type
When I type 'wikipedia' chars to 'Google Input'
When I type 'wikipedia' chars into 'Google Input'

I click {string}​

Click element

paramtypedescription
aliasstringelement to click
When I click 'Google Button'

I right click {string}​

Right click element

paramtypedescription
aliasstringelement to click
When I right click 'Google Button'

I double click {string}​

Double click element

paramtypedescription
aliasstringelement to click
When I double click 'Google Button'

I tap {string}​

Tap element

paramtypedescription
aliasstringelement to tap
When I tap 'Google Button'

I clear {string}​

Clear element

paramtypedescription
aliasstringelement to clear
When I clear 'Search Input'

I click {string} text in {string} collection​

Click on element with desired text in collection

paramtypedescription
expectedTextstringtext to click
aliasstringcollection
When I click 'google' text in 'Search Engines' collection

I switch to {int} window​

Switch to window by index

paramtypedescription
indexnumberwindow index to switch
When I switch to 2 window

I switch to {string} window​

Switch to window by matcher

paramtypedescription
matcherstringwindow matcher (url or title)
When I switch to 'google.com' window

I open new tab​

Open new browser tab

When I open new tab

I close current tab​

Close current browser tab

When I close current tab

I refresh page​

Refresh page

When I refresh page

I press {string} key(s)​

Press key

paramtypedescription
keystringkey to press
When I press 'Enter' key

I press {string} key(s) {int} time(s)​

Press button given number of times

paramtypedescription
keystringkey to press
numbernumbernumber of times
I press 'Enter' key 5 times
I press 'Space' key 4 times

I hover over {string}​

Hover over element

paramtypedescription
aliasstringelement to hover over
When I hover over 'Google Button'

I select {string} option from {string} dropdown​

Select option with certain text from select element

paramtypedescription
optionstringoption to select
aliasstringalias of select
When I select '1900' option from 'Registration Form > Date Of Birth'
When I select '$dateOfBirth' option from 'Registration Form > Date Of Birth' dropdown

I select {int}(st|nd|rd|th) option from {string} dropdown​

Select option with certain index from select element

paramtypedescription
optionIndexnumberindex of option to select
aliasstringalias of select
When I select 1 option from 'Registration Form > Date Of Birth' dropdown

I accept alert​

Accepts an alert

When I accept alert

I dismiss alert​

Dismisses an alert

When I dismiss alert

I type {string} to alert​

Type a text to alert

paramtypedescription
valuestringvalue to type
When I type 'coffee' to alert

I upload {string} file to {string}​

Provide file url to upload input

paramtypedescription
aliasstringelement to upload file
valuestringfile path
When I upload '/folder/file.txt' file to 'File Input'

I scroll by {string}​

Scroll by offset

paramtypedescription
offsetstringoffset string in 'x, y' format
When I scroll by '0, 100'

I scroll to {string}​

Scroll to element

paramtypedescription
aliasstringalias of element
When I scroll to 'Element'

I scroll by {string} in {string}​

Scroll by offset in element

paramtypedescription
offsetstringoffset string in 'x, y' format
aliasstringalias of element
When I scroll by '0, 100' in 'Overflow Container'

I scroll until {string} to be visible​

Scroll page by mouse wheel until element becomes visible (limited by expect timeout)

paramtypedescription
aliasstringtarget element
When I scroll until 'Row 99' to be visible

I scroll in {string} until {string} to be visible​

Scroll in container by mouse wheel until element becomes visible (limited by expect timeout)

paramtypedescription
scrollstringscroll container
targetstringtarget element
When I scroll in 'List' until 'Row 99' to be visible

I drag and drop {string} to {string}​

Drag&Drop one element to another

paramtypedescription
elementAliasstringelement to drop
targetAliasstringtarget
When I drag and drop 'Bishop' to 'E4'

I define {string} as {string} locator​

Register selector as page object element in the root of page object. The alias stays available to scenarios that run later in the same worker.

paramtypedescription
selectorKeystringselector to register
aliasKeystringalias of element
When I define '#someId' as 'My Button' locator
And I click 'My Button'
When I define 'li.selected' as 'Selected Items' locator
And I expect number of elements in 'Selected Items' collection to equal '3'

I press {mouseButton} mouse button​

Press mouse button

paramtypedescription
buttonstringbutton to press (left, right, middle)
When I press left mouse button

I release {mouseButton} mouse button​

Release mouse button

paramtypedescription
buttonstringbutton to release (left, right, middle)
When I release left mouse button

I move mouse to {string}​

Move mouse to coordinates

paramtypedescription
coordinatesstringx, y coordinates to move
When I move mouse to '10, 15'

I scroll mouse wheel by {string}​

Scroll mouse wheel by x, y offset

paramtypedescription
coordinatesstringx, y offset to scroll
When I scroll mouse wheel by '0, 15'

I hold down {string} key​

Press and hold keyboard key

paramtypedescription
keystringkey to press
When I hold down 'Q' key

I release {string} key​

Release keyboard key

paramtypedescription
keystringkey to release
When I release 'Q' key

I click {browserButton} button​

Click browser button

paramtypedescription
buttonstringbrowser button (back, forward)
When I click back button
When I click forward button

I upload {string} file by clicking {string}​

Provide file url to file chooser

paramtypedescription
filestringfile path or file handle
aliasstringelement that invokes file chooser
When I upload '/folder/file.txt' file by clicking 'Upload Button'

I upload files by clicking {string}: [DataTable]​

Provide multiple files to file chooser

paramtypedescription
aliasstringelement that invokes file chooser
dataTableDataTablelist of file paths
When I upload files by clicking 'Upload Button':
| /folder/file1.txt |
| /folder/file2.txt |

I save file to {string} by clicking {string}​

Save downloaded file to certain path

paramtypedescription
pathstringfile path
aliasstringelement that invokes downloading
When I save file to './folder/file.pdf' by clicking 'Download Button'

I set window size {string}​

Resize browser viewport

paramtypedescription
viewportSizestringwidth and height in pixels separated by comma
When I set window size '1440,900'

I click {string} coordinates in {string}​

Click a certain coordinate of an element

paramtypedescription
coordinatesstringcomma separated x and y coordinates
aliasstringelement to click
When I click '0,20' coordinates in 'Google Button'

I force click {string}​

Force click element

paramtypedescription
aliasstringelement to click
When I force click 'Google Button'

Validation Steps​


I expect {string} {state}​

Verify that element satisfies certain condition

paramtypedescriptionexample
aliasstringelement to check conditionSearch Input
conditionWaitstringfunction to wait conditionto be visible, not to be present
Then I expect 'Header' to be visible
Then I expect 'Loading' not to be present

I expect number of elements in {string} collection {validation} {string}​

Verify that number of element in collection satisfies condition

paramtypedescriptionexample
collectionstringcollection to check conditionSearch Results
validationstringfunction to verify conditionto be equal, to be above, to be below
expectedValuestringexpected value
Then I expect number of elements in 'Search Results' collection to be equal '50'
Then I expect number of elements in 'Search Results' collection to be above '49'
Then I expect number of elements in 'Search Results' collection to be below '51'

I expect text of {string} {validation} {string}​

Verify that text of element satisfies condition

paramtypedescriptionexample
aliasstringelement to check conditionLabel, #1 of Search Results > Title
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect text of '#1 of Search Results' to be equal 'google'
Then I expect text of '#1 of Search Results' to be equal '$firstResult'

I expect value of {string} {validation} {string}​

Verify that value of element satisfies condition

paramtypedescriptionexample
aliasstringelement to check conditionInput, Text Area
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect value of 'Input' to be equal 'google'
Then I expect value of '#1 of Textareas' to be equal '$firstResult'

I expect {string} property of {string} {validation} {string}​

Verify that property of element satisfies condition

paramtypedescriptionexample
propertystringproperty check conditionvalue, href, checked, innerHTML
aliasstringelement to check conditionLabel, #1 of Search Results > Title
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect 'value' property of 'Search Input' to be equal 'text'
Then I expect 'innerHTML' property of 'Label' to contain '<b>'
Then I expect 'value' property of 'Search Input' to be equal '$inputText'

I expect {string} attribute of {string} {validation} {string}​

Verify that attribute of element satisfies condition

paramtypedescriptionexample
attributestringattribute check conditionhref, checked
aliasstringelement to check conditionLabel, #1 of Search Results > Title
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect 'href' attribute of 'Home Link' to contain '/home'
Then I expect 'href' attribute of 'Home Link' to be equal '$url'

I expect {string} custom property of {string} {validation} {string}​

Verify that result of custom function executed on element satisfies validation

paramtypedescriptionexample
propertystringfunction that accepts element as argument$js(element => element.value)
aliasstringelement to verifySearch Input
validationstringfunction to verify conditionto be equal, to be above, to be below
expectedValuestringexpected result
Then I expect '$js(element => element.value)' custom property of 'Element' to be equal '123'

I expect current url {validation} {string}​

Verify that current url satisfies condition

paramtypedescriptionexample
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect current url contains 'wikipedia'
Then I expect current url equals 'https://wikipedia.org'

I expect page title {validation} {string}​

Verify that page title satisfies condition

paramtypedescriptionexample
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect page title equals 'Wikipedia'

I expect every element in {string} collection {state}​

Verify that all elements in collection satisfy condition

paramtypedescriptionexample
aliasstringalias of collectionSearch Results
conditionstringcondition to waitto be visible, to be present
Then I expect every element in 'Header > Links' collection to be visible
Then I expect every element in 'Loading Bars' collection not to be present

I expect text of every element in {string} collection {validation} {string}​

Verify that all texts in collection satisfy condition

Note: step passes in case of empty collection

paramtypedescriptionexample
aliasstringalias of collectionSearch Results
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect text of every element in 'Search Results' collection equals to 'google'
Then I expect text of every element in 'Search Results' collection does not contain 'google'

I expect {string} attribute of every element in {string} collection {validation} {string}​

Verify that all particular attributes in collection satisfy condition

Note: step passes in case of empty collection

paramtypedescriptionexample
attributestringattribute to gethref, checked
aliasstringalias of collectionSearch Results
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect 'href' attribute of every element in 'Search Results' collection to contain 'google'

I expect {string} property of every element in {string} collection {validation} {string}​

Verify that all particular properties in collection satisfy condition

Note: step passes in case of empty collection

paramtypedescriptionexample
attributestringattribute to gethref, checked
aliasstringalias of collectionSearch Results
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect 'href' property of every element in 'Search Results' collection to contain 'google'

I expect {string} custom property of every element in {string} collection {validation} {string}​

Verify that result of custom function executed on every element in collection satisfies validation

paramtypedescriptionexample
propertystringfunction that accepts element as argument$js(element => element.nodeName)
aliasstringcollection to verifySearch Results
validationstringfunction to verify conditionto be equal, to be above, to be below
expectedValuestringexpected result
Then I expect '$js(element => element.nodeName)' custom property of every element in 'Collection' collection to equal 'LI'

I expect {string} css property of {string} {validation} {string}​

Verify that css property of element satisfies condition

paramtypedescriptionexample
propertystringproperty check conditioncolor, font-size
aliasstringelement to check conditionLabel, #1 of Search Results > Title
validationstringvalidation typeto be equal, to contain, not to match
expectedValuestringexpected result
Then I expect 'color' css property of 'Search Input' to be equal 'rgb(42, 42, 42)'
Then I expect 'font-family' css property of 'Label' to contain 'Fira'

I expect text of alert {validation} {string}​

Verify that text of an alert meets expectation

paramtypedescriptionexample
validationstringfunction to verify conditionto be equal, to be above, to be below
expectedValuestringexpected result
Then I expect text of alert does not contain 'coffee'
Then I expect text of alert does not contain 'hello world'
Then I expect text of alert does not contain 'Are you sure you want to leave this page?'

I expect {string} {validation} {string}​

Verify that value from memory satisfies validation against other value

paramtypedescriptionexample
value1anyvalue142, $value, $currentDate()
validationFunctionfunction to verify conditionto be equal, to be above, to be below
value2anyvalue242, $value, $currentDate()
Then I expect '$value' to equal '$anotherValue'
Then I expect '$value' not to contain '56'

I expect every element in {string} array {validation} {string}​

Verify that every element in array satisfies validation against other value

Then I expect every element in '$arr' array to be above '50'

I expect at least {int} element(s) in {string} array {validation} {string}​

Verify that at least x elements in array pass validation

Then I expect at least 2 elements in '$arr' array to be above '50'

I expect {string} array to be sorted by {string}​

Verify that array is sorted by provided comparator function

Then I expect '$arr' array to be sorted by '$ascending'

I expect {string} array {validation}: [DataTable]​

Verify that array satisfies validation against array provided as data table

Then I expect '$arr' array to have members:
| uno |
| dos |
| tres |

I expect {string} {validation} at least one of {string}​

Verify that value satisfies validation with at least one value from the array

Then I expect '$value' to equal at least one of '$js([1, 2, 3])'

I expect {string} {validation} at least one of: [DataTable]​

Verify that value satisfies validation with at least one value from the data table

Then I expect '$value' to equal at least one of:
| 1 |
| 2 |

I expect {string} {validation} all of {string}​

Verify that value satisfies validation with all values from the array

Then I expect '$value' not to equal all of '$js([1, 2, 3])'

I expect {string} {validation} all of: [DataTable]​

Verify that value satisfies validation with all values from the data table

Then I expect '$value' to contain all of:
| a |
| b |

Memory Steps​


I save text of {string} as {string}​

Save text of element to memory

paramtypedescriptionexample
aliasstringelement to get valueLabel, #1 of Search Results > Title
keystringkey to store value
When I save text of '#1 of Search Results' as 'firstSearchResult'

I save value of {string} as {string}​

Save value of input element to memory

paramtypedescriptionexample
aliasstringelement to get valueSearch Input
keystringkey to store valuequery
When I save value of 'Search Input' as 'query'

I save {string} property of {string} as {string}​

Save property of element to memory

paramtypedescriptionexample
propertystringproperty to storevalue, href, checked, innerHTML
aliasstringelement to get valueLabel, #1 of Search Results > Title
keystringkey to store value
When I save 'checked' property of 'Checkbox' as 'checked'
When I save '$prop' property of 'Checkbox' as 'checked'

I save {string} attribute of {string} as {string}​

Save attribute of element to memory

paramtypedescriptionexample
attributestringattribute to storehref, checked
aliasstringelement to get valueLabel, #1 of Search Results > Title
keystringkey to store value
When I save 'href' attribute of 'Link' as 'linkHref'
When I save '$prop' attribute of 'Link' as 'linkHref'

I save number of elements in {string} collection as {string}​

Save number of elements in collection to memory

paramtypedescriptionexample
collectionstringcollection to get valueSearch Results
keystringkey to store value
When I save number of elements in 'Search Results' collection as 'numberOfSearchResults'

I save text of every element of {string} collection as {string}​

Save array of texts of collection to memory

paramtypedescriptionexample
aliasstringcollection to get valueSearch Results
keystringkey to store value
When I save text of every element of 'Search Results' collection as 'searchResults'

I save {string} attribute of every element of {string} collection as {string}​

Save array of attributes of collection to memory

paramtypedescriptionexample
attributestringattribute to get valuechecked, href
aliasstringcollection to get valueSearch Results
keystringkey to store value
When I save 'checked' attribute of every element of 'Search > Checkboxes' collection as 'checkboxes'

I save {string} property of every element of {string} collection as {string}​

Save array of properties of collection to memory

paramtypedescriptionexample
propertystringproperty to get valuehref
aliasstringcollection to get valueSearch Results
keystringkey to store value
When I save 'href' property of every element of 'Search Results' collection as 'hrefs'

I save {string} custom property of {string} as {string}​

Save result of custom function executed on element to memory

When I save '$js(element => element.value)' custom property of 'Element' as 'value'

I save {string} custom property of every element of {string} collection as {string}​

Save array of results of custom function executed on every element of collection to memory

When I save '$js(element => element.nodeName)' custom property of every element of 'Collection' collection as 'nodeNames'

I save current url as {string}​

Save current url to memory

paramtypedescriptionexample
keystringkey to store value
When I save current url as 'currentUrl'

I save page title as {string}​

Save current page title to memory

paramtypedescriptionexample
keystringkey to store value
When I save page title as 'currentTitle'

I save {string} css property of {string} as {string}​

Save css property of element to memory

paramtypedescriptionexample
propertystringproperty to storebackground-color, font-size
aliasstringelement to get valueLabel, #1 of Search Results > Title
keystringkey to store value
When I save 'color' css property of 'Checkbox' as 'checkboxColor'
When I save '$propertyName' property of 'Checkbox' as 'checkboxColor'

I save screenshot as {string}​

Save page screenshot into memory

paramtypedescription
keystringkey to store value
When I save screenshot as 'screenshot'

I save full page screenshot as {string}​

Save full page screenshot into memory

paramtypedescription
keystringkey to store value
When I save full page screenshot as 'screenshot'

I save screenshot of {string} as {string}​

Save element screenshot into memory

paramtypedescription
keystringkey to store value
aliasstringelement to get screenshot
When I save screenshot of 'Element' as 'screenshot'

I save bounding rect of {string} as {string}​

Save bounding client rect to memory https://developer.mozilla.org/en-US/docs/Web/API/DOMRect

paramtypedescription
aliasstringelement to get bounding rect
keystringkey to store value
When I save bounding rect of 'Node' as 'boundingRect'
Then I expect '$boundingRect.width' to equal '42'

I save {string} to memory as {string}​

Save value to memory

When I save '42' to memory as 'answer'
When I save '$js(Date.now())' to memory as 'timestamp'

I set {string} = {string}​

Save value to memory (alias of I save {value} to memory as {value})

When I set 'answer' = '42'

I save multiline string to memory as {string}: [Multiline]​

Save multiline string to memory

When I save multiline string to memory as 'text':
"""
first line
second line
"""

I save json to memory as {string}: [Multiline]​

Parse json and save it to memory

When I save json to memory as 'payload':
"""
{ "name": "qavajs" }
"""

I save key-value pairs to memory as {string}: [DataTable]​

Save data table as object to memory

When I save key-value pairs to memory as 'user':
| name | qavajs |
| role | admin |

Wait Steps​


I wait {int} ms​

Wait for specified number of milliseconds

When I wait 1000 ms
note

until steps repeat action every 5 seconds until condition is met, up to 60 seconds.


I click {string} until {string} {state}​

Repeatedly click element until other element matches state

When I click 'Refresh Button' until 'Order Status' to be visible

I click {string} until text of {string} {validation} {string}​

Repeatedly click element until text of other element matches condition

When I click 'Send Message Button' until text of 'Information Alert' to be equal 'Your account has been banned'

I click {string} until value of {string} {validation} {string}​

Repeatedly click element until value of other element matches condition

When I click 'Plus Button' until value of 'Quantity Input' to be equal '9'

I refresh page until {string} {state}​

Refresh page until element matches state

When I refresh page until 'Internal Server Error Box' to be visible

I refresh page until text of {string} {validation} {string}​

Refresh page until element text matches condition

When I refresh page until text of 'Order Status' to be equal 'Processing'

I refresh page until value of {string} {validation} {string}​

Refresh page until element value matches condition

When I refresh page until value of 'Order Status Input' to be equal 'Processing'

Execute Steps​


I execute {string} function​

Execute client function

paramtypedescription
functionKeystringfunction memory key to execute
When I execute '$fn' function # fn is function reference
When I execute 'window.scrollBy(0, 100)' function

I execute {string} function and save result as {string}​

Execute client function and save result into memory

paramtypedescription
functionKeystringfunction memory key to execute
memoryKeystringmemory key to save value
When I execute '$fn' function and save result as 'result' # fn is function reference
When I execute 'window.scrollY' function and save result as 'scroll'

I execute {string} function on {string}​

Execute client function on certain element

paramtypedescription
functionKeystringfunction memory key to execute
aliasstringtarget element alias
When I execute '$fn' function on 'Component > Element' # fn is function reference
When I execute 'arguments[0].scrollIntoView()' function on 'Component > Element'

I execute {string} function on {string} and save result as {string}​

Execute client function on certain element

paramtypedescription
functionKeystringfunction memory key to execute
memoryKeystringmemory key to save value
aliasstringtarget element alias
When I execute '$fn' function on 'Component > Element' and save result as 'innerText' # fn is function reference
When I execute 'arguments[0].innerText' function on 'Component > Element' and save result as 'innerText'

Electron Steps​

Electron apps are tested with the same steps as web pages, plus electron steps. The app is launched by QavajsPlaywrightElectronWorld using launchOptions of the Playwright project, and this.page is the first window of the app.

qavajs.config.ts

export default defineConfig({
require: [
'node_modules/@qavajs/playwright/steps.js', // built-in step definitions
'node_modules/@qavajs/playwright/lib/electron.js', // electron step definitions
'step_definitions/*.ts' // custom step definitions incl. world setup (must go after steps.js)
],
});

step_definitions/setup.ts

import { setWorldConstructor, QavajsPlaywrightElectronWorld } from '@qavajs/playwright';

setWorldConstructor(QavajsPlaywrightElectronWorld);

playwright.config.ts

import { defineConfig } from '@playwright/test';

export default defineConfig({
testMatch: 'qavajs.config.ts',
projects: [
{
name: 'electron',
use: {
launchOptions: {
args: ['path/to/main.js']
}
},
}
]
});

In custom steps, the Electron main process is available as this.electron.


I execute {string} function/script on electron app​

Execute function on electron main process

When I execute '$js(async ({ app }) => app.getAppPath())' function on electron app

I execute {string} function/script on electron app and save result as {string}​

Execute function on electron main process and save result into memory

When I execute '$js(async ({ app }) => app.getAppPath())' function on electron app and save result as 'path'

I click {string} electron menu​

Click electron application menu item

When I click 'File > Edit' electron menu

Mock Steps​


I create mock for {string} as {string}​

Create mock instance

paramtypedescription
urlTemplatestringminimatch url template to mock
memoryKeystringmemory key to store mock instance
When I create mock for '/yourservice/**' as 'mock1'
When I create mock for '$mockUrlTemplate' as 'mock1'

I set {string} mock to respond {string} with: [multiline]​

Add mocking rule to respond with desired status code and payload

paramtypedescription
mockKeystringmemory key to get mock instance
statusCodestringstatus code
bodystringresponse body
When I create mock for '/yourservice/**' as 'myServiceMock'
And I set '$myServiceMock' mock to respond '200' with:
"""
{
"status": "success"
}
"""

I set {string} mock to respond {string} with {string}​

Add mocking rule to respond with desired status code and payload

paramtypedescription
mockKeystringmemory key to get mock instance
statusCodestringstatus code
bodystringresponse body
When I create mock for '/yourservice/**' as 'myServiceMock'
And I set '$myServiceMock' mock to respond '200' with '$response'

I set {string} mock to abort with {string} reason​

Add mocking rule to abort request with certain reason

paramtypedescription
mockKeystringmemory key to get mock instance
reasonstringreason string see https://playwright.dev/docs/api/class-route#route-abort
When I create mock for '/yourservice/**' as 'myServiceMock'
And I set '$myServiceMock' mock to abort with 'Failed' reason

I restore {string} mock​

Restore mock

paramtypedescription
mockKeystringmemory key to get mock instance
When I restore '$myServiceMock'

I restore all mocks​

Restore all mocks

When I restore all mocks

Set cookie

paramtypedescription
cookiestringcookie name
valuestringvalue to set
When I set 'userID' cookie as 'user1'
When I set 'userID' cookie as '$userIdCookie'

Save cookie value to memory

paramtypedescription
cookiestringcookie name
keystringmemory key
When I save value of 'auth' cookie as 'authCookie'

Local/Session Storage Steps​


I set {string} {storageType} storage value as {string}​

Set value of local/session storage

paramtypedescription
storageKeystringlocal/session storage key to set value
storageTypewordstorage type (local or session)
valuestringvalue to set
When I set 'username' local storage value as 'user1'
When I set '$sessionStorageKey' session storage value as '$sessionStorageValue'

I save value of {string} {storageType} storage as {string}​

Set value of local/session storage

paramtypedescription
storageKeystringlocal/session storage key to set value
storageTypewordstorage type (local or session)
keystringmemory key
When I save value of 'username' local storage as 'localStorageValue'
When I save value of '$sessionStorageKey' session storage value as 'sessionStorageValue'

Network Intercept Steps​


I create interception for {string} as {string}​

Create interception for url or predicate function

paramtypedescription
predicatestringurl or predicate function to listen
keystringkey to save interception
When I create interception for '**/api/qavajs' as 'interception'
When I create interception for '$condition' as 'intercept' # where condition is function that wait for particular event https://playwright.dev/docs/network#network-events

I wait for {string} response​

Wait for interception event

paramtypedescription
interceptionstringmemory key of interception event
When I create interception for '**/api/qavajs' as 'interception'
And I wait for '$interception' response

I save {string} response as {string}​

Wait for interception event and save response to memory

paramtypedescription
interceptionstringmemory key of interception event
keystringkey to save interception response
When I create interception for '**/api/qavajs' as 'interception'
And I save '$interception' response as 'response' # response will be instance of Response object https://playwright.dev/docs/api/class-response
And I expect '$response.status()' to equal '200'

File Steps​


I expect file matching {string} regexp exists in {string}​

Verify that file matching regexp exists in directory

paramtypedescriptionexample
filestringfile name regex to waitf.+.txt
dirstringdirectory path to wait./yourFolder
When I expect file matching 'f.+\.txt' regexp exists in './test-e2e/folder'
When I expect file matching '$fileRegexp' regexp exists in '$folder'

I expect {string} file exists​

Verify that file exists in provided location

paramtypedescriptionexample
filestringfile path to wait./yourFolder/file.txt
When I expect './test-e2e/folder/file.txt' file exists
When I expect '$filePath' file exists

I expect {string} text file content {validation} {string}​

Verify that text file content satisfy validation

paramtypedescriptionexample
filestringfile path./yourFolder/file.txt
validationTypestringvalidationto be equal, to contain
expectedValuestringexpected valuetext, $value
When I expect './folder/file.txt' text file content to be equal 'file content'
When I expect '$filePath' text file content to contain '$content'

I save {string} file content as {string}​

Save file content to memory as buffer

paramtypedescriptionexample
filestringfile path./yourFolder/file.jpeg
memoryKeystringmemory keyfileContent, value
When I save './folder/file.txt' file content as 'fileContent'
When I save '$filePath' file content as 'fileContent'

I save {string} text file content as {string}​

Save file content to memory as text (utf-8)

paramtypedescriptionexample
filestringfile path./yourFolder/file.txt
memoryKeystringmemory keytextContent, value
When I save './folder/file.txt' text file content as 'fileContent'
When I save '$filePath' text file content as 'fileContent'

HTTP Steps​


I create {method} request {requestKey}​

Create request and save it to memory

paramtypedescription
methodstringAPI method
requestKeystringkey to save request
When I create 'GET' request 'request'

I add headers to {requestKey}: [headersDataTable]​

Add data table of headers to request

paramtypedescription
requestKeystringmemory key of request
headersDataTableDataTablekey value array of headers
When I create 'GET' request 'request'
And I add headers to '$request':
| Content-Type | application/json |

I add {requestKey} headers to {headersKey}​

Add headers to request

paramtypedescription
requestKeystringmemory key of request
headersKeystringmemory key of headers that resolves to JS object
When I create 'GET' request 'request'
And I add '$headers' headers to '$request'

I add body to {requestKey}: [body]​

Add body to request as multiline parameter

paramtypedescription
requestKeystringmemory key of request
bodystring (Multiline)body
When I create 'GET' request 'request'
And I add body to '$request':
"""
{
"message": "qavajs"
}
"""

I add {requestKey} body to {body}​

Add body to request

paramtypedescription
requestKeystringmemory key of request
bodystringbody
When I create 'GET' request 'request'
And I add '$body' body to '$request'

I add {requestKey} url to {url}​

Add url to request

paramtypedescription
requestKeystringmemory key of request
urlstringurl
When I create 'GET' request 'request'
And I add 'https://qavajs.github.io/' url to '$request'

I send {requestKey} request and save response as {responseKey}​

Send prepared request and save response

paramtypedescription
requestKeystringmemory key of request
responseKeystringmemory key to save response
When I create 'GET' request 'request'
And I add 'https://qavajs.github.io/' url to '$request'
And I send '$request' request and save response as 'response'

I add form data body to {requestKey}: [dataTable]​

Send prepared request and save response

paramtypedescription
requestKeystringmemory key of request
dataTableDataTablebody
When I add body to '$request':
| key | value | filename | contentType |
| formKey | formValue | | application/json |
| otherKey | otherValue | | text/plain |
| fileKey | $file('./path/file.png') | file.png | image/png |

I create GraphQL request {requestKey}​

Create GraphQL request and save it to memory

paramtypedescription
requestKeystringkey to save request
When I create GraphQL request 'request'

I add {property} to GraphQL {string}: [value]​

Add GraphQL property

paramtypedescription
propertygqlRequestPropertyquery or variables
requestKeystringmemory key of request
valuestring (Multiline)value multiline string
When I create GraphQL request 'request'
And I add query to GraphQL '$request':
"""
query {
characters(page: 2, filter: { name: "rick" }) {
results {
name
}
}
}
"""
And I add variables to GraphQL '$request':
"""
{
"value": 42
}
"""

I parse {response} body as {bodyParsingType}​

MANDATORY STEP THAT SHOULD BE USED AFTER SENDING REQUEST Parsing body in needed way and adds payload property to response

paramtypedescription
responsestringresponse key in memory
typebodyParsingTypetype of payload (json, text, buffer)
When I parse '$response' body as json
Then I expect '$response.payload.foo' to equal 'bar'