/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { stripAnsi } from '../config/utils';
import { test, expect } from './pageTest';
test('toMatchText-based assertions should have matcher result', async ({ page }) => {
await page.setContent('
Text content
');
const locator = page.locator('#node');
{
const e = await expect(locator).toHaveText(/Text2/, { timeout: 1 }).catch(e => e);
e.matcherResult.message = stripAnsi(e.matcherResult.message);
expect.soft(e.matcherResult).toEqual({
actual: 'Text content',
expected: /Text2/,
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveText(expected)`),
name: 'toHaveText',
pass: false,
log: expect.any(Array),
timeout: 1,
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveText(expected)
Locator: locator('#node')
Expected pattern: /Text2/
Received string: \"Text content\"
Call log`);
}
{
const e = await expect(locator).not.toHaveText(/Text/, { timeout: 1 }).catch(e => e);
e.matcherResult.message = stripAnsi(e.matcherResult.message);
expect.soft(e.matcherResult).toEqual({
actual: 'Text content',
expected: /Text/,
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveText(expected)`),
name: 'toHaveText',
pass: true,
log: expect.any(Array),
timeout: 1,
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveText(expected)
Locator: locator('#node')
Expected pattern: not /Text/
Received string: \"Text content\"
Call log`);
}
});
test('toBeTruthy-based assertions should have matcher result', async ({ page }) => {
await page.setContent('
Text content
');
{
const e = await expect(page.locator('#node2')).toBeVisible({ timeout: 1 }).catch(e => e);
e.matcherResult.message = stripAnsi(e.matcherResult.message);
expect.soft(e.matcherResult).toEqual({
actual: 'hidden',
expected: 'visible',
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeVisible()`),
name: 'toBeVisible',
pass: false,
log: expect.any(Array),
timeout: 1,
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeVisible()
Locator: locator('#node2')
Expected: visible
Received:
Call log`);
}
{
const e = await expect(page.locator('#node')).not.toBeVisible({ timeout: 1 }).catch(e => e);
e.matcherResult.message = stripAnsi(e.matcherResult.message);
expect.soft(e.matcherResult).toEqual({
actual: 'visible',
expected: 'visible',
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeVisible()`),
name: 'toBeVisible',
pass: true,
log: expect.any(Array),
timeout: 1,
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeVisible()
Locator: locator('#node')
Expected: not visible
Received: visible
Call log`);
}
});
test('toEqual-based assertions should have matcher result', async ({ page }) => {
await page.setContent('