Robot framework not allowing me to break message across multiple lines - robotframework

I've got the following code and it won't allow me to break my message over multiple lines. I've looked at over a dozen stack exchange questions but none of them work.
Should Be Equal As Integers ${ans} 0 msg=Failed stuff, the accepted value did not match. Expected value \n
... was between max and min, returned value is below this
It is giving me the error
Keyword 'BuiltIn.Should Be Equal As Integers' got positional argument after named arguments.
I've looked at the following links but they don't work
How I can write code in 2 lines in the Robot framework
Robot framework not allowing me to print over multiple lines

You can achieve this by using catenate:
${ans} = Convert To Integer 1
${message} = Catenate Failed stuff, the accepted value did not match. Expected value \n
... was between max and min, returned value is below this
Should Be Equal As Integers ${ans} 0 msg=${message}

Keep the error message on single line and you can Add ${\n} at the end of the string to get a newline character.
I think, you are using a kw which has positional argument it may not allow using real new line using ...
However, you can use Catenate keyword with SEPARATOR=\n as below:
${str3} = Catenate SEPARATOR=\n line1 text
... line2 text

Related

Can't Assign Value of Excel cell To variable in Robot Framework [duplicate]

I'm writing a test case in robot framework. I'm getting the response in below json string:
{"responseTimeStamp":"1970-01-01T05:30:00",
"statusCode":"200",
"statusMsg":"200",
"_object":{"id":"TS82",
"name":"newgroup",
"desc":"ttesteste",
"parentGroups":[],
"childGroups":[],
"devices":null,
"mos":null,
"groupConfigRules" {
"version":null,
"ruleContents":null
},
"applications":null,"type":0
}
}
From that I want to take "_object" using:
${reqresstr} = ${response['_object']}
... but am getting the error "No keyword with name '=' found" error
If I try the following:
${reqresstr}= ${response['_object']}
... I'm getting the error "Keyword name cannot be empty." I tried removing the '=' but still get the same error.
How can I extract '_object' from that json string?
When using the "=" for variable assignment with the space-separated format, you must make sure you have no more than a single space before the "=". Your first example shows that you've got more than one space on either side of the "=". You must have only a single space before the = and two or more after, or robot will think the spaces are a separator between a keyword and argument.
For the "keyword must not be empty" error, the first cell after a variable name must be a keyword. Unlike traditional programming languages, you cannot directly assign a string to a variable.
To set a variable to a string you need to use the Set Variable keyword (or one of the variations such as Set Test Variable). For example:
${reqresstr}= Set variable ${response['_object']}
${reqresstr}= '${response["_object"]}'
wrap it inside quotes and two spaces after =
There is a syntax error in your command. Make sure there is a space between ${reqresstr} and =.
Using your example above:
${reqresstr} = ${response['_object']}

How to find open and closing braces present in a string (a list converted into string)?

My requirement is to check whether the input is list or not using robot framework.
I tried using type(${temp}).name with evaluate function, which works in case of list and fails for string type.
Below is the error message -
Evaluating expression 'type(testdata).name' failed: SyntaxError: invalid token (, line 1)
Tried to use regex, but no luck.:(
Code :-
testRegEx
${match} Run Keyword Should Match Regexp ["swerwv","sfsdfdsf","edsfdf"] \[\s\S\]
Log To Console ${match}
output:-
FAIL : '["swerwv","sfsdfdsf","edsfdf"]' does not match '[\s\S]'
I'm new to robotframework. Any help would be appreciated.
My requirement is to check whether the input is list or not using robot framework.
You can use robot's special syntax for evaluate and the various keywords which accept expressions, where you omit the brackets in the variable reference to pass the actual variable to the expression (versus passing the value of the variable).
Example:
*** Variables ***
#{a_list} one two three
*** Test Cases ***
Test that variable is a list
run keyword unless type(a_list) == list
... Fail not a list
This feature is mentioned in the Evaluating expressions section of the built-in library.

robotframework: what is the easiest way to verify a value is bigger than 10

so there is a website: https://www.guruwatch.nl/Aandelen/Default.aspx
I click the element 'koop' and then I want to verify that the value in the top is bigger then 10
id="ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy"
what is the fastest way to do this?
i used
Element Text Should Be ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy 24
but that is for the exact match, i just want to verify the integer is bigger then 10.
there is also an
Should Be Equal As Integers first second
builtin
but not a
Should Be Bigger As Integer
Should be Smaller As Integer
p.s. why are those not builtin? is it so strange to use this?
There are plenty of ways of checking if one value is larger than another with the * If keywords that can be found in the BuiltIn Library. Below is an example of how you can craft the larger than keyword:
*** Test Cases ***
Test Positive
${value} Set Variable 24
Should Be Larger Than ${value} 1
Test Negative
${value} Set Variable 24
Run Keyword And Expect Error * Should Be Larger Than ${value} 100
*** Keywords ***
Should Be Larger Than
[Arguments] ${value_1} ${value_2}
Run Keyword If ${value_1} <= ${value_2}
... Fail The value ${value_1} is not larger than ${value_2}
In order to do this, you need to find the xpath locator first. Since the xpath is quite long so, I just assign it to a variable as below.
${top_position_xpath}= set variable //span[#id='ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy'
${get_number}= GET TEXT xpath=${top_position_xpath} ## --> This is xpath locator for that top column
${check}= SHOULD BE TRUE ${get_number} > 10 # --> The current test will fail if the result is false..
Okay, so I summarize the steps I use above here:
Get the xpath locator for the specific column that you want to verify.
Use the GET TEXT keyword to get the exact output (number) of that column.
Verify using the SHOULD BE TRUE keyword. This keyword is sufficient to verify the condition.
But just to highlight, that if you use the SHOULD BE TRUE keyword as above, the test will fail immediately, so a good approach is to use with keyword RUN AND RETURN STATUS and assign a variable to tell either the condition is true or false, so that you can proceed with your next code or statements..
${result}= RUN KEYWORD AND RETURN STATUS SHOULD BE TRUE ${get_number} > 10 #
Before I read the messages I solved it myself this way:
Should Match Regexp ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy [0-9]{1}[0-9]{1}

How I can write code in 2 lines in the Robot framework

colleagues!
Sometimes I have a very long string in the code, e.g. more than 200 symbols in a string.
Could I carry some trail to the new line in the Robot Framework code?
Thank you for your attention!
You can use the built-in keyword Catenate and the line continuation syntax (the triple dots ...)
${long var}= Catenate This is a long string
... that will be concatenated
# you can combine multiple Catenate calls, for formatting clarity:
${long var}= Catenate ${long var}, and it continues on
... multiple lines.
By default the different portions will be concatenated with a space, you can change that with the SEPARATOR argument (the case matters).

Robot "should be equal as strings"

I've got some code in a Robot script that will check a field value is as expected:
${search_box}= Get Value fullSearchBox
Should Be Equal As Strings ${search_string} ${search_box}
When I run the script, a failure is recorded against that verification step. However, when I look at the two strings, I can see no differences between them at all (I've also tried using Should Be Equal).
If the two strings are the same - why am I seeing this failure?
If there is some whitespace on one of the variables, you can strip the whitespace by calling .strip() using the extended variable syntax:
Should Be Equal As Strings ${search_string.strip()} ${search_box.strip()}

Resources