How to combine two booleans in Robot Framework - robotframework

I'm using robot framework to test if a webpage opens correctly. The webpage has two possible outcomes if everything works as planned:
${element_1_visible} = Run Keyword And Return Status Element should be visible element_1
${element_2_visible} = Run Keyword And Return Status Element should be visible element_2
These variables are always True and False, so a simple or operation should be enough. How do I combine these two booleans to test if my page works? So far have tried:
Should be True ${element_1_visible} or ${element_2_visible}
Should be True ${element_1_visible} == True or ${element_2_visible} == True
also:
${result} = ${element_1_visible} or ${element_2_visible}
Should be True ${result}

The statement that needs to be evaluated should be a single argument. This means prevent multiple spaces, as 2+ consequtive spaces is the divider between arguments.
Updated your example, this now works.
*** Test Cases ***
TC
${element_1_visible} Set Variable ${True}
${element_2_visible} Set Variable ${False}
Should be True ${element_1_visible} or ${element_2_visible}
Should be True ${element_1_visible}==True or ${element_2_visible}==True
${element_1_visible} Set Variable ${False}
${element_2_visible} Set Variable ${False}
Should not be True ${element_1_visible} or ${element_2_visible}
Should not be True ${element_1_visible}==True or ${element_2_visible}==True

Related

How to identify if a value is integer or number?

I want to identify if a value stored in a variable is an integer or not. If its an integer then it should return a Boolean value
I have tried using Built-In functions like Should be Equal As Numbers, Should be Equal As Integers but they did not work.
Since I am not so sound in Python, hence I was not able to make use of the Python built-in functions but I have a strong feeling that python functions like .isdigit() or .isnumeric() can come in handy here.
I am storing some value in a variable, say ${TestVariable}
Now, I have tried identifying the stored value as integer via following ways:
${Status} Run Keyword and Return Status Should be Equal As Numbers ${TestVariable} 1
Log to Console \n ${TestVariable}-${Status}
And I have passed values like
a,b,1,2
Since I have hard coded value 1 in Should Be Equal As Numbers, hence it returned True when the value stored in ${TestVariable} is 1 but returned False when the value was 2
Actual Result:
a-False
b-False
1-True
2-False
Expected Result:
I want Robot to return True when value is a number and False when its a character like below
a-False
b-False
1-True
2-True
Here is a possible solution, please note that "2e10" is converted to number, but the keyword does not consider that.
*** Test Cases***
Verify Types
FOR ${item} IN two ${None} 1235 2.567 2e10
${result}= Check Type ${item}
Log Item ${item} is ${result}
END
*** Keywords ***
Check Type
[Arguments] ${object}
[Documentation] Checks if the ${object } is INTEGER, NUMBER or STRING
Return From Keyword If not "${object}" NONE
${result} ${value}= Run Keyword And Ignore Error Convert To Number ${object}
${isnumber}= Run Keyword And Return Status Should Be Equal As Strings ${object} ${value}
${result} ${value}= Run Keyword And Ignore Error Convert To Integer ${object}
${isinteger}= Run Keyword And Return Status Should Be Equal As Strings ${object} ${value}
Return From Keyword If ${isnumber} NUMBER
Return From Keyword If ${isinteger} INTEGER
Return From Keyword STRING
if type(a) == int:
print('the value is integer')
a = "sabuj"
if type(a) == str:
print('the value is string')
a = [1,2,3]
if type(a) == list:
print('the value is List')

Why does this R function not short-circuit properly?

I'm working my way through the Data Science courses at DataCamp. (Not a plug.) One of the practice lessons has the following completed solution:
# logs is available in your workspace
extract_info <- function(x, property = "success", include_all = TRUE) {
info <- c()
for (log in x) {
if (include_all || !log$success) {
info <- c(info, log[[property]])
}
}
return(info)
}
# Call extract_info() on logs, no additional arguments
extract_info(logs)
# Call extract_info() on logs, set include_all to FALSE
extract_info(logs, include_all = FALSE)
The first call (extract_info(logs)) works as I would expect it to: it returns a vector containing all the log entries (regardless of the value of log$success).
The second call (extract_info(logs, include_all = FALSE)) does not return the results I would expect. It returns a vector containing only those results where log$success evaluates to FALSE.
It seems to me that the use of the || operator should cause the if block to short-circuit, and the second call should return nothing. From what I can tell, R evaluates expressions from left to right; but this looks like it's evaluating from right to left.
Can someone explain what's going on here?
(According to the site, this is the correct solution, and there's nothing wrong with the code. I want to know why it works the way it does. Even if the answer is that I'm overlooking something painfully obvious and stupid.)
Well || is the "or" operator. You don't short circuit the "or" operator with a FALSE value; you basically ignore that parameter and just look at the next one because you are looking for any TRUE value.
Assume a is a boolean value. These should be equivalent (<==>).
# or
FALSE || a <==> a
TRUE || a <==> TRUE
# and
TRUE && a <==> a
FALSE && a <==> FALSE
It seems like this was a temporary confusion.
|| is OR and so if either condition evaluates to TRUE, the compound expression evaluates to TRUE. If include_all was TRUE, you could short-circuit the expression, but when include_all is FALSE, you must wait to see what the other part is.

