-
Notifications
You must be signed in to change notification settings - Fork 5k
Closed
Description
The app I am writing tests, has multiple windows. For example, first I need to login on MainPage, click button Edit, then second page EditPage will be opened, and the rest of actions happen on second page EditPage
I have written method to take video with chromium of the whole test flow from begin to end, but when the EditPage opens, the video is still focused on MainPage. The same goes for screenshot, when test fails on EditPage, the screenshot is still taken on MainPage
Below is part of my code:
// definition of take video and take screenshot functions
export async function recordeVideo(page: Page, name: string) {
return await saveVideo(page, videoDir + name + "_" + Date.now() + ".mp4");
}
export async function takeScreenshot(
page: Page,
name: string,
fullPage: boolean = true
): Promise<Buffer> {
return await page.screenshot({
fullPage: fullPage,
path: screenshotsDir + name + "_" + Date.now() + ".png",
});
}
// definition of test
beforeAll(async () => {
browser = await _.getBrowser();
context = await browser.newContext(_.contextOptions);
page = await context.newPage();
capture = await _.recordeVideo(page, "test_video");
await page.goto(URL, { waitUntil: "networkidle" });
});
describe("E2E Tests", () => {
// here are all defined test steps,
// just example how to handle multiple windows:
const editBtn = await page.$(editButton);
await editBtn.click();
// Get EditPage after clicking button
[editPage] = await Promise.all([
context.waitForEvent('page')
]);
await editPage.waitForLoadState();
// then the tests go on on editPage
});
afterEach(async () => {
if (jasmine.currentTest.failedExpectations.length > 0) {
await _.takeScreenshot(page, jasmine.currentTest.id);
success = false;
}
});
afterAll(async (done) => {
await capture.stop();
await page.close();
await browser.close();
});As I see the problem is, page is the input of function recordeVideo and takeScreenshot, that's why they don't take video or screenshot on editPage.
How can I record or take screenshot with multiple windows?
Thanks in advance.
Metadata
Metadata
Assignees
Labels
No labels