2021-01-23 05:47:02 +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.
|
|
|
|
*/
|
2021-02-06 01:24:27 +03:00
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
import { Page } from '../../index';
|
|
|
|
import { test as it, expect } from './inspectorTest';
|
2021-01-23 05:47:02 +03:00
|
|
|
|
2021-06-05 04:43:54 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should resume when closing inspector', async ({ page, recorderPageGetter, closeRecorder, mode }) => {
|
2021-06-05 04:43:54 +03:00
|
|
|
it.skip(mode !== 'default');
|
|
|
|
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
})();
|
|
|
|
await recorderPageGetter();
|
|
|
|
await closeRecorder();
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-04-05 19:18:56 +03:00
|
|
|
it.describe('pause', () => {
|
2021-04-30 23:26:13 +03:00
|
|
|
it.skip(({ mode }) => mode !== 'default');
|
2021-04-05 19:18:56 +03:00
|
|
|
|
|
|
|
it.afterEach(async ({ recorderPageGetter }) => {
|
2021-02-19 20:33:24 +03:00
|
|
|
try {
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-19 20:33:24 +03:00
|
|
|
recorderPage.click('[title=Resume]').catch(() => {});
|
|
|
|
} catch (e) {
|
|
|
|
// Some tests close context.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-05 19:18:56 +03:00
|
|
|
it('should pause and resume the script', async ({ page, recorderPageGetter }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-14 09:13:51 +03:00
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
2021-02-06 01:24:27 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should resume from console', async ({ page }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
})();
|
2021-02-06 01:24:27 +03:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForFunction(() => (window as any).playwright && (window as any).playwright.resume).then(() => {
|
|
|
|
return page.evaluate('window.playwright.resume()');
|
|
|
|
})
|
|
|
|
]);
|
2021-02-14 09:13:51 +03:00
|
|
|
await scriptPromise;
|
2021-02-06 01:24:27 +03:00
|
|
|
});
|
2021-01-23 05:47:02 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should pause after a navigation', async ({ page, server, recorderPageGetter }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.pause();
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-14 09:13:51 +03:00
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
2021-02-06 01:24:27 +03:00
|
|
|
});
|
2021-02-12 21:11:30 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should show source', async ({ page, recorderPageGetter }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-14 09:13:51 +03:00
|
|
|
const source = await recorderPage.textContent('.source-line-paused .source-code');
|
2021-02-12 21:11:30 +03:00
|
|
|
expect(source).toContain('page.pause()');
|
2021-02-14 09:13:51 +03:00
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should pause on next pause', async ({ page, recorderPageGetter }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause(); // 1
|
|
|
|
await page.pause(); // 2
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-14 09:13:51 +03:00
|
|
|
const source = await recorderPage.textContent('.source-line-paused');
|
|
|
|
expect(source).toContain('page.pause(); // 1');
|
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause(); // 2")');
|
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should step', async ({ page, recorderPageGetter }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.click('button');
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-14 09:13:51 +03:00
|
|
|
const source = await recorderPage.textContent('.source-line-paused');
|
|
|
|
expect(source).toContain('page.pause();');
|
|
|
|
|
|
|
|
await recorderPage.click('[title="Step over"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused :has-text("page.click")');
|
|
|
|
|
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should highlight pointer', async ({ page, recorderPageGetter }) => {
|
2021-02-14 09:13:51 +03:00
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.click('button');
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-14 09:13:51 +03:00
|
|
|
await recorderPage.click('[title="Step over"]');
|
|
|
|
|
|
|
|
const point = await page.waitForSelector('x-pw-action-point');
|
|
|
|
const button = await page.waitForSelector('button');
|
|
|
|
const box1 = await button.boundingBox();
|
|
|
|
const box2 = await point.boundingBox();
|
|
|
|
|
|
|
|
const x1 = box1.x + box1.width / 2;
|
|
|
|
const y1 = box1.y + box1.height / 2;
|
|
|
|
const x2 = box2.x + box2.width / 2;
|
|
|
|
const y2 = box2.y + box2.height / 2;
|
|
|
|
|
|
|
|
expect(Math.abs(x1 - x2) < 2).toBeTruthy();
|
|
|
|
expect(Math.abs(y1 - y2) < 2).toBeTruthy();
|
|
|
|
|
2021-02-19 20:33:24 +03:00
|
|
|
await recorderPage.click('[title=Resume]');
|
2021-02-14 09:13:51 +03:00
|
|
|
await scriptPromise;
|
2021-02-12 21:11:30 +03:00
|
|
|
});
|
2021-02-15 19:32:13 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should skip input when resuming', async ({ page, recorderPageGetter }) => {
|
2021-02-15 19:32:13 +03:00
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.click('button');
|
|
|
|
await page.pause(); // 2
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-15 19:32:13 +03:00
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause(); // 2")');
|
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should populate log', async ({ page, recorderPageGetter }) => {
|
2021-02-15 19:32:13 +03:00
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.click('button');
|
|
|
|
await page.pause(); // 2
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-15 19:32:13 +03:00
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause(); // 2")');
|
|
|
|
expect(await sanitizeLog(recorderPage)).toEqual([
|
2021-02-20 05:12:33 +03:00
|
|
|
'page.pause- XXms',
|
|
|
|
'page.click(button)- XXms',
|
|
|
|
'page.pause',
|
2021-02-15 19:32:13 +03:00
|
|
|
]);
|
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-29 02:02:34 +03:00
|
|
|
it('should show expect.toHaveText', async ({ page, recorderPageGetter }) => {
|
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await expect(page.locator('button')).toHaveText('Submit');
|
|
|
|
await page.pause(); // 2
|
|
|
|
})();
|
|
|
|
const recorderPage = await recorderPageGetter();
|
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause(); // 2")');
|
|
|
|
expect(await sanitizeLog(recorderPage)).toEqual([
|
|
|
|
'page.pause- XXms',
|
|
|
|
'expect.toHaveText(button)- XXms',
|
|
|
|
'page.pause',
|
|
|
|
]);
|
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should highlight waitForEvent', async ({ page, recorderPageGetter }) => {
|
2021-02-21 01:36:19 +03:00
|
|
|
await page.setContent('<button onclick="console.log(1)">Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await Promise.all([
|
2021-05-13 01:19:27 +03:00
|
|
|
page.waitForEvent('console', msg => msg.type() === 'log' && msg.text() === '1'),
|
2021-02-21 01:36:19 +03:00
|
|
|
page.click('button'),
|
|
|
|
]);
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-21 01:36:19 +03:00
|
|
|
await recorderPage.click('[title="Step over"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.click")');
|
|
|
|
await recorderPage.waitForSelector('.source-line-running:has-text("page.waitForEvent")');
|
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should populate log with waitForEvent', async ({ page, recorderPageGetter }) => {
|
2021-02-15 19:32:13 +03:00
|
|
|
await page.setContent('<button onclick="console.log(1)">Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForEvent('console'),
|
|
|
|
page.click('button'),
|
|
|
|
]);
|
|
|
|
await page.pause(); // 2
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-15 19:32:13 +03:00
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause(); // 2")');
|
|
|
|
expect(await sanitizeLog(recorderPage)).toEqual([
|
2021-02-20 05:12:33 +03:00
|
|
|
'page.pause- XXms',
|
2021-02-21 01:36:19 +03:00
|
|
|
'page.waitForEvent(console)',
|
2021-02-20 05:12:33 +03:00
|
|
|
'page.click(button)- XXms',
|
|
|
|
'page.pause',
|
2021-02-15 19:32:13 +03:00
|
|
|
]);
|
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should populate log with error', async ({ page, recorderPageGetter }) => {
|
2021-02-15 19:32:13 +03:00
|
|
|
await page.setContent('<button onclick="console.log(1)">Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.isChecked('button');
|
|
|
|
})().catch(e => e);
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-15 19:32:13 +03:00
|
|
|
await recorderPage.click('[title="Resume"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-error');
|
|
|
|
expect(await sanitizeLog(recorderPage)).toEqual([
|
2021-02-20 05:12:33 +03:00
|
|
|
'page.pause- XXms',
|
|
|
|
'page.isChecked(button)- XXms',
|
2021-09-25 04:55:45 +03:00
|
|
|
'waiting for selector "button"',
|
2021-02-18 09:10:13 +03:00
|
|
|
'selector resolved to <button onclick=\"console.log(1)\">Submit</button>',
|
2021-09-25 06:51:09 +03:00
|
|
|
'error: Error: Not a checkbox or radio button',
|
2021-02-15 19:32:13 +03:00
|
|
|
]);
|
|
|
|
const error = await scriptPromise;
|
|
|
|
expect(error.message).toContain('Not a checkbox or radio button');
|
|
|
|
});
|
2021-02-19 20:33:24 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should populate log with error in waitForEvent', async ({ page, recorderPageGetter }) => {
|
2021-02-21 01:36:19 +03:00
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await Promise.all([
|
2021-09-23 03:09:09 +03:00
|
|
|
page.waitForEvent('console', { timeout: 1 }).catch(() => {}),
|
|
|
|
page.pause(),
|
2021-02-21 01:36:19 +03:00
|
|
|
]);
|
2021-09-23 03:09:09 +03:00
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-21 01:36:19 +03:00
|
|
|
await recorderPage.click('[title="Step over"]');
|
2021-09-23 03:09:09 +03:00
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause")');
|
2021-02-21 01:36:19 +03:00
|
|
|
await recorderPage.waitForSelector('.source-line-error:has-text("page.waitForEvent")');
|
|
|
|
expect(await sanitizeLog(recorderPage)).toEqual([
|
|
|
|
'page.pause- XXms',
|
|
|
|
'page.waitForEvent(console)',
|
|
|
|
'waiting for event \"console\"',
|
|
|
|
'error: Timeout while waiting for event \"console\"',
|
2021-09-23 03:09:09 +03:00
|
|
|
'page.pause',
|
2021-02-21 01:36:19 +03:00
|
|
|
]);
|
2021-09-23 03:09:09 +03:00
|
|
|
await recorderPage.click('[title="Resume"]');
|
2021-02-21 01:36:19 +03:00
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-04-05 19:18:56 +03:00
|
|
|
it('should pause on page close', async ({ page, recorderPageGetter }) => {
|
2021-02-19 20:33:24 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.close();
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-19 20:33:24 +03:00
|
|
|
await recorderPage.click('[title="Step over"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.close();")');
|
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
|
|
|
|
2021-04-05 19:18:56 +03:00
|
|
|
it('should pause on context close', async ({ page, recorderPageGetter }) => {
|
2021-02-19 20:33:24 +03:00
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
await page.context().close();
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-02-19 20:33:24 +03:00
|
|
|
await recorderPage.click('[title="Step over"]');
|
|
|
|
await recorderPage.waitForSelector('.source-line-paused:has-text("page.context().close();")');
|
2021-09-23 03:09:09 +03:00
|
|
|
// Next line can throw because closing context also closes the inspector page.
|
|
|
|
await recorderPage.click('[title=Resume]').catch(e => {});
|
2021-02-19 20:33:24 +03:00
|
|
|
await scriptPromise;
|
|
|
|
});
|
2021-03-09 18:44:10 +03:00
|
|
|
|
2021-04-05 19:18:56 +03:00
|
|
|
it('should highlight on explore', async ({ page, recorderPageGetter }) => {
|
2021-03-09 18:44:10 +03:00
|
|
|
await page.setContent('<button>Submit</button>');
|
|
|
|
const scriptPromise = (async () => {
|
|
|
|
await page.pause();
|
|
|
|
})();
|
2021-04-05 19:18:56 +03:00
|
|
|
const recorderPage = await recorderPageGetter();
|
2021-03-09 18:44:10 +03:00
|
|
|
const [element] = await Promise.all([
|
|
|
|
page.waitForSelector('x-pw-highlight:visible'),
|
|
|
|
recorderPage.fill('input[placeholder="Playwright Selector"]', 'text=Submit'),
|
|
|
|
]);
|
|
|
|
const button = await page.$('text=Submit');
|
|
|
|
const box1 = await element.boundingBox();
|
|
|
|
const box2 = await button.boundingBox();
|
|
|
|
expect(box1).toEqual(box2);
|
|
|
|
await recorderPage.click('[title=Resume]');
|
|
|
|
await scriptPromise;
|
|
|
|
});
|
2021-01-23 05:47:02 +03:00
|
|
|
});
|
2021-02-15 19:32:13 +03:00
|
|
|
|
|
|
|
async function sanitizeLog(recorderPage: Page): Promise<string[]> {
|
2021-02-18 09:10:13 +03:00
|
|
|
const results = [];
|
|
|
|
for (const entry of await recorderPage.$$('.call-log-call')) {
|
2021-02-21 01:36:19 +03:00
|
|
|
const header = (await (await entry.$('.call-log-call-header')).textContent()).replace(/— [\d.]+(ms|s)/, '- XXms');
|
|
|
|
results.push(header.replace(/page\.waitForEvent\(console\).*/, 'page.waitForEvent(console)'));
|
|
|
|
results.push(...await entry.$$eval('.call-log-message', ee => ee.map(e => {
|
|
|
|
return (e.classList.contains('error') ? 'error: ' : '') + e.textContent;
|
|
|
|
})));
|
2021-02-18 09:10:13 +03:00
|
|
|
}
|
|
|
|
return results;
|
2021-02-15 19:32:13 +03:00
|
|
|
}
|