Hello,
I'm using Codeceptjs with webdriverio and browserstack (automate) and I鈥檓 facing an issue related with MJSONWP endpoint to fetch the timeouts and makes my test suite to crash.
Error: Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}
-- FAILURES:
1) Commit valid answer
"before each" hook: codeceptjs.before for "Commit a valid answer for an explicit commit block":
Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}
rror: Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}
at getErrorFromResponseBody (node_modules/webdriver/build/utils.js:336:12)
at Request._callback (node_modules/webdriver/build/request.js:116:64)
at Request.self.callback (node_modules/request/request.js:185:22)
at Request.EventEmitter.emit (domain.js:441:20)
at Request.<anonymous> (node_modules/request/request.js:1161:10)
at Request.EventEmitter.emit (domain.js:441:20)
at IncomingMessage.<anonymous> (node_modules/request/request.js:1083:12)
Using inside browserstack: appium_version: 1.9.1 (Tried with 1.6.5, 1.7.1, etc...)**
Configuration file:
What I found interesting is that Inside my config file (codeceptjs config file) I do not specify any timeout option.
exports.config = {
tests: './test_codecept/*.js',
output: './test_codecept/output',
helpers: {
WebDriver: {
host: 'hub.browserstack.com',
path: '/wd/hub',
url: 'http://WEBSITE:8080/renderer',
user: 'xx',
key: 'xx',
browser: 'iphone',
desiredCapabilities: {
'os_version' : '11',
'device' : 'iPhone 8',
'real_mobile' : 'true',
'browserstack.local' : 'true',
'browserstack.debug' : 'true',
'browserstack.networkLogs' : 'true',
'browserstack.appium_version' : '1.9.1',
'browserstack.user' : 'xx',
'browserstack.key' : 'xx'
}
}
}
}
After failing a few times, I tried to specify a timeout option inside the helper like mention in the w3c WebDriver spec
and didn't work neither, appeared that I was sending an empty object to the sessionId/timeouts.
timeouts: {
type: 'script',
ms: 1000
}
After that I tried to setup the timeouts like the error message propose: "type" and "ms", didn't work neither.
timeouts: {
type: 'script',
ms: 1000
}
Thanks for reading
Codecept with WebDriver/WebDriverIO/Appium calls defineTimeout after browser starts.
I think, problem in "browser" field. What it you fill it as "safari" ?
Maybe, it's WebDriverIO issue.
@LukoyanovE I tried both options for browser. Interesting is that running tests on Android (same Appium version) works.
I opened an issue on WebdriverIO but they indicated it was a Codeceptjs issue.
@raquelgs, which two options did you use?
Can You place config for android, if it works?
exports.config = {
tests: './test_codecept/*.js',
output: './test_codecept/output',
helpers: {
WebDriver: {
host: 'hub.browserstack.com',
path: '/wd/hub',
url: process.env.URL,
user: 'SECRET_USER',
key: 'SECRET_KEY',
browser: 'DOESNOTMATTER', // Here we can specify anything, because it's ignored once you are running in BrowserStack.
desiredCapabilities: {
os_version: '7.0',
device: 'Samsung Galaxy S8',
real_mobile: 'true',
'browserstack.local': 'true',
'browserstack.debug': 'true',
'browserstack.networkLogs': 'true',
'browserstack.appium_version': '1.9.1'
}
}
}
}
This is the request for Android:
[HTTP] --> POST /wd/hub/session/b2664649-4bc8-42f3-8d04-24f6e4fb2c18/timeouts
[HTTP] {"script":1000}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Matched '/wd/hub/session/b2664649-4bc8-42f3-8d04-24f6e4fb2c18/timeouts' to command name 'timeouts'
[debug] [Protocol Converter] Will send the following request bodies to /timeouts: [{"type":"script","ms":1000}]
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/b2664649-4bc8-42f3-8d04-24f6e4fb2c18/timeouts] to [POST http://127.0.0.1:18083/wd/hub/session/a96fc472ef3730d35e5aeae026f14c89/timeouts] with body: {"type":"script","ms":1000}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"a96fc472ef3730d35e5aeae026f14c89","status":0,"value":null}
This is what happens when it is iOS:
[HTTP] --> POST /wd/hub/session/664e2ad7-e4ae-47a4-844e-d989b7ae4cb0/timeouts
[HTTP] {"script":1000}
[debug] [MJSONWP (664e2ad7)] Encountered internal error running command: BadParametersError: Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}
[debug] [MJSONWP (664e2ad7)] at checkParams (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/appium-base-driver/lib/protocol/protocol.js:177:15)
[debug] [MJSONWP (664e2ad7)] at /usr/local/.browserstack/appium_1.9.1_bstack/node_modules/appium-base-driver/lib/protocol/protocol.js:335:7
[debug] [MJSONWP (664e2ad7)] at Generator.next (<anonymous>)
[debug] [MJSONWP (664e2ad7)] at asyncGeneratorStep (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
[debug] [MJSONWP (664e2ad7)] at _next (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
[debug] [MJSONWP (664e2ad7)] at /usr/local/.browserstack/appium_1.9.1_bstack/node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
[debug] [MJSONWP (664e2ad7)] at Promise (<anonymous>)
[debug] [MJSONWP (664e2ad7)] at /usr/local/.browserstack/appium_1.9.1_bstack/node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12
[debug] [MJSONWP (664e2ad7)] at asyncHandler (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/appium-base-driver/lib/protocol/protocol.js:287:19)
[debug] [MJSONWP (664e2ad7)] at app.(anonymous function) (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/appium-base-driver/lib/protocol/protocol.js:492:15)
[debug] [MJSONWP (664e2ad7)] at Layer.handle [as handle_request] (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/layer.js:95:5)
[debug] [MJSONWP (664e2ad7)] at next (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/route.js:137:13)
[debug] [MJSONWP (664e2ad7)] at Route.dispatch (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/route.js:112:3)
[debug] [MJSONWP (664e2ad7)] at Layer.handle [as handle_request] (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/layer.js:95:5)
[debug] [MJSONWP (664e2ad7)] at /usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:281:22
[debug] [MJSONWP (664e2ad7)] at param (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:354:14)
[debug] [MJSONWP (664e2ad7)] at param (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:365:14)
[debug] [MJSONWP (664e2ad7)] at Function.process_params (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:410:3)
[debug] [MJSONWP (664e2ad7)] at next (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:275:10)
[debug] [MJSONWP (664e2ad7)] at logger (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/morgan/index.js:144:5)
[debug] [MJSONWP (664e2ad7)] at Layer.handle [as handle_request] (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/layer.js:95:5)
[debug] [MJSONWP (664e2ad7)] at trim_prefix (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:317:13)
[debug] [MJSONWP (664e2ad7)] at /usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:284:7
[debug] [MJSONWP (664e2ad7)] at Function.process_params (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:335:12)
[debug] [MJSONWP (664e2ad7)] at next (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/express/lib/router/index.js:275:10)
[debug] [MJSONWP (664e2ad7)] at /usr/local/.browserstack/appium_1.9.1_bstack/node_modules/body-parser/lib/read.js:130:5
[debug] [MJSONWP (664e2ad7)] at invokeCallback (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/raw-body/index.js:224:16)
[debug] [MJSONWP (664e2ad7)] at done (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/raw-body/index.js:213:7)
[debug] [MJSONWP (664e2ad7)] at IncomingMessage.onEnd (/usr/local/.browserstack/appium_1.9.1_bstack/node_modules/raw-body/index.js:273:7)
[debug] [MJSONWP (664e2ad7)] at emitNone (events.js:105:13)
[debug] [MJSONWP (664e2ad7)] at IncomingMessage.emit (events.js:207:7)
[debug] [MJSONWP (664e2ad7)] at endReadableNT (_stream_readable.js:1059:12)
[debug] [MJSONWP (664e2ad7)] at _combinedTickCallback (internal/process/next_tick.js:138:11)
[debug] [MJSONWP (664e2ad7)] at process._tickCallback (internal/process/next_tick.js:180:9)
[debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}
@LukoyanovE I've been checking with webdriverio 4.14.1 and same test on iOS works. Here the traces:
```[HTTP] <-- POST /wd/hub/session/a7ed46dd-7a34-4658-aa19-e270b658c622/timeouts 400 43 ms - 105
[HTTP]
[HTTP] --> POST /wd/hub/session/a7ed46dd-7a34-4658-aa19-e270b658c622/timeouts
[HTTP] {"type":"script","ms":1000}
[debug] [MJSONWP (a7ed46dd)] Calling AppiumDriver.timeouts() with args: ["script",1000,null,null,null,"a7ed46dd-7a34-4658-aa19-e270b658c622"]
[debug] [XCUITest] Executing command 'timeouts'
[debug] [BaseDriver] MJSONWP timeout arguments: {"type":"script","ms":1000}}
[debug] [iOS] Set async script timeout to 1000ms
[debug] [MJSONWP (a7ed46dd)] Responding to client with driver.timeouts() result: null
@LukoyanovE Do you have any update? Thanks!
Seems like a bug in appium - https://github.com/appium/ruby_lib_core/issues/128, But the fix itself has landed in 1.9.1 and still the issue exists. Worth a try with the new appium release.
Hi, Is this issue resolved?
@lokesh-rj I still need to try with appium latest release. Without having investigated more, using same appiume version (1.9.1) with webdriverio 4 it was working fine
@lokesh-rj @raquelgs any updates on this? We are using Sauce Labs and I reached out to their support team and they seemed to say the same thing that it was a bug in CodeceptJS.
@danieltisdale I was not able to try with a version higher than 1.9.1 (no device available with this version, I've contacted Browserstack support team)
@raquelgs : is this issue resolved?
I'm facing the same issue in IOS devices, but the same code is working in Android.
I have the same problem.
@raquelgs what does the BrowserStack support answered, could they help you to fix it?
@pablopaul copy&paste of their response:
To execute the tests on iOS, XCUITest driver is used, however, to execute the tests on Android, Appium Driver is used. From the Appium Logs, I observed that the client bindings at your end are sending the request in W3C mode, however, WebdriverIO understands the request in W3C mode, only when Appium Driver is used. Hence setting timeouts is being executed successfully on Android since to execute tests on Android, Appium driver is used and to execute tests on iOS, XCUItest Driver is used. Hence, using WebdriverIO, you are able to set the timeouts when running the test on Android device, whereas setting the timeouts on an iOS device, throws the error 'Error: Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}'.
thanks @raquelgs I am confused now :)
Hi,
We still have this issue active. When I tried to remove timeouts from WebDriver helper, Things seems to be working fine. Can someone help me to close fix this?
Seeing this issue when testing on Sauce Labs iOS Real Devices (aka TestObject)...
@michaeldrews which Appium version is running on Sauce Labs in your case?
@pablopaul seeing this when using Appium 1.9.1 and 1.13.0
thanks @michaeldrews , I expected this to be resolved on iOS with Appium version later then 1.9.1.
Why? Because Android with Appium 1.12.1 is running fine with CodeceptJS and BrowserStack.
@michaeldrews can you please double check the Appium version on iOS you used?
@pablopaul @michaeldrews
With Saucelabs
1.9.0' -> Error: Appium version '1.9.0' is not available for 'WEB' apps on 'IOS'
1.9.1 /1.13.0-> Parameters were incorrect. We wanted "MJSONWP protocol requires type and ms" and you sent {"script":1000}
FYI: Saucelabs has 1.13.0 as default Appium version
I digged deeper.
I tested Appium 1.9.1 with CodeceptJS locally running a test on iOS works fine, this seems to be a BrowserStack and Appium specific problem.
I contacted BrowserStacks support but I do not expect a fix in short time.
Maybe its time to report the issue in the Appium repo, maybe they can fix it - but as there is only a "old" Appium version 1.9.1 available on BrowserStack, this also would not really solve it by now. Difficult.
I also created an issue in the Appium repo as I am unsure where the fix need to happen: On BrowserStack side or on Appium side?
For reference https://github.com/webdriverio/webdriverio/issues/4273
I did the following patch mechanism to temporarily fix this issue on our side:
Added "postinstall" to the "scripts" objects in the package.json:
"scripts": {
"postinstall": "patch-package"
},
Install "patch-package" via npm i patch-package --save-dev
Remove the following lines from node_modules/lib/helper/WebDriver.js:
timeouts: {
script: 1000, // ms
},
Run npx patch-package codeceptjs.
Commit the changes and the new patch file and start running your iOS tests on BrowserStack :)
@pablopaul , with this new patch added in your previous reply, will this work on Sauce Labs also on Appium 1.13.0?
@prasadam: Yes, It does work.
Just landed here after a bit of Googling. I might not be addressing the right version though.
I experimented with specifying the helper like so:
config.helpers = {
Appium: {
host: 'hub-cloud.browserstack.com',
port: 4444,
user: BROWSERSTACK_USERNAME,
key: BROWSERSTACK_ACCESS_KEY,
platform: 'iOS',
url: 'https://padlet.com',
desiredCapabilities: {
'bstack:options': {
osVersion: '11',
deviceName: 'iPhone 8',
appiumVersion: '1.11.1',
userName: BROWSERSTACK_USERNAME,
accessKey: BROWSERSTACK_ACCESS_KEY,
local: false,
realMobile: true,
},
},
REST: {},
BrowserstackHelper: {
require: 'codeceptjs-bshelper',
user: BROWSERSTACK_USERNAME,
key: BROWSERSTACK_ACCESS_KEY,
shortUrl: false,
}
}
In the config, I explicitly specified the appiumVersion and didn't need to patch node_modules/codeceptjs/lib/helpers/WebDriver.js or node_modules/codeceptjs/lib/helpers/Appium.js. (At first I did, and I later removed the patches to see if the config still works). Seems to work. YMMV.
This is on CodeceptJS version 2.3.0, webdriverio version 5.12.4, codeceptjs-bshelper version 1.1.4.
Yeah using the "W3C protocol" instead of "legacy protocol" of BrowserStack fixes this issue for me as well. See the above example from @quekshuy how the new "W3C protocol" for BrowserStack looks like, I close this issue for now.
Most helpful comment
I did the following patch mechanism to temporarily fix this issue on our side:
Added "postinstall" to the "scripts" objects in the
package.json:Install "patch-package" via
npm i patch-package --save-devRemove the following lines from
node_modules/lib/helper/WebDriver.js:Run
npx patch-package codeceptjs.Commit the changes and the new patch file and start running your iOS tests on BrowserStack :)