browserstack / nightwatch-browserstack

Selenium examples for Nightwatch and BrowserStack Automate
https://www.browserstack.com
77 stars 62 forks source link

Error while running .executeScript() protocol action: Invalid Command #33

Open lunayui opened 4 years ago

lunayui commented 4 years ago

I'm starting the BrowserStackLocal process via local.runner.js. and Nightwatch coverage code

But the build-in Jenkins is still failing and shows the error :

Response 500 POST https://hub-cloud.browserstack.com/wd/hub/execute (163ms) { value: { message: 'Invalid Command', error: [] } } Error while running .executeScript() protocol action: Invalid Command { status: -1, state: '', value: { message: 'Invalid Command', error: [] }, errorStatus: '', error: 'Invalid Command', httpStatusCode: 500 } Error: Error while running "execute" command: An error occurred while gathering coverage information at at process._tickCallback (internal/process/next_tick.js:189:7) nightwatch.conf.js

globals_path: path.resolve(constants.NIGHTWATCH_CONFIGS_PATH, 'globals.js'), custom_commands_path: [ 'node_modules/nightwatch-coverage/commands' ],

global.js `const path = require('path'); const { createCoverageReporter } = require('nightwatch-coverage');

const coverageReporter = createCoverageReporter({ coverageDirectory: path.join(process.cwd(), 'tests/colosseum/coverage'), });

module.exports = {

coverageReporter, abortOnAssertionFailure: true, waitForConditionPollInterval: 500, waitForConditionTimeout: 5000,

// executed after every test suite has ended afterEach(browser,done) { console.log("Nigthwach Browser " + browser.collectCoverage()); browser.collectCoverage(function () { client.end(done); }); },

//executed after the test run has finished

after(done) { console.log("coverage report "+coverageReporter); coverageReporter.save(); done(); } }`

RohanImmanuel commented 4 years ago

Hi @lunayui, can you share the capabilities used for the test, while retracting your credentials.

I suspect that a JSONWire Protocol endpoint '/execute' was sent to what appears to a session using the newer W3C Webdriver Protocol, which expects the endpoint '/execute/sync' causing the error.

JSONWire Protocol: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidexecute W3C Webdriver Protocol: https://www.w3.org/TR/webdriver/#execute-script

lunayui commented 4 years ago

this is my nightwatch_config

nightwatch_config = { src_folders: [source_path], selenium: { start_process: false, host: 'hub-cloud.browserstack.com', port: 443 }, globals_path: 'globals.js', custom_commands_path: [ 'node_modules/nightwatch-coverage/commands' ], test_settings: { default: { // Used for the aynchronous browser.perform command // 30 minutes globals: { asyncHookTimeout: 1800000 }, request_timeout_options: { timeout: 600000 }, desiredCapabilities: { project: BROWSERSTACK_PROJECT, build: BROWSERSTACK_BUILD, 'browserstack.user': XXXXXX, 'browserstack.key': XXXXXX, 'browserstack.local': true, 'browserstack.networkLogs': false, 'browserstack.localIdentifier': BROWSERSTACK_BUILD, browser: 'chrome', browser_version: '83.0', // The latest version of chrome os: 'Windows', os_version: '10', resolution: '2048x1536' // maximum resolution supported on browserstack. } } } }; // Code to copy seleniumhost/port into test settings for (var i in nightwatch_config.test_settings) { var config = nightwatch_config.test_settings[i]; config['selenium_host'] = nightwatch_config.selenium.host; config['selenium_port'] = nightwatch_config.selenium.port; config['desiredCapabilities'] = config['desiredCapabilities'] || {}; }

module.exports = nightwatch_config;

abhi291096 commented 4 years ago

Hello, could you please try executing a test with Nightwatch v.1.3.4 and share the output? I executed a sample test and the command ".execute("document.readyState")"worked fine. Sample session: https://automate.browserstack.com/builds/fbb7c6463835662567d5feb4cd5215db4d26fbf7/sessions/354d6e134ef82a503bdf1342c1b8354043b23f6a?auth_token=20643b00980d140fa4175dab201dc56cf1ae46ba6d14fb7ef824cc9362d2af8e

lunayui commented 4 years ago

Hello, I update Nightwatch v.1.3.4 and the latest but the error was change for :

[0;36m[Run All] Test Suite
10:46:27  ====================
10:46:27  - Connecting to hub-cloud.browserstack.com on port 443...
10:46:27  
10:46:27  Connecting to BrowserStack Local...
10:46:27  ⚠ Error connecting to hub-cloud.browserstack.com on port 443.
10:46:27  Nigthwach Browser Nightwatch API
10:46:27     Response 500 POST https://hub-cloud.browserstack.com/wd/hub/execute (161ms)
10:46:27     { value: { message: 'Invalid Command', error: [] } }
10:46:27   Error while running .executeScript() protocol action: Invalid Command
10:46:27  
10:46:27  { status: -1,
10:46:27    state: '',
10:46:27    value: { message: 'Invalid Command', error: [] },
10:46:27    errorStatus: '',
10:46:27    error: 'Invalid Command',
10:46:27    httpStatusCode: 500 }
10:46:27     Error: Error while running "execute" command: An error occurred while gathering coverage information
10:46:27         at <anonymous>
10:46:27  
10:46:27    See more info, video, & screenshots on Browserstack:
10:46:27    https://automate.browserstack.com/builds/undefined/sessions/undefined
10:46:27  _________________________________________________
10:46:27  
10:46:27  TEST FAILURE: 2 errors during execution; 0 tests failed, 0 passed (1.259s)
10:46:27  
10:46:27   ✖ runAll
10:46:27     Error while running "execute" command: An error occurred while gathering coverage information
10:46:27  Error: Error while running "execute" command: An error occurred while gathering coverage information
10:46:27      at <anonymous>

10:46:27  
10:46:27    Error: An error occurred while retrieving a new session: "[browserstack.local] is set to true but local testing through BrowserStack is not connected."
10:46:27         at endReadableNT (_stream_readable.js:1064:12)
10:46:27         at _combinedTickCallback (internal/process/next_tick.js:139:11)
10:46:27  
10:46:27  
10:46:27    Error: Error while running "execute" command: An error occurred while gathering coverage information
10:46:27         at <anonymous>
shawnlobo96 commented 4 years ago

Hey @lunayui

I have reached out to you over email for further steps to get this working.

kavyajain-qa commented 2 years ago

Hi @shawnlobo96 I am stuck with a similar issue. Can you pls help me with the further steps too? Thanks!

browserstack-support commented 2 years ago

Hello, Thank you for reaching out to us. We are working on your issue -706829 and will get back to you soon with an update. Please let us know if you have any more questions, we will be happy to help.  Regards, Utkarsh Sharma BrowserStack Support BrowserStack Docs BrowserStack FAQs

                        On
                        Fri, 8 Jul at  9:10 AM
                        ,  browserstack/nightwatch-browserstack ***@***.***>  wrote:

Hi @shawnlobo96 I am stuck with a similar issue. Can you pls help me with the further steps too? Thanks!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>