mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
chore: render user-friendly intermediate match values (#18867)
This commit is contained in:
parent
4e58b0c2ea
commit
b1acc0d0ea
@ -1406,7 +1406,7 @@ export class Frame extends SdkObject {
|
||||
// expect(locator).not.conditionThatDoesMatch
|
||||
progress.setIntermediateResult(result.received);
|
||||
if (!Array.isArray(result.received))
|
||||
progress.log(` unexpected value "${result.received}"`);
|
||||
progress.log(` unexpected value "${progress.injectedScript.renderUnexpectedValue(options.expression, result.received)}"`);
|
||||
return progress.continuePolling;
|
||||
}
|
||||
|
||||
|
@ -1205,6 +1205,30 @@ export class InjectedScript {
|
||||
throw this.createStacklessError('Unknown expect matcher: ' + expression);
|
||||
}
|
||||
|
||||
renderUnexpectedValue(expression: string, received: any): string {
|
||||
if (expression === 'to.be.checked')
|
||||
return received ? 'checked' : 'unchecked';
|
||||
if (expression === 'to.be.unchecked')
|
||||
return received ? 'unchecked' : 'checked';
|
||||
if (expression === 'to.be.visible')
|
||||
return received ? 'visible' : 'hidden';
|
||||
if (expression === 'to.be.hidden')
|
||||
return received ? 'hidden' : 'visible';
|
||||
if (expression === 'to.be.enabled')
|
||||
return received ? 'enabled' : 'disabled';
|
||||
if (expression === 'to.be.disabled')
|
||||
return received ? 'disabled' : 'enabled';
|
||||
if (expression === 'to.be.editable')
|
||||
return received ? 'editable' : 'readonly';
|
||||
if (expression === 'to.be.readonly')
|
||||
return received ? 'readonly' : 'editable';
|
||||
if (expression === 'to.be.empty')
|
||||
return received ? 'empty' : 'not empty';
|
||||
if (expression === 'to.be.focused')
|
||||
return received ? 'focused' : 'not focused';
|
||||
return received;
|
||||
}
|
||||
|
||||
expectArray(elements: Element[], options: FrameExpectParams): { matches: boolean, received?: any } {
|
||||
const expression = options.expression;
|
||||
|
||||
|
@ -86,6 +86,16 @@ test.describe('toBeChecked', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('friendly log', async ({ page }) => {
|
||||
await page.setContent('<input type=checkbox></input>');
|
||||
const message1 = await expect(page.locator('input')).toBeChecked({ timeout: 1000 }).catch(e => e.message);
|
||||
expect(message1).toContain('unexpected value "unchecked"');
|
||||
|
||||
await page.setContent('<input type=checkbox checked></input>');
|
||||
const message2 = await expect(page.locator('input')).toBeChecked({ checked: false, timeout: 1000 }).catch(e => e.message);
|
||||
expect(message2).toContain('unexpected value "checked"');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('toBeEditable', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user