using LoginPI.Engine.ScriptBase; public class functionTimersExamples : ScriptBase { private void Execute() { /* -Disclaimer: This workload is provided as-is and might need further configuration and customization to work successfully in each unique environment. For further Professional Services-based customization please consult with the Login VSI Support and Services team. Please refer to the Help Center section "Application Customization" for further self-help information regarding workload crafting and implementation. -Run the workload against the "target" using Script Editor to ensure it will work before uploading it and testing with it -If needed, configure the Set global variables section of this workload -Workload version and changelist: --V1.0 | original -Leave Application running compatibility: false -Recommended to read through the comments of this script to understand what it's doing and modify anything needing to be -This script shows examples of how to use the function timers (custom timers) to generate relevant and helpful datapoints. The following scenarios are exampled: -Start a defined app (notepad.exe in the example), verify it's opened, and record how long it takes to load the app until the defined window title is present (timer is named "Start"), and will also record a custom timer for how long it takes for the full GUI to be fully loaded (looking for something to be present in the actual GUI, in this case, the text editor main pane) -Record how long it takes to stop the defined app -Run an "external" command-line statement that will launch a process, such as "notepad"; this will track how long it takes the process to start and become detect-able, and is encapsulated in a custom timer -Run an "external" self-contained statement, such as a command line that will finish by itself (ping.exe in this case), or the invocation statement for a script that is expected to end by itself. The custom timer will track how long the self-contained external process takes to run and complete by itself -Copy a file from source to destination; this function is encapsulated by a custom timer -Copy a folder from source to destination; this function is encapsulated by a custom timer -Development environmental information: -Login Enterprise scriptingtoolset version 4.2.14 -Winver 2004 OS Build 19041.508 Windows 10 Professional x64 */ // Setting global variables int globalFunctionTimeoutInSeconds = 20; // Starting test preparation ShellExecute(@"cmd /c taskkill /f /im notepad.ex*",waitForProcessEnd:true,timeout:globalFunctionTimeoutInSeconds); // This will taskkill notepad.exe applications if already running var tempEnvironmentVariablePath = GetEnvironmentVariable("temp"); Log("Temp path is: " + tempEnvironmentVariablePath); CopyFile(KnownFiles.ExcelSheet, tempEnvironmentVariablePath + @"\loginvsi.xlsx"); // This will start the defined app, verify it's opened, and record how long it takes to load the app until the defined window title is present (timer is named "Start"), and will also record a custom timer for how long it takes for the full GUI to be fully loaded (looking for something to be present in the actual GUI) StartTimer("NotepadFullyOpenTime"); START(mainWindowTitle:"Untitled - Notepad",mainWindowClass:"Win32 Window:Notepad",processName:"notepad",timeout:globalFunctionTimeoutInSeconds); MainWindow.FindControl(className : "Document:RichEditD2DPT", title : "RichEdit Control",timeout:globalFunctionTimeoutInSeconds); // This finds the text editor main pane in Notepad.exe StopTimer("NotepadFullyOpenTime"); // This will record how long it takes to stop the defined app StartTimer("NotepadTimeToStop"); STOP(timeout:globalFunctionTimeoutInSeconds); StopTimer("NotepadTimeToStop"); // The following will run a statement that will launch a process, such as "notepad"; this will track how long it takes the process to start and become detect-able, and is encapsulated in a custom timer StartTimer("ExternalStartCompletionTime"); ShellExecute("notepad.exe",waitForProcessEnd:false); StopTimer("ExternalStartCompletionTime"); ShellExecute(@"cmd /c taskkill /f /im notepad.ex*",waitForProcessEnd:false); // The following will run a self contained statement, such as a command line that will finish by itself, or the invocation statement for a script that is expected to end by itself. The custom timer will track how long the self-contained external process takes to run and complete by itself. StartTimer("ExternalStartEndCompletionTime"); ShellExecute("ping.exe",waitForProcessEnd:true,timeout:globalFunctionTimeoutInSeconds); StopTimer("ExternalStartEndCompletionTime"); // The following will copy a file from source to destination; this process is encapsulated by a custom timer StartTimer("CopyFileCompletionTime"); CopyFile(sourcePath:tempEnvironmentVariablePath + @"\loginvsi.xlsx",destinationPath:tempEnvironmentVariablePath + @"\loginvsi2.xlsx",continueOnError:true); StopTimer("CopyFileCompletionTime"); // The following will copy a folder from source to destination; this process is encapsulated by a custom timer StartTimer("CopyFolderCompletionTime"); CopyFolder(sourcePath:tempEnvironmentVariablePath + @"\loginpi",destinationPath:tempEnvironmentVariablePath + @"\loginpi2",continueOnError:true); StopTimer("CopyFolderCompletionTime"); // Doing some test clean-up here RemoveFolder(tempEnvironmentVariablePath + @"\loginpi2",continueOnError:true); RemoveFile(tempEnvironmentVariablePath + @"\loginvsi.xlsx",continueOnError:true); RemoveFile(tempEnvironmentVariablePath + @"\loginvsi2.xlsx",continueOnError:true); } }