Test a GUI application with functions

This exercise describes how to create and use a user-defined function, which is useful to handle tasks not supported by default for a specific object class.

Create a new test to test a function

Create a copy of your existing MyFlight test, where you can add a function library and use it to test your app.

To create a test:

  1. Start with the MyFlightApplication solution open in OpenText Functional Testing.

    If you've closed and opened OpenText Functional Testing, make sure you start it with the WPF Add-in loaded.

  2. In the Solution Explorer, right-click the MyFlight test node, and select Save As.

  3. Save the test in the same location (C:\Users\<username>\Documents\UFT One).

    In the File name field, enter MyFlightFunction, and then click Save.

The Solution Explorer switches to display MyFlightFunction test instead, with all the same actions and steps as the original MyFlight test.

Tip: To display both of your tests at the same time, add the MyFlight test back to your solution.

In the Solution Explorer, right click the solution node, and select Add > Add Existing Test. Select the MyFlight test.

Back to top

Create a function and associate it with your test

Create a function to test whether a date in the MyFlights app is displayed in the correct format and is actually valid.

Associate it with the MyFlightsFunction test to make it available for use.

To create a function and associate it:

  1. In the toolbar, click the New button down arrow and select New Function Library.

    In the New Function library dialog:

    1. Ensure that you are located in the C:%HOMEPATH%\My Documents\UFT One folder.
    2. Create a new sub-folder named TutorialFunctionLibraries, and open it.
    3. In the File name field, enter CheckDateFunction to name your new function library.
    4. Click Create.

    The new CheckDateFunction is opened as a new tab in OpenText Functional Testing.

  2. Copy and paste the following code into the CheckDateFunction file.

    This function verifies that the date format is equal to DD-<MMM string>-YYYY, and is actually a valid date for the app.

    Copy code
    'The following function checks whether a date string (dateStr)
    'has the characters representing DD-<MMM string>-YYYY
    Function check_data_validity( dateStr )
     Dim firstDashPos, secondDashPos
     Dim mmPart, ddPart, yyyyPart
     firstDashPos = inStr( dateStr , "-" )
     secondDashPos = inStrRev( dateStr, "-" )
     If ( (firstDashPos <> 2 and firstDashPos <> 3) or (secondDashPos <> 6 and secondDashPos <> 7)) Then
       reporter.ReportEvent micFail,"Format check", "Date string is: "&" missing at least one dash ( - )."
       check_data_validity = False
       Exit function
     End If
     If firstDashPos = 2 Then
       ddPart = mid( dateStr, 1, 1)
     else
       ddPart = mid( dateStr, 1,2 )
     End If
     mmPart = mid( dateStr, firstDashPos+1, 3 )
     yyyyPart = mid( dateStr, secondDashPos +1 , 4 )
     If  not( mmPart="Jan" or mmPart="Feb" or mmPart="Mar" or mmPart="Apr" or mmPart="May" or mmPart="Jun" or mmPart="Jul" or mmPart="Aug" or mmPart="Sep" or mmPart="Oct" or mmPart="Nov" or mmPart="Dec")  Then
       reporter.ReportEvent micFail, "Format Check", "The month: "& mmPart&"is invalid. It is not a valid month string."
       check_data_validity = False
       Exit function
     End If
     If ddPart > 31 Then
       reporter.ReportEvent micFail, "Format Check", "The date: "& ddPart&"is invalid. It exceeds 31."
       check_data_validity = False
       Exit function
     End If
     If yyyyPart < 2021 Then
       reporter.ReportEvent micFail, "Format Check", "The year: "&yyyyPart&" is invalid. (Prior to this year.)"
       check_data_validity = False
       Exit function
     End If
     check_data_validity = True
    End Function
  3. Save, and then close the function library file.
  4. Associate your new function library with the MyFlightsFunction test:

    1. In the Solution Explorer, right-click the MyFlightsFunction test node, and select Add > Associate Function Library.
    2. In the Open Function Library dialog, select the CheckDateFunction.qfl file, and click Open.

    The CheckDateFunction is added to the MyFlightsFunction test in the Solution Explorer, under a separate Function Libraries sub-folder.

  5. Save your test, and continue with Find the name of the date property to check.

