Is it possible to write a test case where the entire test case is a while loop and the condition of the while loop is
while test.status == failed
Run this test
Generate a test result
end while
Is it possible to write a test case where the entire test case is a while loop and the condition of the while loop is
while test.status == failed
Run this test
Generate a test result
end while
Hi @CSUThornton,
By default once a test fails it exits, so your while would never be true.
It’s not clear what you are trying to acheive, perhaps if you describe the problem you’re trying to solve here we can suggest some better ways to acheive what you want.
Having said that, if you put Run this test
and Generate a test result
into a keyword and call it with Wait Until Keyword Succeeds you’d have something similar to what you described. Bearing in mind if any keyword in Run this test
fails Generate a test result
won’t be run.
Builtin library also has other keywords that might be useful like:
It really depends on what your trying to do as to what the best option is.
Hope that helps,
Dave.
This is what I’m trying to do:
MUST support NAT6to4 Device
[Documentation] Check translations
[Tags] 00000000001
BuiltIn.Sleep 5 seconds
SSH to host ${SRVR} ${USER} ${PASS}
WRITE ping6 -c 20 -s 1500 1:1:1::1 -I ens224
${output} get_config ${connection_en} ${TRANSLATIONS}
Log ${output}
${status} = nat_check ${6to4NAT_IP1} ${6to4NAT_IP2} ${6to4NAT_IP3} ${6to4NAT_IP4} ${output}
Should be Equal ${status} ${TRUE}
IF ${status} == ${TRUE}
SET SUITE VARIABLE ${NAT6to4_result} 1
END
WHILE True ${NAT6to4_result} = 0
BuiltIn.Sleep 5 seconds
SSH to host ${SRVR} ${USER} ${PASS}
WRITE ping6 -c 20 -s 1500 1:1:1::1 -I ens224
${output} get_config ${connection_en} ${TRANSLATIONS}
Log ${output}
${status} = nat_check ${6to4NAT_IP1} ${6to4NAT_IP2} ${6to4NAT_IP3} ${6to4NAT_IP4} ${output}
Should be Equal ${status} ${TRUE}
IF ${status} == ${TRUE}
SET SUITE VARIABLE ${NAT6to4_result} 1
END
END
Log To Console \n\nIPv6_Dest_result equals: ${NAT6to4_result}
${output} get_config ${connection_en} ${CLEAR_TRANSLATIONS}
BuiltIn.Sleep 5 seconds
${output} = Run sudo route del -net 2.2.2.0 netmask 255.0.0.0
${output} = Run sudo route -6 del 1:1:1::/64
${result1} = Run route
Should Not Contain ${result1} 2.2.2.0
${result2} = Run route -6
Should Not Match Regexp ${result2} ${IPV6ROUTE}
Close SSH
BuiltIn.Sleep 30 seconds
Close connection
BuiltIn.Sleep 30 seconds
The problem is that Robot keeps coming back with:
------------------------------------------------------------------------------
MUST support NAT6to4 Device :: Check translations | FAIL |
'While' is a reserved keyword.
------------------------------------------------------------------------------
I’m following the syntax provided in the following link:
[While loops in Robot Framework | Robocorp documentation](I’m following the syntax provided in the following link: While loops in Robot Framework | Robocorp documentation I’m not sure what the issue is.)
I’m not sure what the issue is.
Yeah your using the WHILE loop wrong, the second argument is a optional one that is “limit” and by default it has a limit of 10000, the first which happens to be “True” in your test means it will never evaluate to anything else, but this will be where you’d evaluate for it to exit or not, I’d imagine you’d be wanting to check if ${NAT6to4_result} is equal 0 here based on what you’ve provided.
Please be aware an exception will be thrown when using a limit if the condition is never met (limit is met)so you’d want to handle it.
Hope that helps
Thanks
Sorry in addition and I wouldn’t recommend it, If you really wanted to loop infinitely, you can set the limit
argument to NONE
, but I’d recommend setting appropriately based on your understanding of the application.
You’d want to wrap in a try catch to capture the exception as well if the limit is met.