docker-robot-framework icon indicating copy to clipboard operation
docker-robot-framework copied to clipboard

How to pass variables with spaces?

Open VMM-Mtech opened this issue 6 years ago • 16 comments

Hi!

Running docker on windows. Following is my simple test case:

*** Test Cases ***
Test
    Should Be Equal  This with spaces  ${MY_VARIABLE}

If I run the test directly with robot like this, it succeeds:

robot --variable MY_VARIABLE:"This with spaces" robot

But if I try to run it with your docker image, it fails

docker run -v %cd%/reports:/opt/robotframework/reports:Z -v %cd%/robot:/opt/robotframework/tests:Z -e ROBOT_OPTIONS="--loglevel DEBUG --extension robot -v MY_VARIABLE:\"This with spaces\" " my_docker_image

The error message is "[ ERROR ] Parsing 'with' failed: File or directory to execute does not exist."

I've tried with singe quotes, single quotes escaped etc, and I just can't get this to work.

VMM-Mtech avatar Sep 02 '19 13:09 VMM-Mtech

-E space:_ and using _ instead of spaces seems to work, but this is deprecated. That's why I created this issue

VMM-Mtech avatar Sep 02 '19 13:09 VMM-Mtech

Can you try MY_VARIABLE:This\ with\ spaces. ?

UltimateDogg avatar Sep 02 '19 14:09 UltimateDogg

docker run -v %cd%/reports:/opt/robotframework/reports:Z -v %cd%/robot:/opt/robotframework/tests:Z -e ROBOT_OPTIONS="--loglevel DEBUG --extension robot -v MY_VARIABLE:This\ with\ spaces" my_docker_image [ ERROR ] Parsing 'with\' failed: File or directory to execute does not exist.

VMM-Mtech avatar Sep 03 '19 05:09 VMM-Mtech

hmm, how about docker run -v %cd%/reports:/opt/robotframework/reports:Z -v %cd%/robot:/opt/robotframework/tests:Z -e ROBOT_OPTIONS='--loglevel DEBUG --extension robot -v MY_VARIABLE:"This with spaces"'

UltimateDogg avatar Sep 03 '19 11:09 UltimateDogg

Even worse.

docker: invalid reference format: repository name must be lowercase.

And as far as I know, we can't just drop double quotes from ROBOT_OPTIONS since we want to inject some variables there

VMM-Mtech avatar Sep 03 '19 12:09 VMM-Mtech

https://stackoverflow.com/questions/56059255/docker-environment-variable-with-spaces

Ok this leads me to believe if even json notation doesnt work we dont have the correct escaping in the docker container itself

UltimateDogg avatar Sep 03 '19 13:09 UltimateDogg

If I looked at your code correctly, docker will run the run-tests-in-virtual-screen.sh script, right? Could you test if you could do some escaping or something there?

VMM-Mtech avatar Sep 04 '19 05:09 VMM-Mtech

I think, i did this once: robot -v "USERNAME:John Doe" greet_user.robot Exclamation marks include the variable.

Noordsestern avatar Sep 04 '19 11:09 Noordsestern

docker run -v %cd%/reports:/opt/robotframework/reports:Z -v %cd%/robot:/opt/robotframework/tests:Z -e ROBOT_OPTIONS="--loglevel DEBUG --extension robot -v \"MY_VARIABLE:This with spaces\"" my_docker_image

[ ERROR ] Parsing 'with' failed: File or directory to execute does not exist.

VMM-Mtech avatar Sep 04 '19 13:09 VMM-Mtech

after several hours and about 50 combinations, i could not find a way to get it to work, even changing the .sh file. I think we could it to work by splitting each option into a separate -e but that is a lot of work and makes this very brittle. space:_ actually did work however but thats deprecated as you said. Maybe its time to ask for that to stay.

UltimateDogg avatar Sep 04 '19 22:09 UltimateDogg

Hi,

refreshing this one. The escape (or -E) worked with 3.6.0, but does not work at all with 3.7.0.

docker run -v %cd%/reports:/opt/robotframework/reports:Z -v %cd%/robot:/opt/robotframework/tests:Z -e ROBOT_OPTIONS="--loglevel DEBUG --extension robot -v MY_VARIABLE:This_with_spaces -E space:_" ppodgorsek/robot-framework:3.7.0
[ ERROR ] option -E not recognized

I guess there is no new options for me, but to use older versions? I'd like to upgrade to the newest since there are some random issues occuring between geckodriver and firefox that hopefully would work better in newer versions...

VMM-Mtech avatar Dec 17 '20 10:12 VMM-Mtech

For informations, I had the same problem by setting a custom user-agent.

TL;DR; : You should double quote the $@ in bin/chromium-browser.sh and bin/chromedriver.sh files :

#!/bin/sh

exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox "$@"

Here my question (and the working solution too) : https://stackoverflow.com/questions/65995818/robot-framework-calling-add-argument-with-spaces

PapsOu avatar Feb 02 '21 09:02 PapsOu

Good catch, let me submit and see if that works

UltimateDogg avatar Feb 02 '21 15:02 UltimateDogg

The PR has been merged but reopening this issue, as we need to add automated tests.

ppodgorsek avatar Feb 02 '21 17:02 ppodgorsek

I'm not convinced that the fix PapsOu suggested will solve the whole issue since my issue was with RF itself and not the chrome in the container.

VMM-Mtech avatar Feb 03 '21 08:02 VMM-Mtech

Updating the situation:

We finally were forced to update to v. 3.8.0, where we couldn't use the -E flag anymore. So our workaround now is to pass the variables with underscores to our Robot scripts, and then replace the underscores with spaces for each variable before they are used. Not the most elegant solution, but luckily we only have a couple of variables and they are used just once, so the replacement needs to happen only in couple of places.

But as @UltimateDogg said in https://github.com/ppodgorsek/docker-robot-framework/issues/194#issuecomment-528122598, I guess the original problem still remains.

VMM-Mtech avatar Mar 28 '23 05:03 VMM-Mtech