import { Given, BeforeAll, Before, After, AfterAll } from '@wdio/cucumber-framework'
browser.addCommand('rootLevel', () => {
return true
})
BeforeAll(async () => {
expect(browser.Cucumber_Test).toBe(0)
expect(await browser.pause(1)).toBe(undefined)
expect(await browser.rootLevel()).toBe(true)
})
Before(async function (scenario) {
expect(browser.Cucumber_Test).toBe(1)
expect(Array.isArray(scenario.pickle.tags)).toBe(true)
expect(typeof this.attach).toBe('function')
expect(await browser.pause(1)).toBe(undefined)
})
After(async function (scenario) {
expect(browser.Cucumber_Test).toBe(1)
expect(typeof this.attach).toBe('function')
expect(Array.isArray(scenario.pickle.tags)).toBe(true)
expect(await browser.pause(1)).toBe(undefined)
})
AfterAll(async () => {
expect(browser.Cucumber_Test).toBe(-1)
expect(await browser.pause(1)).toBe(undefined)
})
Given('I choose the {string} scenario', { retry: { wrapperOptions: { retry: 1 } } }, async (scenario) => {
if (typeof browser[scenario] !== 'function') {
throw new Error(`Scenario with name "${scenario}" is not defined`)
}
await browser[scenario]()
})
const stepText = 'I go on the website'
Given(`${stepText} {string}`, async function (url) {
expect(typeof this.attach).toBe('function')
expect(browser.Cucumber_CurrentStepText.startsWith(stepText)).toBe(true)
await browser.url(url)
})
Given('I click on link {string}', async (selector) => {
const elem = await browser.$(selector)
expect(browser.Cucumber_Test).toBe(3)
await elem.click()
})
let foobarCounter = 1
Given(/^Foo (.*) and Bar (.*) are passed$/, async function (foo, bar) {
expect(foo).toBe('f' + foobarCounter)
expect(bar).toBe('b' + foobarCounter)
foobarCounter++
})
Given(/^a table step$/, async function (table) {
const expected = [
['Apricot', '5'],
['Brocolli', '2'],
['Cucumber', '10']
]
expect(table.rows()).toEqual(expected)
})
Given('this is ambiguous', () => {
})
Given('this is a step with timeout', { timeout: 6000 }, async () => {
await browser.pause(5500)
})
Given('I use the snapshot matcher', async () => {
await expect({ foo: 'bar' }).toMatchSnapshot()
})