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

aw protractor with multiCapabilities enabled fails with JSON.stringify error #413

Closed
PiotrNestor opened this issue Nov 16, 2018 · 9 comments

Comments

@PiotrNestor
Copy link

Description

The idea is to use Protractor to start multiple browser sessions to run the test suite.
The browser sessions could be in parallel or in sequense.

But:
aw protractor with multiCapabilities enabled fails with JSON.stringify error:

[11:15:28] E/launcher - TypeError: Map#toJSON isn't generic
at String.toJSON (...\node_modules\core-js\library\modules_collection-to-json.js:6:38)
at Function.toJSON (...\node_modules\core-js\library\modules_ctx.js:18:15)
at JSON.stringify ()

Steps to Reproduce

  1. Add multiCapabilities to aw.config.js
    multiCapabilities: [
      {
        name: 'desktop',
        browserName: 'chrome',
        chromeOptions: {
          args: [
            '--window-size=1024,768',
          ],
        },
      },
      {
        name: 'mobile',
        browserName: 'chrome',
        chromeOptions: {
          args: [
            '--window-size=375,667',
          ],
        },
      },
    ],
  1. Run tests
  2. ...
Expected behavior

Two browser sessions in parallel started by Protractor

Actual behavior

Error from Protractor:

[11:15:28] W/launcher - You have specified both capabilities and multiCapabilities. This will result in capabilities being ignored
[11:15:28] E/launcher - Map#toJSON isn't generic
[11:15:28] E/launcher - TypeError: Map#toJSON isn't generic
    at String.toJSON (...\node_modules\core-js\library\modules\_collection-to-json.js:6:38)
    at Function.toJSON (...\node_modules\core-js\library\modules\_ctx.js:18:15)
    at JSON.stringify (<anonymous>)
    at ChildProcess.target._send (internal/child_process.js:675:23)
    at ChildProcess.target.send (internal/child_process.js:586:19)
    at TaskRunner.run (...\node_modules\protractor\built\taskRunner.js:95:26)
    at createNextTaskRunner (...\node_modules\protractor\built\launcher.js:235:28)
    at helper.runFilenameOrFn_.then.then.then (...\node_modules\protractor\built\launcher.js:260:13)
    at _fulfilled (...\node_modules\q\q.js:834:54)
    at self.promiseDispatch.done (...\node_modules\q\q.js:863:30)
[11:15:28] E/launcher - Process exited with error code 199

Environment

Operating system
[ ] Windows 10

Versions

  • Node.js: v8.11.4
  • Webdriver: ChromeDriver 2.43
  • Operating system: Windows 10
  • [Other relevant versions]
@axelssonHakan
Copy link
Member

Could you please specify what AW version you use and if possible the whole aw.config.js

@PiotrNestor
Copy link
Author

PiotrNestor commented Nov 16, 2018

AW version: 5.1.1
aw.config.js.txt

@axelssonHakan
Copy link
Member

axelssonHakan commented Nov 16, 2018

Getting it to work with something like below:


module.exports = function initConfig() {
  return {
    multiCapabilities: [
      {
        name: 'desktop',
        browserName: 'chrome',
        directConnect: true,
        chromeOptions: {
          args: ['--window-size=1024,768'],
        },
      },
      {
        name: 'mobile',
        browserName: 'chrome',
        directConnect: true,
        chromeOptions: {
          args: ['--window-size=375,667'],
        },
      },
    ],
    specs: [path.resolve(__dirname, 'test/*.spec.js')],
    mochaOpts: {
      reporter: 'spec',
    },
  };
};

@PiotrNestor
Copy link
Author

No difference in my case if I try with the above 'aw.config.js' in my project code tree.
There could be some package.json dependency that uses the problematic JSON.stringify

@PiotrNestor
Copy link
Author

OK, I have some progress ...

1. I removed node-modules
2. Cleared 'packages.json' --> "devDependencies": {},
3. npm install --save-dev @after-work.js/aw

Now I should have node-modules restored because we just use after-works.js

4. Run tests with: npx aw protractor -c test\integration\aw.config.js
Fails:

npx: installed 1 in 2.142s
command not found: prefix
index.js protractor

Run protractor

