Sunday, October 2, 2011

FOR loops & IF condition in RobotFramework

Using Robot Framework, test engineer can create FOR loops and IF conditions. I don't think so, any other Keyword driven framework is giving this kind of flexibility.

FOR loop can be set in two ways. First one is based on number of items in a List. Another one is based on range like from 1 to 50. Similarly keywords can be executed if condition matches or not. See below example.

FOR Loop & IF condition explantation using Robot Framework

TestCase Action Arguments
VerifyListItems [Arguments] ${Locator} @{ListItems}
[Documentation] Verifies the list of items present in a List Object.
: FOR ${Element} IN @{ListItems}
Select From List ${Locator} ${Element}
List Selection Should Be ${Locator} ${Element}
: FOR ${index} IN RANGE 50
${obj1}= Evaluate ${index}*4+3
Run Keyword if '@{tDriverData}[4]'=='2' Go To MyProfile
Run Keyword Unless '@{tDriverData}[4]'=='2' Go To UserCreation

5 comments:

saveyourhealth said...

Application Development
G Tech of NC, USA is a leader in custom software development, mobile application development, offshore outsourcing, mobile apps, mobile testing, remote DBA, and software testing on Android, iPhone, Blackberry, Windows, Linux using Java, Dot .Net, C/C++, C#, JavaScript, Objective-C, VB, PHP, Perl, Python, Ruby, Oracle, SQL Server, MySQL, Flash, Flex, SAP, iSeries AS400 RPG and other platforms.

Anonymous said...

Would like discussion of continuing loop despite one test failing, or stopping if test fails.

Bob Jones said...

I don't mean this to be critical, but that example of looping looks pretty rough. I suppose it will work, but it really limits the group of people who can work on the framework to the very technical who understand this framework.

Palani Selvam said...

Bob,
I was unable to find the examples of FOR loops, thats why I wrote this post.

In the automation world, FOR loops in keyword driven framework is not critical but significant one...

Anonymous,
You can send your queries to palani.selvam@gmail.com

Aquila Morrison said...

Continues executing the attaching for cycle.This keyword and key phrase can be used in a for cycle or in a keyword and key phrase that the for cycle uses. In both situations the analyze performance continues with the next version of the for cycle.