2023-03-18 06:20:35 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2023-04-29 00:18:46 +03:00
|
|
|
import { createImage } from './playwright-test-fixtures';
|
2023-05-18 21:28:28 +03:00
|
|
|
import { test, expect, retries } from './ui-mode-fixtures';
|
|
|
|
|
|
|
|
test.describe.configure({ mode: 'parallel', retries });
|
2023-03-18 06:20:35 +03:00
|
|
|
|
|
|
|
test('should merge trace events', async ({ runUITest, server }) => {
|
2023-03-29 23:57:19 +03:00
|
|
|
const { page } = await runUITest({
|
2023-03-18 06:20:35 +03:00
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('trace test', async ({ page }) => {
|
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
expect(1).toBe(1);
|
|
|
|
await page.getByRole('button').click();
|
|
|
|
expect(2).toBe(2);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('trace test').dblclick();
|
|
|
|
|
2023-09-08 03:14:39 +03:00
|
|
|
const listItem = page.getByTestId('actions-tree').getByRole('listitem');
|
2023-03-18 06:20:35 +03:00
|
|
|
await expect(
|
|
|
|
listItem,
|
|
|
|
'action list'
|
|
|
|
).toHaveText([
|
2023-05-06 01:12:18 +03:00
|
|
|
/Before Hooks[\d.]+m?s/,
|
|
|
|
/page.setContent[\d.]+m?s/,
|
|
|
|
/expect.toBe[\d.]+m?s/,
|
|
|
|
/locator.clickgetByRole\('button'\)[\d.]+m?s/,
|
|
|
|
/expect.toBe[\d.]+m?s/,
|
|
|
|
/After Hooks[\d.]+m?s/,
|
2023-04-29 00:18:46 +03:00
|
|
|
]);
|
2023-03-18 06:20:35 +03:00
|
|
|
});
|
|
|
|
|
2023-04-21 20:07:23 +03:00
|
|
|
test('should merge web assertion events', async ({ runUITest }, testInfo) => {
|
|
|
|
const { page } = await runUITest({
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('trace test', async ({ page }) => {
|
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
await expect(page.locator('button')).toBeVisible();
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('trace test').dblclick();
|
|
|
|
|
2023-09-08 03:14:39 +03:00
|
|
|
const listItem = page.getByTestId('actions-tree').getByRole('listitem');
|
2023-04-21 20:07:23 +03:00
|
|
|
await expect(
|
|
|
|
listItem,
|
|
|
|
'action list'
|
|
|
|
).toHaveText([
|
2023-05-06 01:12:18 +03:00
|
|
|
/Before Hooks[\d.]+m?s/,
|
|
|
|
/page.setContent[\d.]+m?s/,
|
|
|
|
/expect.toBeVisiblelocator\('button'\)[\d.]+m?s/,
|
|
|
|
/After Hooks[\d.]+m?s/,
|
2023-04-29 00:18:46 +03:00
|
|
|
]);
|
2023-04-21 20:07:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should merge screenshot assertions', async ({ runUITest }, testInfo) => {
|
|
|
|
const { page } = await runUITest({
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('trace test', async ({ page }) => {
|
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
await expect(page.locator('button')).toHaveScreenshot();
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('trace test').dblclick();
|
|
|
|
|
2023-09-08 03:14:39 +03:00
|
|
|
const listItem = page.getByTestId('actions-tree').getByRole('listitem');
|
2023-04-21 20:07:23 +03:00
|
|
|
await expect(
|
|
|
|
listItem,
|
|
|
|
'action list'
|
|
|
|
).toHaveText([
|
2023-05-06 01:12:18 +03:00
|
|
|
/Before Hooks[\d.]+m?s/,
|
2023-05-19 01:52:44 +03:00
|
|
|
/page.setContent[\d.]+m?s/,
|
|
|
|
/expect.toHaveScreenshot[\d.]+m?s/,
|
2023-10-26 03:05:06 +03:00
|
|
|
/attach "trace-test-1-actual.png/,
|
2023-05-23 19:36:35 +03:00
|
|
|
/After Hooks[\d.]+m?s/,
|
2023-04-29 00:18:46 +03:00
|
|
|
]);
|
2023-04-21 20:07:23 +03:00
|
|
|
});
|
|
|
|
|
2023-03-18 06:20:35 +03:00
|
|
|
test('should locate sync assertions in source', async ({ runUITest, server }) => {
|
2023-03-29 23:57:19 +03:00
|
|
|
const { page } = await runUITest({
|
2023-03-18 06:20:35 +03:00
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('trace test', async ({}) => {
|
|
|
|
expect(1).toBe(1);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('trace test').dblclick();
|
2023-05-06 01:12:18 +03:00
|
|
|
await page.getByText('expect.toBe').click();
|
2023-03-18 06:20:35 +03:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
page.locator('.CodeMirror .source-line-running'),
|
|
|
|
'check source tab',
|
2023-04-29 00:18:46 +03:00
|
|
|
).toHaveText('4 expect(1).toBe(1);');
|
2023-03-18 06:20:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should show snapshots for sync assertions', async ({ runUITest, server }) => {
|
2023-03-29 23:57:19 +03:00
|
|
|
const { page } = await runUITest({
|
2023-03-18 06:20:35 +03:00
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('trace test', async ({ page }) => {
|
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
await page.getByRole('button').click();
|
|
|
|
expect(1).toBe(1);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('trace test').dblclick();
|
|
|
|
|
2023-09-08 03:14:39 +03:00
|
|
|
const listItem = page.getByTestId('actions-tree').getByRole('listitem');
|
2023-03-18 06:20:35 +03:00
|
|
|
await expect(
|
|
|
|
listItem,
|
|
|
|
'action list'
|
|
|
|
).toHaveText([
|
2023-05-06 01:12:18 +03:00
|
|
|
/Before Hooks[\d.]+m?s/,
|
2023-03-18 06:20:35 +03:00
|
|
|
/page\.setContent[\d.]+m?s/,
|
|
|
|
/locator\.clickgetByRole\('button'\)[\d.]+m?s/,
|
|
|
|
/expect\.toBe[\d.]+m?s/,
|
2023-05-06 01:12:18 +03:00
|
|
|
/After Hooks[\d.]+m?s/,
|
2023-04-29 00:18:46 +03:00
|
|
|
]);
|
2023-03-18 06:20:35 +03:00
|
|
|
|
|
|
|
await expect(
|
2023-03-21 17:40:54 +03:00
|
|
|
page.frameLocator('iframe.snapshot-visible[name=snapshot]').locator('button'),
|
2023-03-18 06:20:35 +03:00
|
|
|
'verify snapshot'
|
|
|
|
).toHaveText('Submit');
|
|
|
|
});
|
2023-04-29 00:18:46 +03:00
|
|
|
|
|
|
|
test('should show image diff', async ({ runUITest, server }) => {
|
|
|
|
const { page } = await runUITest({
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = {
|
|
|
|
snapshotPathTemplate: '{arg}{ext}'
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'snapshot.png': createImage(100, 100, 255, 0, 0),
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('vrt test', async ({ page }) => {
|
|
|
|
await page.setViewportSize({ width: 100, height: 100 });
|
|
|
|
await expect(page).toHaveScreenshot('snapshot.png', { timeout: 2000 });
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('vrt test').dblclick();
|
2023-05-10 03:53:01 +03:00
|
|
|
await page.getByText(/Attachments/).click();
|
2023-04-29 00:18:46 +03:00
|
|
|
await expect(page.getByText('Diff', { exact: true })).toBeVisible();
|
|
|
|
await expect(page.getByText('Actual', { exact: true })).toBeVisible();
|
|
|
|
await expect(page.getByText('Expected', { exact: true })).toBeVisible();
|
|
|
|
await expect(page.locator('.image-diff-view .image-wrapper img')).toBeVisible();
|
|
|
|
});
|
2023-06-02 06:29:32 +03:00
|
|
|
|
|
|
|
test('should show screenshot', async ({ runUITest, server }) => {
|
|
|
|
const { page } = await runUITest({
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = {
|
|
|
|
use: {
|
|
|
|
screenshot: 'on',
|
|
|
|
viewport: { width: 100, height: 100 }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('vrt test', async ({ page }) => {
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.getByText('vrt test').dblclick();
|
|
|
|
await page.getByText(/Attachments/).click();
|
|
|
|
await expect(page.getByText('Screenshots', { exact: true })).toBeVisible();
|
|
|
|
await expect(page.locator('.attachment-item img')).toHaveCount(1);
|
|
|
|
});
|