electron-userland / spectron

DEPRECATED: 🔎 Test Electron apps using ChromeDriver
http://electronjs.org/spectron
MIT License
1.68k stars 229 forks source link

Application 'args' parameter order gets mixed up when too many arguments #306

Open proto-n opened 6 years ago

proto-n commented 6 years ago

Hi! After a fun debugging session I noticed the following bug: When you pass at least 11 arguments to the Application, for example:

let app = new Application({
    path: electronPath,
    args: [
        __dirname,
        '--a', '0',
        '--b', '1',
        '--c', '2',
        '--d', '3',
        '--e', '4',
    ],
})

The order gets messed up: the application receives

[
    "xyz/node_modules/electron/dist/electron",
    "xyz",
    "--a", "4",
    "0",
    "--b","1",
    "--c","2",
    "--d","3",
    "--e",
    "--disable-background-networking",
    "--disable-client-side-phishing-detection", 
    ... // bunch more chrome related stuff
]

This happens because the args are relayed to webdriverio as

['spectron-path=xyz/node_modules/electron/dist/electron',
         'spectron-arg0=xyz',
         'spectron-arg1=--a',
         'spectron-arg2=0',
         'spectron-arg3=--b',
         'spectron-arg4=1',
         'spectron-arg5=--c',
         'spectron-arg6=2',
         'spectron-arg7=--d',
         'spectron-arg8=3',
         'spectron-arg9=--e',
         'spectron-arg10=4' ]

and apparently webdriverio orders the arguments alphabetically (?). Left padding numbers with zeros to a fixed size fixes this.

Cheers

jdhiser commented 4 years ago

I just bumped into this exact issue when passing my 11th argument.

jdhiser commented 4 years ago

Pull request 18 fixes the issue, along with a test.

https://github.com/electron-userland/spectron/pull/588