2

In my web application, I have to update 25 fields to create a user. Test data in Excel has a list of 100 users with required info for all 25 fields.

Using Robot framework,test script was written in such a way that it reads a single row(Single user info) from excel and updates all the corresponding fields in web application.

If I want to update only 10 fields (or ‘n’ fields), how do I handle it in script? enter image description here

Note: Fields to be update may change based on test case.

Rakesh
  • 1,525
  • 1
  • 15
  • 25
  • Can you please show the current test script that you have? You mean to say, it is having 25 fields and only 10 fields are mandatory while create user and you want to achieve both the cases? – Rao Mar 04 '16 at 18:09
  • @Rao ,Yes,I want to achieve both the cases. I have added test script for your reference – Rakesh Mar 06 '16 at 02:37
  • please have a look at my answer and provide me with some feedback so that we could close this issue for you and for anyone who might come across this in future – jim Apr 23 '16 at 23:05

1 Answers1

1

From what I understood about your situation, this is not an easy task for Robot. However, there is a rather simple way to handle this by having a universal test script and case-specific excel file.

  1. Populate your excel spreadsheet with FieldName and TabName to be able to locate the input on the page. My way of doing this would be:

table 1

  1. Retrieve TabName, FieldName and Value to a list using ExcelLibrary (you seem more familiar than me with the use of it, so I leave it up to you). As a result of this step you will have a list of 3 items, say ${SingleFieldOfSingleUser} # ['Tab1', 'Field1', 'aaa']

  2. Now create a list of these Fields:

        \  Insert Into List  ${SingleUser}  ${ColIndex}  ${SingleFieldOfSingleUser}
    
  3. Instead of manually going through every possible Input Field, use a universal custom keyword:

        :FOR  ${UserAttribute}  IN  @{SingleUser}
        \  Input Attribute Into User Form  ${UserAttribute}
    
  4. The keyword might look something like this:

    Input Attribute Into User Form
        [Arguments]  ${Attribute}
        # Try switching to the correct Tab. If already there, don't break upon error
        Run Keyword And Ignore Error  Click Element  ${Attribute[0]}
        # Input Value
        Input Text  ${Attribute[1]}  ${Attribute[2]}
    
  5. Profit! You can now provide an Excel spreadsheet with any number of columns depending on which fields you want to update.

Here I leave for you a mockup of complete code listing:

*** Keywords ***

(...)

Read Column Data For User
    ${SingleUser}  Create List

    :FOR  ${ColIndex}  IN RANGE  ${COLCOUNT}
    ( ... Excel-related code here ... )
    \  ${SingleFieldOfSingleUser}  Create List  ${TabName}  ${FieldName}  ${Value}
    \  Insert Into List  ${SingleUser}  ${ColIndex}  ${SingleFieldOfSingleUser}

    :FOR  ${UserAttribute}  IN  @{SingleUser}
    \  Input Attribute Into User Form  ${UserAttribute}

    (...)

Input Attribute Into User Form
        [Arguments]  ${Attribute}
        Run Keyword And Ignore Error  Click Element  ${Attribute[0]}
        Input Text  ${Attribute[1]}  ${Attribute[2]}

P. s. you really don't need so many FOR loops and lists to make this thing work, but I tried to make my solution as close to your original coding pattern as possible in case it has some hidden personal value.

jim
  • 906
  • 7
  • 14