Page tree
Skip to end of metadata
Go to start of metadata

Last updated: May 31, 2020 15:22

By Assa Lahav

This descriptive code sample shows how to use reporting commands in a UFT script.


This sample script contains a simple skeleton script that:

  • Selects and opens a device.
  • Installs an application
  • Logins to the application

 Each of these actions are defined as Steps for the Reporting tool, and the code highlights the additional calls to TestStart, TestStep, and TestEnd that inform the Reporting tool where to annotate the test report.


Public Function TestLogin()
    ' Add Test start to reporting
    PerfectoLab("lab_id:=lab").TestStart "name=PerfectoCommunityAppLogIn","tags=AndroidNativeAppTests","jobName=Job1","jobNumber=11","projectName=Sample Reportium project","projectVersion=1.0"
 
    ' Open device
    PerfectoLab("lab_id:=lab").TestStep "name=step1: Open device" ' Add Test Step to Reporting
    PerfectoLab("lab_id:=lab").SelectDevice("os=Android")
    Device("DUT").SetTOProperty "device_id","03157DF3B81ABD26"
    Device("DUT").Open
 
    ' Install and start application
    PerfectoLab("lab_id:=lab").TestStep "name=step2: Install application" ' Add Test Step to Reporting
    Device("DUT").Applications.Install "PUBLIC:Android/android.perfecto.apk"
    Device("DUT").Applications.Start "name=Perfecto Mobile"
 
    ' Validate login page
    PerfectoLab("lab_id:=lab").TestStep "name=step3: Validate login page" ' Add Test Step to Reporting
    Device("DUT").MNativeElement("identifier:=//*[@resourceid='com.bloomfire.android.perfecto:id/sso1']").GetROProperty "text"
 
    ' Login to app
    PerfectoLab("lab_id:=lab").TestStep "name=step4: Login to app" ' Add Test Step to Reporting
    Device("DUT").MNativeElement("identifier:=//*[@resourceid='com.bloomfire.android.perfecto:id/email_address']").Set "MyCommunityUser"
    Device("DUT").MNativeElement("identifier:=//*[@resourceid='com.bloomfire.android.perfecto:id/password']").Set  "MyCommunityPassword"
    Device("DUT").MNativeElement("identifier:=//*[@resourceid='com.bloomfire.android.perfecto:id/item_button_sign_in_done']").Click
 
    ''' Other test commands here...
 
    ' Close device
    Device("DUT").Close
 
    ' Add Test end with status 'success' to reporting
    PerfectoLab("lab_id:=lab").TestEnd "success=true"
End Function
 
On Error Resume Next
TestLogin
If Err.Number <> 0 Then
    ' Add Test end with status 'failure' to reporting
    PerfectoLab("lab_id:=lab").TestEnd "success=false","failureDescription=" + Err.Description
End If   
 
On Error GOTO 0

The full UFT sample can be found here