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

4 comments:

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

    ReplyDelete
  2. 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.

    ReplyDelete
  3. 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

    ReplyDelete
  4. 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.

    ReplyDelete