简体   繁体   中英

Working with RobotFramework and Curl responses while using Variables

I am trying to test a gateway with a benign url and a phishing url. I am using SSHLibrary to connect to a machine, curl the URL and then check with "Should contain" if the output contains the page title or Connection was reset.

When testing the Benign URL, it works. The output of curl command looks like this - curl output of benign url:

I use ${variable} = execute command curl url and then should contain ${variable} Submit

And it works.

When I test the phishing URL, the variable does not contain any output as the connection is reset by the gateway.

When I run the curl command with the phishing URL I get -

curl: (56) Recv failure: Connection was reset

When I use the should contain with ${variable} Connection was reset, it doesn't work. I also tried ${variable.stdout} but the variable is still empty each time.

How can I process the connection was reset response and validate it was indeed reset?

The issue was the stream return on the curl command.

While stdout had no information, stderr had the information regarding the "connection was reset".

Even when I added return_stderr=True to "execute command", it did not work.

"execute command" keyword has a number of multiple return options, stdout enabled by default.

When using both the stdout and stderr, my variable became a list and the "should contain" keyword only checked the first record of the list [0]. The solution is to either disable the default stdout and enable stderr if we want to use one variable OR use multiple variables.

${variable} = execute command curl -v example.com return_stdout=False return_stderr=True

${stdout} ${stderr} ${rc} = execute command curl -v example.com return_stderr=True return_rc=True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM