I'm able to pick a random number from a list but now I don't know how to use the if-else statement so that it should match to condition to get further details with that number.
I tried doing it with "Run Keyword If" command but it didn't work out for me. Also tried using "For loop" as well and it didn't work out as well.
*** Variables ***
#{PARTY} ABC XYZ RTY DOG
*** Test Cases ***
View all Details
${value} = Evaluate random.choice($PARTY) random
input text ${SEARCH_BAR} ${value}
log to console \nvalue: ${value}
click element ${SEARCH_BUTTON}
:for ${ELEMENT} IN #{PARTY}
\ log ${ELEMENT}
\ run keyword if '#{ELEMENT}' == 'ABC'
\ ... else if '#{ELEMENT}' == 'XYZ'
\ ... else if '#{ELEMENT}' == 'RTY'
\ ... else '#{ELEMENT}' == 'DOG'
Expected Result: Now when the random value is picked, the value should be compared with the list and when the condition is true, then I should be able to click that element to get further details of that party.
Actual Result: Random value is picked & FOR loop contains no keywords.
You have several issues.
You use a list varibale #{ELEMENT for comparison instead of a scalar one.
In your Run Keyword If statement you have no keyword to run if the condition is true. The same for ELSE IF lines.
else if should be capitalized since it is a reserved keyword.
ELSE needs no condition at all, it handles all case which are not handled by the previous conditions.
You pick a random ${value} but don't use it. Iterating over a list will give you every condition true once.
If you want to use a random value, you don't need a for-loop at all. The code should look like this:
View all Details
${ELEMENT} = Evaluate random.choice($PARTY) random
log ${ELEMENT}
Run Keyword If '${ELEMENT}' == 'ABC' Your Keyword One Here
... ELSE IF '${ELEMENT}' == 'XYZ' Your Keyword Two Here
... ELSE IF '${ELEMENT}' == 'RTY' Your Keyword Three Here
... ELSE Your Keyword Four Here
Related
Here's my list
#{referentiel} N1(exemple)/N2(exemple) N2(exemple)/exemple
where i use it
Visca barca
[Arguments] ${index}
Click Element Using Javascript //div[#id='mat-select-value-5']
Click element of long page //span[#class='mat-option-text'][contains(.,'#{referentiel}[${index}]')]
And my testcase
we are the best
Visca barca 1
Error :
Value of variable '#{referentiel}[${index}]' is not list or list-like.
The issue you are describing here has nothing to do with the semicolons or slashes. The issue is actually that you are attempting to return the list item with wrong decorator.
To get a single item from a list you should use $ instead of #. When you use # Robot will attempt to return you a list which it cannot since the item on ${index} is a string.
See below:
#{referentiel} # == ['N1(exemple)/N2(exemple)', 'N2(exemple)/exemple']
or
${referentiel[0]} # == N1(exemple)/N2(exemple)
I have a for loop in which I would like to create list and add values to there.
FOR ${i} IN RANGE 3
*Create list List_${i}
Add values to list
END
How could I do it?
So that after exit the for loop, I would have list_1 & list_2 and list_3
Meaning I can create dynamic variable like this:
FOR ${idx} IN RANGE 3
${var_name} = Catenate SEPARATOR=_ var ${idx}
Set Suite Variable ${${var_name}} ${idx}
END
Maybe it is some easy way to do the same with #list ?
This does not work:
FOR ${i} IN RANGE 3
Log ${i}
${var_name}= Catenate SEPARATOR=_ TEST_NAME ${i}
Log ${var_name}
#{${${var_name}}}= Create List data
END
I think this is the answer:
FOR ${i} IN RANGE 3
Log ${i}
Set Suite Variable #{List${i}} #{EMPTY}
Append To List ${List${i}} ${i}
END
Note sure if this is exactly what you are looking for; but, I'll try to help.
First, lists cannot be empty; so you will need at least an initial value which you can then remove (or ignore) when you iterate thru the list. That said, I can suggest you create a For-Loop which returns is List-of-Lists since your "loop range may change".
Test-Dynamic-Lists-Creation
${listOfLists} Create List initial-value
FOR ${index} IN RANGE 3
${List_$index} Create List initial-value
Append To List ${listOfLists} ${List_$index}
END
Comment Removes the first value from the list.
Remove From List ${listOfLists} ${0}
Log List ${listOfLists}
Return From Keyword ${listOfLists}
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.
I have a new problem in my automation testing and I need to check if the data in my tables exist.
For Example.. I have a table below. I need to check if the cat and dog exist in the table.. else it will failed. so I create a run keyword if to verify if the data exist but first I need to get all the data because sometimes he table is dynamic. This is my sample code. my problem is.. what if the data(Dog) didn't exist in the table?
${Count} get element count ${Table_Row}
FOR ${i} IN RANGE 1 ${Count}
${Animals} get text xpath=//div[#id='table1']/table/tbody/tr/td[41]/div/table/tbody/tr[${i}]/td
Run Keyword If "${Animals}" == "Dog" Log to console Dog Exist ELSE fail Dog didn't exist
END
What you need is to get all the elements of first column into a array, something like:
${animals} Get WebElements xpath=//"xpath for all elements in first column"
then with that you can run a for cycle to check each element and fail the test if you don't find whatever you need to find:
FOR ${element} in #{animals}
${animal} Get Text ${element}
Log To Console ${animal}
END
You can check first expected data exists or not
${data}= Page Should Contain Element element xpath
if not exists you can fail the test.
Please let me know if I am not understood your question correctly..
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}