Back to top

Find the name of the date property to check

The function you added in the previous steps checks the date format for a calendar object.

To verify this date format in your test, you must first find and note the properties for the specific object where you want to perform this check.

To verify the date property's format:

  1. Open the MyFlights GUI sample app, and log in.

    For more details, see Flight GUI layer.

  2. In OpenText Functional Testing, click the Object Identification Center button in the toolbar.

  3. In the OIC, click the Start spying button . The OIC window is replaced by the OIC widget .

    OpenText Functional Testing is minimized to display the MyFlights app. Click the date field to let the OIC capture its properties.

  4. In the OIC, scroll through the identification properties until you see the Date value, and note the property name.

    For example:

  5. Close the OIC and return to your test.
  6. In the MyFlightFunction test, open the FlightFinder action in the Editor.
  7. In the FlightFinder action, place your cursor after the WpfCalendar.SetDate step and press ENTER to add a new line.
  8. Add a step to retrieve the date property for the datePicker object. This ensures that OpenText Functional Testing has the details it needs to run the function properly.

    Copy and paste the following code to the new line in your action:

    Copy code
    currentDate = WpfWindow("OpenText MyFlight Sample").WpfCalendar("datePicker").GetROProperty("DisplayDate")
    orderDate = currentDate + 10
    WpfWindow ("OpenText MyFlight Sample").WpfCalendar("datePicker").SetDate orderDate
    departureDate = WpfWindow("OpenText MyFlight Sample").WpfCalendar("datePicker").GetROProperty("date")
  9. Add another step to call the checkpoint function. Copy and paste the following code to a new line after the departureDate step.

    If check_data_validity(departureDate) Then
    	reporter.ReportEvent micPass, "Date is valid", departureDate
    End If
  10. Save your test and continue with:

Back to top

View your action in the Editor

Verify that your action now has the following lines in the Editor:

 

WpfWindow("OpenText MyFlight Sample").WpfComboBox("fromCity").Select "Los Angeles"
WpfWindow("OpenText MyFlight Sample").WpfComboBox("toCity").Select Sydney
currentDate = WpfWindow("OpenText MyFlight Sample").WpfCalendar("datePicker").GetROProperty("DisplayDate")
orderDate = currentDate + 10
WpfWindow ("OpenText MyFlight Sample").WpfCalendar("datePicker").SetDate orderDate
departureDate = WpfWindow("OpenText MyFlight Sample").WpfCalendar("datePicker").GetROProperty("date")
If check_data_validity(departureDate) Then
reporter.ReportEvent micPass, "Date is valid", departureDate
End If
WpfWindow("OpenText MyFlight Sample").WpfComboBox("Class").Select Business
WpfWindow("OpenText MyFlight Sample").WpfComboBox("numOfTickets").Select "2"
WpfWindow("OpenText MyFlight Sample").WpfButton("FIND FLIGHTS").Click

Back to top

View your action in the Keyword View

Switch to the Keyword View, and note the new datePicker GetROProperty and Function Call steps.

Back to top

Run your function test and analyze the results

Run your test to see how OpenText Functional Testing performs the function check to verify the date format and value.

To run the test:

  1. Close any open windows running MyFlights.

  2. In the toolbar, click Run .

    In the Run dialog, ensure that the MyFlightFunction test and the New run results folder options are selected.

  3. Click Run.
  4. When the test run is complete and the run results open, scroll down in the Test Flow to the FlightFinder action > Date is valid node.

    Note that a checkmark is displayed next to the step name. This informs you that the checkpoint passed, as per the function you added.

Back to top

Next steps: