37 lines
1 KiB
TypeScript
37 lines
1 KiB
TypeScript
import { expect, type Locator } from '@playwright/test';
|
|
expect.extend({
|
|
async toBeAbove(self: Locator, other: Locator) {
|
|
const name = 'toBeAbove';
|
|
let pass: boolean;
|
|
let matcherResult: any;
|
|
let selfY: number | null = null;
|
|
let otherY: number | null = null;
|
|
try {
|
|
selfY = (await self.boundingBox())?.y ?? null;
|
|
otherY = (await self.boundingBox())?.y ?? null;
|
|
pass = selfY !== null && otherY !== null && (selfY < otherY);
|
|
} catch (e: any) {
|
|
matcherResult = e.matcherResult;
|
|
pass = false;
|
|
}
|
|
|
|
if (this.isNot) {
|
|
pass =!pass;
|
|
}
|
|
|
|
const message = () => this.utils.matcherHint(name, undefined, undefined, { isNot: this.isNot }) +
|
|
'\n\n' +
|
|
`Locator: ${self}\n` +
|
|
`Expected: above ${other} (y=${this.utils.printExpected(otherY)})\n` +
|
|
(matcherResult ? `Received: y=${this.utils.printReceived(selfY)}` : '');
|
|
|
|
return {
|
|
message,
|
|
pass,
|
|
name,
|
|
expected: (this.isNot ? '>=' : '<') + otherY,
|
|
actual: selfY,
|
|
};
|
|
|
|
}
|
|
});
|