UIA Pro code sample (JavaScript SDK)
Calculate 2 squared using a calculator application
This example shows how to test the "squared" operation on the Windows calculator, by calculating 2 squared and checking the result:
var LFT = require("leanft");
var Desktop = LFT.Desktop;
var UIAPro = LFT.UIAPro;
var expect = require("leanft/expect");
var whenDone = LFT.whenDone;
describe("FTDTest", function () {
// set the default Jasmine time out
jasmine: jasmine.DEFAULT_TIMEOUT_INTERVAL = 30 * 1000;
beforeAll(function (done) {
LFT.init();
whenDone(done);
});
beforeEach(function (done) {
LFT.beforeTest();
whenDone(done);
});
it("Test", function (done) {
// Make sure that the Windows calculator application is launched.
// Describe the two button.
var twoButton = Desktop.$(UIAPro.Window({
processName: "ApplicationFrameHost",
name: "Calculator",
path: "Window",
frameworkId: "Win32",
controlType: "Window"
}))
.$(UIAPro.UiObject({
processName: "CalculatorApp",
path: "Window;Window;Custom",
frameworkId: "XAML",
controlType: "Custom"
}))
.$(UIAPro.Button({
processName: "CalculatorApp",
name: "Two",
path: "Window;Window;Custom;Group;Group;Button",
frameworkId: "XAML",
controlType: "Button"
}));
// Describe the square button.
var squareButton = Desktop.$(UIAPro.Window({
processName: "ApplicationFrameHost",
name: "Calculator",
path: "Window",
frameworkId: "Win32",
controlType: "Window"
}))
.$(UIAPro.UiObject({
processName: "CalculatorApp",
path: "Window;Window;Custom",
frameworkId: "XAML",
controlType: "Custom"
}))
.$(UIAPro.Button({
processName: "CalculatorApp",
name: "Square",
path: "Window;Window;Custom;Group;Group;Button",
frameworkId: "XAML",
controlType: "Button"
}));
// Describe the result text.
var resultText = Desktop.$(UIAPro.Window({
processName: "ApplicationFrameHost",
name: "Calculator",
path: "Window",
frameworkId: "Win32",
controlType: "Window"
}))
.$(UIAPro.UiObject({
processName: "CalculatorApp",
path: "Window;Window;Custom",
frameworkId: "XAML",
controlType: "Custom"
}))
.$(UIAPro.Pane({
processName: "CalculatorApp",
path: "Window;Window;Custom;Group;Text;Pane",
frameworkId: "XAML",
controlType: "Pane",
}));
// Invoke the default action on the 2 button (clicking using the invoke pattern).
twoButton.invokePattern().invoke().then(invokeResult => {
// Click the square button.
squareButton.click().then(clickResult => {
// Get the result value from the text.
resultText.legacyAccessiblePattern().getName().then(resultValue => {
// Verify the expected result (as string) matches with the actual result.
expect(resultValue).toEqual("4");
});
});
});
whenDone(done);
});
afterEach(function (done) {
LFT.afterTest();
whenDone(done);
});
afterAll(function (done) {
LFT.cleanup();
whenDone(done);
});
});

