Skip to content

[🐛 Bug]: switchFrame(selector) tries to wait for a delayed iframe - but fails #14082

@htho

Description

@htho

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.5.7

Node.js Version

20.15.1

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [{
    browserName: 'chrome'
}, {
    browserName: 'firefox'
}],

What happened?

I have an Iframe that is inserted to the dom at some point.
I use browser.switchFrame to switch to that iframe.

I found out, that switchFrame seems to wait for the iframe to appear, but then it fails anyway.
I can see that, because switchFrame takes longer, the longer it takes to load the iframe.
In the same moment the iframe appears, switchFrame fails.

    it(`(almost) waits automatically for delayedIframe`, async () => {
        await expect( () => browser.switchFrame(delayedIframe())).rejects.toThrow();
        
        // this means, that switchFrame waited, but failed anyway.
        await expect(delayedIframe()).toExist({wait:0});
        await expect(h1()).toHaveText("Delayed Iframe"); // still in parent frame
    });

I tried to create a helper function, that wraps browser.switchFrame and additionally waits using .waitForExist.
But this fails with different errors in chrome and firefox:

  • firefox: WebDriver Bidi command "script.callFunction" failed with error: invalid argument - Expected "type" to be a string, got [object Undefined] undefined
  • chrome: WebDriver Bidi command "script.callFunction" failed with error: invalid argument - Invalid input in "arguments"/0.
    it(`should let us use our custom switchFrame to wait for delayedIframe`, async () => {
        await switchFrame(delayedIframe());
        await expect(h1()).toHaveText("Delayed Inner Iframe");
    });
    async function switchFrame(sel: ChainablePromiseElement) {
        await sel.waitForExist();
        await browser.switchFrame(sel);
    }

What is your expected behavior?

Since we are almost there, I think browser.switchFrame should not fail, but properly switch the frame, after it waited.

Well, and I think it should be possible to pass a selector to another function and use it there.

How to reproduce the bug.

I created a repository that I can reuse to report bugs: https://github.com/htho/wdio-repro-collection

  1. git clone https://github.com/htho/wdio-repro-collection.git
  2. cd wdio-repro-collection
  3. npm ci
  4. npm run test:delayedIframe

Relevant log output

I included error messages above, the other messages can be reproduced in the repository.

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

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions