Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Take DOM snapshots of all windows on failure #29983

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,13 @@ class Driver {

const filepathBase = `${artifactDir(title)}/test-failure`;
await fs.mkdir(artifactDir(title), { recursive: true });

const windowHandles = await this.driver.getAllWindowHandles();
// On occasion there may be a bug in the offscreen document which does
// not render visibly to the user and therefore no screenshot can be
// taken. In this case we skip the screenshot and log the error.
try {
// If there's more than one tab open, we want to iterate through all of them and take a screenshot with a unique name
const windowHandles = await this.driver.getAllWindowHandles();
for (const handle of windowHandles) {
await this.driver.switchTo().window(handle);
const windowTitle = await this.driver.getTitle();
Expand All @@ -1252,12 +1253,24 @@ class Driver {
} catch (e) {
console.error('Failed to take screenshot', e);
}
const htmlSource = await this.driver.getPageSource();
await fs.writeFile(`${filepathBase}-dom.html`, htmlSource);

try {
for (const handle of windowHandles) {
const windowNumber = windowHandles.indexOf(handle) + 1;
await this.driver.switchTo().window(handle);

const htmlSource = await this.driver.getPageSource();
await fs.writeFile(
`${filepathBase}-dom-${windowNumber}.html`,
htmlSource,
);
}
} catch (e) {
console.error('Failed to capture DOM snapshot', e);
}

// We want to take a state snapshot of the app if possible, this is useful for debugging
try {
const windowHandles = await this.driver.getAllWindowHandles();
for (const handle of windowHandles) {
await this.driver.switchTo().window(handle);
const uiState = await this.driver.executeScript(
Expand Down
Loading