Options:
  --version                    Show version number                                                             [boolean]
  --presetEnv                  Preset the test environment with Sinon, Chai, Sinon-Chai, Chai as promised and Chai
                               subset                                                                 [string] [default:
  "...\node_modules\@after-work.js\aw\node_modules\@after-work.js\cli\src\preset-
                                                                                                                env.js"]
  --config, -c                 Path to config file                                              [string] [default: null]
  --glob                       Glob pattern                                                       [string] [default: []]
  --coverage                   Generate coverage                                              [boolean] [default: false]
  --require                    Require path                                                        [array] [default: []]
  --hookRequire                Hook require to be able to mock and transform files             [boolean] [default: true]
  --babel.enable               Enable babel                                                    [boolean] [default: true]
  --babel.core                 Path to babel core module                                          [string] [default: ""]
  --babel.babelPluginIstanbul  Path to babel plugin istanbul module          [string] [default: "babel-plugin-istanbul"]
  --babel.options              Babel options                                                               [default: {}]
  --typescript                 Path to typescript compiler module                       [string] [default: "typescript"]
  -h, --help                   Show help                                                                       [boolean]

Can not get babel core module

5. To satisfy after-work.js dependencies I've added then to our project's package.json all after-work.js 5.1.1 dependencies as in its github source

"devDependencies": {
    "@after-work.js/aw": "^5.1.1",
    "@babel/core": "7.1.5",
    "@babel/plugin-transform-react-jsx": "7.0.0",
    "@babel/preset-env": "7.1.5",
    "@types/chai": "4.1.7",
    "@types/mocha": "5.2.5",
    "babel-plugin-istanbul": "5.1.0",
    "coveralls": "3.0.2",
    "eslint": "5.9.0",
    "eslint-config-airbnb": "17.1.0",
    "eslint-plugin-import": "2.14.0",
    "eslint-plugin-jsx-a11y": "6.1.2",
    "eslint-plugin-react": "7.11.1",
    "globby": "8.0.1",
    "lerna": "3.4.3",
    "protractor": "5.4.1",
    "requirejs": "2.3.6",
    "typescript": "3.1.6",
    "yargs": "12.0.2"
  },

6. npm install
7. Run tests again with: npm run test:integration
Fails:

> aw protractor -c test/integration/aw.config.js

[16:29:49] W/launcher - You have specified both capabilities and multiCapabilities. This will result in capabilities being ignored
[16:29:49] I/launcher - Running 2 instances of WebDriver
[16:29:59] I/testLogger -
------------------------------------

[16:29:59] I/testLogger - [chrome #01] PID: 60972
[chrome #01] [16:29:50] I/local - Starting selenium standalone server...
[chrome #01] [16:29:52] I/local - Selenium standalone server started at http://172.20.46.209:52175/wd/hub
[chrome #01] [16:29:58] I/runnerCli - options.reporterPlugin.getBrowser is not a function

[16:29:59] I/testLogger -

[16:29:59] E/launcher - Runner process exited unexpectedly with error code: 1
[16:29:59] I/launcher - 1 instance(s) of WebDriver still running
[16:29:59] I/testLogger -
------------------------------------

[16:29:59] I/testLogger - [chrome #11] PID: 28356
[chrome #11] [16:29:50] I/local - Starting selenium standalone server...
[chrome #11] [16:29:52] I/local - Selenium standalone server started at http://172.20.46.209:50323/wd/hub
[chrome #11] [16:29:59] I/runnerCli - options.reporterPlugin.getBrowser is not a function

[16:29:59] I/testLogger -

[16:29:59] E/launcher - Runner process exited unexpectedly with error code: 1
[16:29:59] I/launcher - 0 instance(s) of WebDriver still running
[16:29:59] I/launcher - chrome #01 failed with exit code: 1
[16:29:59] I/launcher - chrome #11 failed with exit code: 1
[16:29:59] I/launcher - overall: 2 process(es) failed to complete
[16:29:59] E/launcher - Process exited with error code 100

@axelssonHakan
Copy link
Member

Great progress!
Try to add a mocha.opts reporter (seems to be something with the default reporter then running multiCapabilities (will check it more on monday)

    mochaOpts: {
      reporter: 'spec',
    },

@axelssonHakan
Copy link
Member

If just running chrome and locally you can try to add the directConnect: true option as well do avoid having selenium as a dependency

@PiotrNestor
Copy link
Author

With the above suggestions:
1. Problems with 'chai':
ReferenceError: expect is not defined
2. I suppose we want the 'after-work' reporter

@axelssonHakan
Copy link
Member

Sorry for not answering yesterday. Then using multiCapabilities protractor is spawning new processes per capability and the global is not "shared". This is making some of the features in AW to "brake". Chai etc is not exposed and the default mocha reporter doesn't pick up browsers correctly. It´s still possible to use it but you have to require chai in your tests and if you want the default reporter you could first log to JSON and run the https://github.com/qlik-oss/after-work.js/blob/master/commands/protractor/src/plugins/reporter/aggregate.js afterwards.

For now I would suggest to run the test in parallel using different configs

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

No branches or pull requests

2 participants