Skip to content

[🐛 Bug]: switchToParentFrame switches to the top-level browsing context (root) instead of (only) the parent frame. #14064

@htho

Description

@htho

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.5.2

Node.js Version

v20.15.1

Mode

WDIO Testrunner

Which capabilities are you using?

{
	browserName: 'chrome',
	'goog:chromeOptions': {
		args: [
			"disable-search-engine-choice-screen",
			"ignore-certificate-errors",
			...(process.env["CI"] ? ['headless', 'disable-gpu'] : [])
		],
	}
}

What happened?

This test fails:

import { expect, browser } from '@wdio/globals'

beforeEach(async () => {
    await browser.url(`https://htho.github.io/wdio-repro-iframes/`);
});

// without this, the next test will load the url in the last selected frame
afterEach(() => browser.switchFrame(null))

describe('switchToParentFrame', () => {
    it("switches to parent (not top-level)", async () => {
        await expect($("h1")).toHaveText("Frame Demo");
        await expect($("h2")).not.toExist();
        await expect($("h3")).not.toExist();
    
        await browser.switchFrame($("#A"));
        await expect($("h1")).not.toExist();
        await expect($("h2")).toHaveText("IFrame A");
        await expect($("h3")).not.toExist();
        
        await browser.switchFrame($("#A2"));
        await expect($("h1")).not.toExist();
        await expect($("h2")).not.toExist();
        await expect($("h3")).toHaveText("IFrame A2");

        await browser.switchToParentFrame();
        await expect($("h1")).not.toExist(); // <- FAILS: Expect $(`h1`) not to exist - Received: "exist"
        await expect($("h2")).toHaveText("IFrame A");
        await expect($("h3")).not.toExist();
    });
});

What is your expected behavior?

The test should not fail.

How to reproduce the bug.

see above - I'm glad to add more if needed

Relevant log output

relevant output included as comment - I'm glad to add more if needed

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions