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

Last updated: Sep 17, 2017 11:48

Code sample that uses StartVitals to open youtube, collect vitals and plays the first video

Supported only up to UFT 12.01 and from Perfecto Version 7.2.

Vitals can be collected in UFT with the StartVitals command. The sample below measures vitals of YouTube while playing a video. To run, download the file or copy the code below. 
Replace 
myDeviceId = "myDeviceID" with your device.

vitals.zip

 

'/*********************************************************************************
'Perfecto collects vitals from the device itself and from the application.
'When the vitalsStart command is run with no parameters, vitals are collcted from 'the device onlyy.
'Users can also specify the application to collect vitals from, and  optionally which vitals to collect.
'/*********************************************************************************
'All vitals from the device
'Device("DUT").StartVitals 
'to select just one or more vitals from the device specify each like the below
'Device("DUT").StartVitals "monitors=outputs.monitors.memory.used"
'Device("DUT").StartVitals "monitors=outputs.monitors.cpu.total"
'To select all vitals from the device and all vitals from an application 
'Device("DUT").StartVitals "sources=device"
'Device("DUT").StartVitals "sources=youtube"
'Vitals can be specified for the application
'Device("DUT").StartVitals "monitors=outputs.monitors.cpu.user","sources=youtube" 
'Device("DUT").StopVitals
'/*********************************************************************************
'SAMPLE OPENING YOUTUBE AND COLLECTING ALL VITALS FROM DEVICE AND YOUTUBE
myDeviceId = "myDeviceID"
Device("DUT").SetTOProperty "device_id",myDeviceId
Device("DUT").Open
Device("DUT").Home
Device("DUT").Applications.Start("youtube")
Device("DUT").StartVitals "sources=device"
Device("DUT").StartVitals "sources=youtube"
Device("DUT").Checkpoints.TextCheckpoint "watch more","timeout=20"
'Get the length of the video, later used in the wait to let the entire video play
clipDuration = Device("DUT").MNativeElement("identifier:=(//text[@resourceid='com.google.android.youtube:id/duration'])[1]").GetROProperty("text")
divider = InStr(clipDuration,":")
seconds=right(clipDuration,divider)
minutes = 60 * (left(clipDuration,divider-1))
Device("DUT").MNativeElement("identifier:=(//text[@resourceid='com.google.android.youtube:id/duration'])[1]").Click
wait seconds+minutes 
Device("DUT").PressKey("BACK")
Device("DUT").Applications.Close("youtube")
Device("DUT").StopVitals
Device("DUT").Close
The vitals are available in a CSV file accessible from the UFT report.