Thursday, March 26, 2015

Robot framework - Notes

Robot framework: To read datas from a row in excel sheet

Add more users
    Open Excel    ${Excel_File_Path}
    @{ROW1}    Get Row Values    Sheet1    0
    ${RUN}=    Get From List    ${ROW1}    0
    ${LIST}    Convert To List    ${RUN}
    log to console    ${LIST[1]}
 
Explanation

Get Row Values - Collects all values from row and assign it to ROW1
 @{ROW1}    Get Row Values    Sheet1    0 ->Output will be tuple -> Eg [(1,2),(3,4)]
 Get From List    ${ROW1}    0 -> To get the first value, i.e  (1,2)
To convert it as [1,2] -> use Convert to List keyword
 ${LIST[1]} - To access 2nd value from the list

Reading values from excel

Add more users
    Open Excel    ${Excel_File_Path}
    ${COLCOUNT}    Get Column Count    Sheet1
    @{ROW1}    Get Row Values    Sheet1    0
    ${RUN}=    Get From List    ${ROW1}    0
    ${LIST}    Convert To List    ${RUN}
    :FOR    ${COUNT}    IN RANGE    ${COLCOUNT}
    \    @{ROW1}    Get Row Values    Sheet1    ${COUNT}
    \    Fetch Column Data

Fetch Column Data
         :FOR    ${ColIndex}    IN RANGE    ${COLCOUNT}
         \    ${VarList}    Create List
         \    ${RUN}=    Get From List    ${ROW1}    ${ColIndex}
         \    ${LIST}    Convert To List    ${RUN}
         \    ${Value1}=    Get From List    ${List}    1   
         \    Insert Into List    ${VarList}    ${ColIndex}    ${Value1}
         \    Log to console    ${VarList}


No comments:

Post a Comment