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

[🐛 Bug]: switchFrame() doesn't always accept promise #13856

Closed
3 tasks done
gavvvr opened this issue Nov 5, 2024 · 9 comments · Fixed by #13863
Closed
3 tasks done

[🐛 Bug]: switchFrame() doesn't always accept promise #13856

gavvvr opened this issue Nov 5, 2024 · 9 comments · Fixed by #13863
Labels
Bug 🐛 help wanted Issues that are free to take by anyone interested

Comments

@gavvvr
Copy link
Contributor

gavvvr commented Nov 5, 2024

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

v9.2.8

Node.js Version

v22.6.0

Mode

Standalone Mode

Which capabilities are you using?

{
    browserName: 'electron',
    browserVersion: '33.0.0',
    'wdio:electronServiceOptions': {
        appArgs: []
    }
}

What happened?

The await browser.switchFrame($('iframe')) will fail in Electron app test setup with wdio-electron-service with the following error:

WebDriverError: invalid argument: missing 'ELEMENT'

What is your expected behavior?

Based on switchFrame() WDIO docs and existing test in E2E test suite, the following construct should work with no errors:

await browser.switchFrame($('iframe'))

How to reproduce the bug.

Here is the repo to reproduce the problem: https://github.com/gavvvr/wdio-electron-service-818

Relevant log output

[0-0] 2024-11-05T22:00:38.362Z ERROR webdriver: WebDriverError: invalid argument: missing 'ELEMENT'
[0-0]   (Session info: chrome=130.0.6723.59) when running "frame" with method "POST" and args "{"id":{}}"
[0-0] invalid argument in "My Login application.should reset the frame when the page is reloaded"
invalid argument: WebDriverError: invalid argument: missing 'ELEMENT'
  (Session info: chrome=130.0.6723.59) when running "frame" with method "POST" and args "{"id":{}}"
    at async Context.<anonymous> (/Users/user/Documents/sandboxes/wdio-electron-iframe-ts/test/specs/test.e2e.ts:4:5

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
@gavvvr gavvvr added Bug 🐛 Needs Triaging ⏳ No one has looked into the issue yet labels Nov 5, 2024
@gavvvr
Copy link
Contributor Author

gavvvr commented Nov 5, 2024

Initially I've opened a webdriverio-community/wdio-electron-service#818, but after some debugging I can see that it's rather a problem of switchFrame() implementation of primary webdriverio codebase.

The browser.switchFrame() call coming from wdio-electron-service-based test get into the following branch and context will be passed to switchToFrame() without promise resolution:

if (!this.isBidi) {
if (typeof context === 'function') {
throw new Error('Cannot use a function to fetch a context in WebDriver Classic')
}
if (typeof context === 'string') {
throw new Error('Cannot use a string to fetch a context in WebDriver Classic')
}
return switchToFrame(this, context)
}

So, I think it should rather be fixed in this repository.

@erwinheitzman
Copy link
Member

Hi there, I think that awaiting the promise is the quickest and easiest solution for now but I do feel like we can/should support this indeed 👍

@gavvvr
Copy link
Contributor Author

gavvvr commented Nov 6, 2024

@erwinheitzman, yeah, that's what I do as a workaround. But I would like to note that TypeScript doesn't agree with me that the result of $(...) can be awaited:
image

That's probably another bug with types (let me know if I should report it too), the object returned from $(...) obviously has .then() at runtime.

@goosewobbler
Copy link
Contributor

I'd like to note that there's some inconsistency in the docs here: In most of the docs, e.g. the selectors examples $(...) is used with await, but in the best practices it says that "You should always use await with the exception of the $ and $$ command.".

@erwinheitzman
Copy link
Member

@goosewobbler with v9 we introduced the .getElement method on the Element object which you can use to make TS stop complaining 🙂
I'm sure there will be leftovers pieces in the docs that we could update but why not contribute those documentation changes to the project? It is an easy way to get involved 😉

@goosewobbler
Copy link
Contributor

goosewobbler commented Nov 6, 2024

@erwinheitzman so you would suggest the following?

switchFrame(await $('iframe').getElement())

My WDIO bandwidth is currently occupied with getting back into webdriverio-community/wdio-electron-service#308, but I'll see if I can fit it in!

EDIT: updated to add await

@erwinheitzman
Copy link
Member

@goosewobbler yes but with the awaited added as well 👍

@christian-bromann
Copy link
Member

but in the best practices it says that "You should always use await with the exception of the $ and $$ command.".

This has changed in v9 and we haven't really fully cleaned up our docs. Elements don't need to be awaited anymore.

Anyway, switchFrame should work with switchFrame($('iframe')) and I thought I'd have tested that.

@christian-bromann christian-bromann added help wanted Issues that are free to take by anyone interested and removed Needs Triaging ⏳ No one has looked into the issue yet labels Nov 6, 2024
@wdio-bot
Copy link
Contributor

wdio-bot commented Nov 6, 2024

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 help wanted Issues that are free to take by anyone interested
Projects
None yet
5 participants