DevExpress / testcafe-browser-provider-electron

This is the Electron browser provider plugin for TestCafe.
https://testcafe.io
MIT License
49 stars 30 forks source link

appArgs inside Configuration file doesn't allow whitespaces ( ) or quotation marks (") #111

Open carvedcow opened 6 months ago

carvedcow commented 6 months ago

Hi, I'm trying to use app arguments for my executable electron application but I'm having 2 issues.

  1. If an argument contains a white space, it would automatically add quotation marks around the argument:
    {
    "mainWindowUrl": "./index.html",
    "appArgs": ["--test:1"]
    }
    vs
    {
    "mainWindowUrl": "./index.html",
    "appArgs": ["--test: 1"]
    }

Here is the app's arguments in Task Manager: image vs image

  1. Quotation marks aren't escaped properly and breaks escape characters:
    {
    "mainWindowUrl": "./index.html",
    "appArgs": ["--location=C:\\"]
    }
    vs
    {
    "mainWindowUrl": "./index.html",
    "appArgs": ["--location=\"C:\\\""]
    }

    image vs image

Thank you very much for your time.

PavelMor25 commented 6 months ago

Hello @carvedcow,

It's expected that an argument containing a space is wrapped in quotes because this allows you to pass a single argument as a string. If you need to obtain a string like --test: 1, split your argument into two and write it in appArgs: "appArgs": ["--test:", "1"].

In the second case, try enclosing your path in single quotes: "appArgs": ["--location='C:'"].

Please let us know your results.

carvedcow commented 6 months ago

Hi @PavelMor25,

Thank you very much for your reply.

The multiple arguments trick worked for white spaces.

For the quotation marks however, the electron application requires double quotation marks. I've tried ' and ` and both wouldn't work.

Is there no way to have quotation marks (") inside an app argument?

Best regards,

PavelMor25 commented 6 months ago

You can try using a JavaScript configuration file instead of JSON:

module.exports = {
    mainWindowUrl: './index.html',
    appArgs: ['--test:', '1', '--location="C://"'],
}
carvedcow commented 6 months ago

After using:

module.exports = {
    mainWindowUrl: './index.html',
    appArgs: ['--test:', '1', '--location="C://"'],
}

The backslash and quotation marks would show up: image

PavelMor25 commented 6 months ago

Can you share a minimal working example? I will try find a solution for your usage scenario. Currently, I can't determinate where the issue occurs.

carvedcow commented 5 months ago

Apologies for the late response, here is a minimal working example: https://github.com/carvedcow/test_hello_world

The goal is to be able to run the testScript.js script on the test.exe electron application with the app arguments provided in .testcafe-electron-rc.js.

When I launch the test, the argument I want testcafe to use for the app is: test.exe --test=".\test folder\test.html" but I can't get the proper formatting.

Thank you

PavelMor25 commented 5 months ago

Hello @carvedcow,

Thank you for sharing the code.

Could you modify the example so that we can reproduce your scenario or that it shows exactly which arguments are passed into the application? Currently, when running testScript.js, the test passes, and we can't determine the issue.

carvedcow commented 5 months ago

Hi @PavelMor25,

I've updated the code to display the argument being passed from .testcafe-electron-rc.js to testScript.js but the actual argument being used by test.exe is displayed under the Details tab in the Task Manager during test.exe's runtime.

Thank you.

github-actions[bot] commented 5 months ago

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.