-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Labels
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
latest
Node.js Version
20
Mode
WDIO Testrunner
Which capabilities are you using?
capabilities: [
{
// capabilities for local browser web tests
browserName: "chrome",
// "wdio:enforceWebDriverClassic": true, - toggled on to check usage differences
},
]What happened?
Toggling wdio:enforceWebDriverClassic or using v8 passing a statement string to browser.executeAsync executes as expected, example:
const res = await browser.executeAsync(`
const callback = arguments[arguments.length - 1];
return Promise.resolve(arguments[0] * 2).then(callback);
`, 6);
console.log({ res }); // 12When using WDIO v9 which defaults to use the BiDi protocol, I get an error:
[0-0] 2024-08-23T17:36:47.136Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[391 bytes]>","awaitPromise":true,"arguments":[{"type":"number","value":6}],"target":{"context":"C510048CD98884A967DA0A57E837406F"}}
[0-0] {
[0-0] res: {
[0-0] error: {
[0-0] message: "SyntaxError: Unexpected token 'const'",
[0-0] columnNumber: 26,
[0-0] exception: [Object],
[0-0] lineNumber: 9,
[0-0] stackTrace: [Object]
[0-0] }
[0-0] }
[0-0] }
To get around this I've had to replace my string with a function:
const res = await browser.executeAsync(function myFunc(...args: any[]) {
return Promise.resolve(args[0] * 2).then(args[args.length - 1]);
}, 6);
console.log({ res }); // 12This appears to have been introduced in: #13389
What is your expected behavior?
browser.executeAsync Function to execute as expected regardless if passed as a string or function declaration.
How to reproduce the bug.
With WDIO v9 use:
const res = await browser.executeAsync(`
const callback = arguments[arguments.length - 1];
return Promise.resolve(arguments[0] * 2).then(callback);
`, 6);
console.log({ res }); // 12Relevant log output
[0-0] 2024-08-23T17:36:47.136Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[391 bytes]>","awaitPromise":true,"arguments":[{"type":"number","value":6}],"target":{"context":"C510048CD98884A967DA0A57E837406F"}}
[0-0] {
[0-0] res: {
[0-0] error: {
[0-0] message: "SyntaxError: Unexpected token 'const'",
[0-0] columnNumber: 26,
[0-0] exception: [Object],
[0-0] lineNumber: 9,
[0-0] stackTrace: [Object]
[0-0] }
[0-0] }
[0-0] }
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
### Is there an existing issue for this?
- [X] I have searched the existing issues
Reactions are currently unavailable