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

[Possible BUG] MJSONWP protocol requires type and ms" and you sent {"script": 1000} #1529

Closed
raquelgs opened this issue Feb 27, 2019 · 30 comments · Fixed by #1807
Closed

[Possible BUG] MJSONWP protocol requires type and ms" and you sent {"script": 1000} #1529

raquelgs opened this issue Feb 27, 2019 · 30 comments · Fixed by #1807

Comments

@raquelgs
Copy link

Hello,

What are you trying to achieve?

I'm using Codeceptjs with webdriverio and browserstack (automate) and I’m facing an issue related with MJSONWP endpoint to fetch the timeouts and makes my test suite to crash.

What do you get instead?

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)

Details

  • CodeceptJS version: 2.0.4

  • NodeJS Version: 10

  • Operating System: Mac OS 10.13

  • WebDriverIO 5.6.3

  • 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

@elukoyanov
Copy link
Collaborator

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.

@raquelgs
Copy link
Author

raquelgs commented Mar 1, 2019

@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.

@elukoyanov
Copy link
Collaborator

@raquelgs, which two options did you use?

Can You place config for android, if it works?

@raquelgs
Copy link
Author

raquelgs commented Mar 4, 2019

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}

@raquelgs
Copy link
Author

raquelgs commented Mar 7, 2019

@LukoyanovE I've been checking with webdriverio 4.14.1 and same test on iOS works. Here the traces:

[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

@raquelgs
Copy link
Author

@LukoyanovE Do you have any update? Thanks!

@vigneshshanmugam
Copy link

vigneshshanmugam commented Mar 22, 2019

Seems like a bug in appium - appium/ruby_lib_core#128, But the fix itself has landed in 1.9.1 and still the issue exists. Worth a try with the new appium release.

@lokesh-rj
Copy link

Hi, Is this issue resolved?

@raquelgs
Copy link
Author

raquelgs commented Apr 8, 2019

@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

@danieltisdale
Copy link

@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.

@raquelgs
Copy link
Author

@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)

@nagamanickamm
Copy link

@raquelgs : is this issue resolved?
I'm facing the same issue in IOS devices, but the same code is working in Android.

@pablopaul
Copy link
Collaborator

I have the same problem.

@raquelgs what does the BrowserStack support answered, could they help you to fix it?

@raquelgs
Copy link
Author

@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}'.

@pablopaul
Copy link
Collaborator

thanks @raquelgs I am confused now :)

@valishah
Copy link

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?

@michaeldrews
Copy link

Seeing this issue when testing on Sauce Labs iOS Real Devices (aka TestObject)...

@pablopaul
Copy link
Collaborator

@michaeldrews which Appium version is running on Sauce Labs in your case?

@michaeldrews
Copy link

@pablopaul seeing this when using Appium 1.9.1 and 1.13.0

@pablopaul
Copy link
Collaborator

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.

@pablopaul
Copy link
Collaborator

@michaeldrews can you please double check the Appium version on iOS you used?

@valishah
Copy link

@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

@pablopaul
Copy link
Collaborator

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.

@pablopaul
Copy link
Collaborator

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?

See appium/appium#12991

@pablopaul
Copy link
Collaborator

For reference webdriverio/webdriverio#4273

@pablopaul
Copy link
Collaborator

pablopaul commented Jul 30, 2019

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 :)

@prasadam
Copy link

prasadam commented Aug 6, 2019

@pablopaul , with this new patch added in your previous reply, will this work on Sauce Labs also on Appium 1.13.0?

@valishah
Copy link

valishah commented Aug 6, 2019

@prasadam: Yes, It does work.

@quekshuy
Copy link
Contributor

quekshuy commented Sep 2, 2019

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.

@pablopaul
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.