CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Option --override fails on Windows: Unexpected token in JSON

Open mirao opened this issue 8 years ago • 5 comments

What are you trying to achieve?

I'm trying to override the version of Android device using Appium

> ./node_modules/.bin/codeceptjs run --override '{"helpers": {"Appium": {"desiredCapabilities"
: {"platformVersion": "8.1"}}}}'

What do you get instead?

The command fails:

undefined:1
{helpers: {Appium: {desiredCapabilities: {platformVersion: 8.1}}}}
 ^

SyntaxError: Unexpected token h in JSON at position 1
    at JSON.parse (<anonymous>)
    at Command.module.exports (C:\workspace\codeceptjs\node_modules\codeceptjs\lib\command\run.js:22:33)
    at Command.listener (C:\workspace\codeceptjs\node_modules\commander\index.js:315:8)
    at emitTwo (events.js:126:13)
    at Command.emit (events.js:214:7)
    at Command.parseArgs (C:\workspace\codeceptjs\node_modules\commander\index.js:651:12)
    at Command.parse (C:\workspace\codeceptjs\node_modules\commander\index.js:474:21)
    at Object.<anonymous> (C:\workspace\codeceptjs\node_modules\codeceptjs\bin\codecept.js:137:9)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)

I tried it in PowerShell and cmd.exe, both fail. When I use the same command on Linux (Ubuntu 18.04) or in WSL Ubuntu 18.04 on Windows 10, it works fine.

Details

  • CodeceptJS version: 1.3.2
  • NodeJS Version: 8.11.4
  • Operating System: Windows 10
  • Configuration file:
{
  "output": "./output",
  "helpers": {
    "Appium": {
      "platform": "Android",
      "device": "emulator",
      "desiredCapabilities": {
        "app": "my.apk",
        "appWaitActivity": "com.myapp.android.controllers.activities.ProvisioningSelection",
        "platformName": "Android",
        "platformVersion": "7.1",
        "autoGrantPermissions": true,
        "noReset": true
      }
    },
    "Mochawesome": {}    
  },
  "include": {
    "I": "./steps_file.js",
    "loginPage": "./pages/login.js",
    "commonPage": "./pages/common.js"
  },
  "mocha": {
    "reporterOptions": {
      "codeceptjs-cli-reporter": {
        "stdout": "-",
        "options": {
          "verbose": false,
          "steps": true
        }
      },
      "mochawesome": {
        "stdout": "./output/console.log",
        "options": {
          "reportDir": "./output",
          "reportFilename": "report"
        }
      }
    }
  },
  "bootstrap": false,
  "teardown": null,
  "hooks": [],
  "gherkin": {},
  "tests": "./*_test.js",
  "timeout": 10000,
  "name": "codeceptjs"
}

mirao avatar Aug 19 '18 14:08 mirao

Hi @mirao I've had the same issue. When using powershell escaping the quotes should fix the issue.

./node_modules/.bin/codeceptjs run --override '{\"helpers\": {\"Appium\": {\"desiredCapabilities\"
: {\"platformVersion\": \"8.1\"}}}}'

DawidTabak avatar Sep 03 '18 13:09 DawidTabak

@DawidTabak : You're right, escaping works in powershell. Thanks.

mirao avatar Oct 04 '18 17:10 mirao

@mirao I use the override too:

"Android-8.1": "codeceptjs run -c ./devices_config/android.json --override '{\"helpers\": {\"Appium\": { \"desiredCapabilities\": {\"deviceName\": \"emulator-5554\", \"platformVersion\": \"8.1\", \"autoGrantPermissions\": true, \"customName\": \"Nexus 6\" }}}}'"

eduardofinotti avatar Apr 30 '19 10:04 eduardofinotti

In ConEmu (not sure if that's a factor here) I have to use "double quotes" and escape the quotes inside the string. Single quotes fail.

isapir avatar Dec 04 '19 19:12 isapir

It could be a behavior/limitation of Windows shells (PowerShell, cmd.exe). A solution exists: Escape double quotes Closing.

mirao avatar Dec 07 '19 14:12 mirao