How to use both Run Keyword If and Run Keyword and Return Status?

file.robot
Keyword1
log this is keyword1
${some_value} = Set Variable Hello, world!
[Return] ${some_value}
file2.robot
Some_name
Run keyword If 'True' == 'True Run Keyword and return Status Keyword1
I want to use this way. How do i access the return value in file2.robot
Above, 'Some_name' in file2.robot calls the 'Keyword1', the return value 'some_value' to be printed in 'Some_name' of file2.robot.
How can it be achieved in one-liner as stated above ?
You cannot use a "Run keyword..." command and both get a return value and a pass/fail value. However, if all you need is the return value, Run keyword if will return the result of the keyword that it runs.
For example:
*** Test Cases ***
Example
${the_value}= run keyword if 'True' == 'True' keyword 1
With the above, keyword 1 will only run if the expression evaluates to true. ${the_value} will be set to the result of keyword 1.
If you need both the status and the returned value, you can use Run keyword and return status to run the keyword, but you'll have to modify the keyword to set a suite or global variable that your test can get after the keyword returns.

Compare FALSE expression in Robot Framework Test Cases

I'm having issue in negate the bool variable or comparison of FALSE against a bool variable to perform Run Keyword If
My Code is
Test Case
${isExist}= Run Keyword And Return Status Element Should Be Visible ${element_Id}
Run Keyword If ${isExist} == false click element ${cancelbtn}
Here I'm facing an Run time error
Evaluating expression 'True and' failed: SyntaxError: unexpected EOF
while parsing (, line 1)
I tried the following comparison too
${isExist} == 'false'
'${isExist}' == 'false'
${isExist} == ${false}
'${isExist}' == '${false}'
!${isExist}
Note: log to console ${isExist} - It logs the appropriate Boolean value in the console window.
if ${isExist} is a boolean, you can use not
Run Keyword If not ${isExist} ...
You can also compare to ${FALSE} or ${TRUE}:
Run Keyword If ${isExist} is ${FALSE} ...
Run Keyword If ${isExist} is not ${TRUE} ...
You say that ${isExist} == ${false} doesn't work, but it will if {isExist} is indeed the boolean value False.
Note: ${FALSE} and ${TRUE} are variables defined by robot. They are briefly mentioned in the documentation in the section titled Boolean and None/null variables in the robot framework user guide.

Check if ArgParse optional argument is set or not (in Julia)

This is essentially the same question as: Check if argparse optional argument is set or not, but in Julia, using Julia's ArgParse module.
Given an argument that takes a value, I want to know if its value was given or not.
In short, once you have parsed the arguments, you can check if an argument was set as parsed_args["argname"] == nothing (will return true if it was not set).
Find bellow a self-contained example (sightly modified example1 from ArgParse.jl) with 2 arguments that prints true if an argument was not set (just replace == with != for the opposite behaviour):
using ArgParse
function main(args)
# initialize the settings (the description is for the help screen)
s = ArgParseSettings(description = "Example usage")
#add_arg_table s begin
"--opt1" # an option (will take an argument)
"arg1" # a positional argument
end
parsed_args = parse_args(s) # the result is a Dict{String,Any}
println(parsed_args["arg1"] == nothing)
println(parsed_args["opt1"] == nothing)
end
main(ARGS)
And example command line calls (assuming above is stored in test.jl):
>>> julia test.jl
true
true
>>> julia test.jl 5
false
true
>>> julia test.jl 5 --opt1=6
false
false
>>> julia test.jl --opt1=6
true
false
However, sometimes it might be more appropriate to define a default value for the parameter rather than checking if it was set. It can be done by adding the default keyword to the parameter:
#add_arg_table s begin
"--opt1"
"--opt2", "-o"
arg_type = Int
default = 0
"arg1"
required = true
end
aswell as the required keyword for the positional parameters, which would force the user to introduce it.

Resources