2024-03-06 18:34:07 +03:00
|
|
|
import { expect as baseExpect, type Locator } from 'playwright/test'
|
2023-11-27 18:48:37 +03:00
|
|
|
|
2024-03-06 18:34:07 +03:00
|
|
|
export const expect = baseExpect.extend({
|
|
|
|
/** Ensures that at least one of the elements that the Locator points to,
|
|
|
|
* is an attached and visible DOM node. */
|
|
|
|
async toExist(locator: Locator) {
|
|
|
|
// Counter-intuitive, but correct:
|
|
|
|
// https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-be-visible
|
|
|
|
const assertionName = 'toExist'
|
|
|
|
let pass: boolean
|
|
|
|
try {
|
|
|
|
await expect(locator.first()).toBeVisible()
|
|
|
|
pass = true
|
|
|
|
} catch (e: any) {
|
|
|
|
console.log(e)
|
|
|
|
pass = false
|
|
|
|
}
|
2024-02-02 20:11:28 +03:00
|
|
|
|
2024-03-06 18:34:07 +03:00
|
|
|
const message = () =>
|
|
|
|
this.utils.matcherHint(assertionName, locator, '', {
|
|
|
|
isNot: this.isNot,
|
|
|
|
})
|
2024-02-28 16:14:48 +03:00
|
|
|
|
2024-03-06 18:34:07 +03:00
|
|
|
return {
|
|
|
|
message,
|
|
|
|
pass,
|
|
|
|
name: assertionName,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async toBeSelected(locator: Locator) {
|
|
|
|
const assertionName = 'toBeSelected'
|
|
|
|
let pass: boolean
|
|
|
|
try {
|
|
|
|
await baseExpect(locator).toHaveClass(/(?<=^| )selected(?=$| )/, { timeout: 50 })
|
|
|
|
pass = true
|
|
|
|
} catch (e: any) {
|
|
|
|
pass = false
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = () =>
|
|
|
|
this.utils.matcherHint(assertionName, locator, '', {
|
|
|
|
isNot: this.isNot,
|
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
|
|
|
message,
|
|
|
|
pass,
|
|
|
|
name: assertionName,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|