Windows Desktop Automation
abstract
This section details how to test Windows Desktop Applications.
If you are not familiar with Sahi Pro, see Quick Tutorial on Sahi Pro
To automate windows desktop applications using Sahi Pro Flowcharts, refer Windows Desktop Automation.
Start Windows Desktop Automation
- Start Sahi Dashboard
- Click
Processes
link on Sahi Pro Dashbord. Ensure thatWindows Automation
is turned on. - "Sahi windows agent started!" message appears on Sahi Pro console.
Using the Controller
- To Launch Sahi Controller, click the Desktop icon on the Sahi Dashboard.
- On the Controller, go to the Record tab and check "enable recording/identification for Windows" checkbox. The Controller can be used to interact with the desktop application. You can Identify, Click, Set, Assert, choose Other Actions. You can even Test an expression from Evaluate Expression to perform an action on the Windows Desktop application.
infoMake sure popup blockers are turned off.
infoRefer Sahi Controller and Java Controller for a better understanding.
Element Identification
- Launch the Controller and check "enable recording/identification for Windows" checkbox.
- To identify an element, press the CTRL key, hover over any element and release the CTRL key.
infoThe accessors will not be populated till CTRL key is released. This is an optimization to stop Sahi from unwanted processing.
Accessor:
shows the Sahi accessor for that elementAlternatives:
shows all alternative accessors for that elementValue:
shows the value of the current element. Mostly this is the input text or the visible text.Prefix:
window name.Mode:
shows the Automation mode
infoBlank
Prefix
means element is present on the taskbar.info
Start SahiWin exe
must be clicked from Sahi Dashboard and ' Windows ' checkbox at right side top most corner in controller must be checked during identification or recording.- If during identification, Sahi is identifing background elements, then goto display setting of PC and change
Change the size of text, apps and other items
to 100% (Recommended). - For SilverLight, XBAP (i.e browser based desktop application) during identification, if Sahi is not identifing some boundary elements, then maximize the browser.
- Refer Identify Elements for a better understanding.
Evaluate Expression
Evaluating Windows Desktop Application expression through Controller. It helps while identifying elements or while debugging.- Put a valid Sahi expression in the Evaluate Expression box
- Select mode as 'Sahi-Windows'
- Click on
→
. The result will be seen in the bottom box. Append
While recording, selecting and clicking onAppend
will append the steps to the currently recording script. This is mainly used for manually append any step from Evaluate Expression to the currently recording script.Highlight
Can be used on selected text to highlight the element (shows a red 1 pixel border briefly). Invokes the_highlight
API.Drop down
Lists some actions like Click, Get Value, Get Text etc.
infoNote: Selecting some text and pressing '→' will only evaluate the selected text.
infoNote:
Start SahiWin exe
must be clicked on Sahi Dashboard and 'Sahi-Windows' must be selected as the 'Select mode for evaluate' during evaluatinginfoRefer Evaluate Expression for a better understanding.
Recording a script
This is similar to recording a Sahi script for normal browser testing.- To record a script, launch the Controller, check 'Windows' checkbox at right side top most corner in controller, give a script name and click 'Record'. Actions done on the Windows Desktop are recorded automatically.
- Steps can also be recorded from the Controller.
-
A. You can use Click, Set, Assert, choose 'Other Actions' to perform an action on the Windows Desktop Application.
B. You will need to record these steps explicitly by clicking on 'Append'.
info
Start SahiWin exe
must be clicked from Sahi Dashboard and 'Windows' checkbox must be checked in Sahi Controller during identification or recording.- Cursor Feedback:During recording, mouse cursor turns to Arrow with Red dot until the step is recorded.
- Refer Record a script for a better understanding.
Playback
From Controller
Once a script is recorded, it can be played back from the Controller Playback tab itself.- Choose the script.
- Select Start Mode as
Windows
. - You can leave the Start url blank. This is not used for Windows Desktop Application.
- Click on Play to playback the script.
- Click on Logs to view the logs of the played back script.
infoNote: A script cannot be played back if
Start SahiWin exe
is not clicked on Sahi Dashboard.infoRefer Playback Tab for a better understanding.
From the Editor
You can playback the script from the Editor as well.- Choose the script/suite/scenario from the Editor and click on the Playback button.
- Choose the Start Mode as Windows.
- Choose either of the two options - 'Run in single machine' or 'distributed (multiple machines)'.
- Press Run to playback the test.
infoNote: A script cannot be play back if
Start SahiWin exe
is not clicked on Sahi Dashboard.Scripting Notes
-
To start a Windows application from script, use
_execute("correct/path/your_application.exe"); // or _execute("correct/path/your_application.bat");
- All code interactions with Windows will need to be preceded by _setMode("WINDOWS")
Auto Scrolling
- In some cases, the element can be found only on vertical scroll. In such a case, you must specify a scrollable parent element using
_startLookInside
api. Windows Automation will gradually scroll vertically inside this scrollable parent element and try to find the element. - It is possible, that the element exists but is visible only on scrolling horizontally. In such a case, Windows Automation will automatically scroll horizontally starting from left to right and make the element visible.
// For example element for folder '823' can be found only on vertical scroll. So if we try to perform any action on this element, it will fail.
// In such case we use _startLookInside api and thus the element will be found on vertical scroll.
_startLookInside(_list("Items View")); // Specify a scrollable parent element
// Now if _listitem("823") is not found,
//Windows automation will scroll vertically from top to bottom inside _list("Items View") and try to find the element.
_click(_listitem("823"));
_stopLookInside();
Additional Configurations
- Execute Faster by Ignoring Hidden and Disabled Elements
- While searching for an element during Playback, Sahi internally iterates through all the elements on the application screen. At times, this iteration may be slower for few screens in your application. This iteration can be made faster by adding below properties to the userdata.properties file as applicable.
// Add below property to ignore hidden elements in your application
sahi.desktop_automation.windows_automation.ignore_hidden_elements=true
// Add below property to ignore disabled elements in your application
sahi.desktop_automation.windows_automation.ignore_disabled_elements=true
- In some applications, inner elements may not be identified from the Sahi Controller. Lets say a pane element contains child elements like textbox, button, etc and the child elements are not getting identified from Sahi Controller. To fix this, find the entry for the parent element type in
<Sahi_Installation>\config\accessor_metadata\mswindows.json
file. Add a new key "deepSearchAlgo" with value as "child" in this entry for the parent element type.
For example, the key "deepSearchAlgo" can be added for a pane element as shown below.
{"type": "pane", "name":"_pane", "id":"50033", "deepSearchAlgo":"child", "attributes": ["name", "automationId", "helpText", "className", "index"], "action": "setValue", "value" : "transform", "assertType":"TEXT", "since": ["NA", "NA", "NA", "7.0.0"]}