docker-robot-framework
docker-robot-framework copied to clipboard
How to pass variables with spaces?
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.
-E space:_ and using _ instead of spaces seems to work, but this is deprecated. That's why I created this issue
Can you try MY_VARIABLE:This\ with\ spaces. ?
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.
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"'
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
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
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?
I think, i did this once:
robot -v "USERNAME:John Doe" greet_user.robot
Exclamation marks include the variable.
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.
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.
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...
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
Good catch, let me submit and see if that works
The PR has been merged but reopening this issue, as we need to add automated tests.
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.
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.