Search code examples
exceltestingvbscriptautomated-testshp-uft

How do I make my UFT script skip a cell in excel based on the labels on the application screen


I have a very dynamic application to automate using UFT. The labels on the application screen change based on the input provided by the user. I have an excel where I have set the field value for all possible fields present in the application. The challenge is I want my UFT script to pick only those field values for which it finds the field name on screen. Each time I run the script, based on the selection whatever fields apppear on the screen, I want it to pick only those corresponding values from the excel sheet and ignore the other values in that excel sheet.

Eg

Excel has the following vales

Name: Nancy Grade: 8 Hobby: Writing Friend: Veronica BFF: Karen

But in the application on screen only the following labels appear

Name: Hobby: BFF:

I want the UFT script to compare the field label on screen with that in excel and pick those values from excel (in this case Name, Hobby, BFF) and ignore the other fields (Grade and Friend) .

Is this possible?


Solution

  • Let's assume your application presents various editboxes on a form for input, and you are using the DataTable object to store your Excel file.

    Ok, here's what I would do.

    First... I'd gather the objects into the Object Repository. I would create/record each possible edit box as a separate object (within an object for the app itself), making sure that each object is uniquely identifyable by name... (if the edit box controls themselves aren't uniquely named behind the scenes, QTP offers the ability to link to the captions next to them...). Also, if the application merely HIDES the edit boxes, then make sure Visible=True is one of the idenfitying attributes, such that when Visible=False, they are not found.

    Once every object is in the OR, then it's a simple matter of checking if they exist.

    'assuming your excel file is already imported as the global DataTable
    if Window("My App").Editbox("Name").exist(0) then Window("My App").Editbox("Name").Set DataTable("Name")
    if Window("My App").Editbox("Grade").exist(0) then Window("My App").Editbox("Grade").Set DataTable("Grade")
    if Window("My App").Editbox("Hobby").exist(0) then Window("My App").Editbox("Hobby").Set DataTable("Hobby")
    if Window("My App").Editbox("Writing Friend").exist(0) then Window("My App").Editbox("Writing Friend").Set DataTable("Writing Friend")
    if Window("My App").Editbox("BFF").exist(0) then Window("My App").Editbox("BFF").Set DataTable("BFF")
    

    Of course, this example is inefficient and can be easily rolled up (i.e. you could make a UDF, and call it from a loop reading field names from an array...) But, it should demonstrate this simple approach.