Anyone know is it possible for the keyword to keep same variable name as it received?
Following short example will add values to list.
Once it has been updated it needs to be set as a new variable (If i add "${first_list_values}" as test variable after new list insertion, it will only work with one specific list) and the same keyword can't be used anymore.
Id much rather use same keyword to loop multiple lists.
**Keyword**
Change List value
[Arguments] ${received_list}
${new_list} Insert Into List ${received_list} 0 xxx
Set Test Variable ${new_list}
**Test Cases*
Checking new list values
Change List value ${first_list_values}
Maybe something like this:
*** Settings ***
Library Collections
*** Variables ***
#{ORIGINAL_LIST} First Second
*** keywords ***
Change List value
[Arguments] ${received_list}
Append to List ${received_list} Appended Third Appended Fourth
[return] ${received_list}
*** Test cases ***
Use Return
Log To Console ORIGINAL_LIST: #{ORIGINAL_LIST}
#{ORIGINAL_LIST}= Change List value ${ORIGINAL_LIST}
Log To Console ORIGINAL_LIST AFTER CHANGE: #{ORIGINAL_LIST}
Related
Here I want to pass only specific variable value and should get other values as default but I am not getting that...
Ex: I want to pass only word2 variable value and want to get word1 value as default Like "Hello See"
*** Keywords ***
Check order
[Arguments] ${word1}=Hello ${word2}=World
log to console word1 is : ${word1}
log to console word2 is : ${word2}
*** Test Cases ***
Test case 1
Check order ${word2}=See
Test case 1 | FAIL |
Variable '${word2}' not found.
The way to do this is to use only the variable name to the left of the equals:
Check order word2=see
This is from the robot framework user guide, in a section titled Named arguments
When the named argument syntax is used with user keywords, the argument names must be given without the ${} decoration. For example, user keyword with arguments ${arg1}=first, ${arg2}=second must be used like arg2=override.
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}
I have a use case for which I have to automate the following steps:
Create an empty list
Push data into the empty list
Keep/save the original order in a variable
Sort the original order
Save the sorted list
Reverse the sorted list and return value
*** Settings ***
Library SeleniumLibrary
Library Collections
*** Keywords ***
Sort order verification
#{username_list}= Create List //creates an empty list
#{get_name}= Get WebElements css=#userTable > tbody > tr> td:nth-child(1)
:FOR ${each} IN #{get_name}
\ ${get_username}= Get Text ${each}
\ Append To List ${username_list} ${get_username} //pushes data into list in iteration
${original_order}= Copy list ${username_list} //returns original order
${sorted_list}= Sort List ${original_order} //sorts the list but returns none(nothing is saved in the variable
${reverse_sorted_list}= Reverse List ${sorted_list} //returns AttributeError: 'NoneType' object has no attribute 'reverse'
The Sort List and Reverse List keywords modify the list in-place, e.g. they change the value of the target variable.
They also don't return anything - thus on the lines you've used them, you have assigned the value None to the variables, which led to the error.
You can read about this behavior in the Collections library documentation
I'm trying to create a keyword that will export a list as a suite variable, but I can't figure out how to pass a name to turn into a variable name.
*** Test Cases ***
Get Ref
${list} = Create List k l m n e
Rename List myName ${list}
log #{myName}
*** Keywords ***
Rename List
[Arguments] ${name} ${values}
log first: ${values[1]}
#{name}= Create List ${values[1]} ${values[3]}
set suite variable #{name}
The keyword takes a string and a list, creates a smaller list and exports it with the name string provided.
As a use-case, you want a generic function that can take values from a dropdown list on a webpage and return you just item 1, 3, and 5 as a new list with the name you provide. This way you could call it multiple times with different names, exporting different lists that you could use later.
Is there any way to make this work?
This seems to do what you want, if I understand the question correctly:
*** keywords ***
rename list
[Arguments] ${name} ${values}
${new}= create list #{values}
set suite variable ${${name}} ${new}
I am trying to create a unique string by embedding epoch time stamp after a static string as:
*** Keywords ***
Unique Title
[Return] ${title}
${secs}= Get Time epoch
${time}= Convert To String ${secs}
{title}= Catenate SEPRATOR=- Title ${time}
*** Test Cases ***
Test_Enter_Unique_Text
Open Browser #{urlUnderTest}
Input Text name=alertTitle Unique Title
Its not working I am not able to get the return value of Unique Title keyword, in the input box text is getting entered as "Unique Title".
Any suggestions will be really helpful.
You have to call the keyword and save what it returns, then use the saved value in the test case:
*** Test Cases ***
Test_Enter_Unique_Test
${title}= Unique Title
...
Input Text name=alertTitle ${title}