0.1.0 • Published 24 days ago

@vavanya/flaui-js v0.1.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
24 days ago

npm downloads gzip size version

npm.io

FlaUI.js

Motivation

FlaUI is a .Net open-source framework that allows the development of automated scripts for testing Windows desktop GUI applications using Microsoft UIA technology. We love the Node.js environment and JavaScript/TypeScript, so the idea of FlaUI.js came into play.

FlaUI.js provides the ability to use the power of FlaUI in the Node.js world.

Installation

You can install FlaUI.js via NPM

npm install @vavanya/flaui-js

Usage

Create the Node.js package

npm init -y

Add FlaUI.js support

npm install @vavanya/flaui-js

Create a file calculator.mjs file

// calculator.mjs
import { init } from '@vavanya/flaui-js';

let d = await init();

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

const findAndWaitForElement = async (mainWindow, xPath) => {
    let element;
    let counter = 0;
    do {
        element = mainWindow.FindFirstByXPath(xPath);
        if (element === null) {
            await sleep(500);
        }
    } while (element === null && ++counter < 60); // wait for 60 * 500 ms = 30 secs
    return element;
}

const UIA3 = d.FlaUI.UIA3;
const UI_Input = d.FlaUI.Core.Input;
const Application = d.FlaUI.Core.Application;

const uiAutomation = new UIA3.UIA3Automation();
let app = Application.LaunchStoreApp("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
let wnd = app.GetMainWindow(uiAutomation);
app.WaitWhileBusy();

// Find the buttons
let btn0 = await findAndWaitForElement(wnd, "//Button[@Name='Zero']");
let btn1 = await findAndWaitForElement(wnd, "//Button[@Name='One']");
let btn2 = await findAndWaitForElement(wnd, "//Button[@Name='Two']");
let btn3 = await findAndWaitForElement(wnd, "//Button[@Name='Three']");
let btn4 = await findAndWaitForElement(wnd, "//Button[@Name='Four']");
let btn5 = await findAndWaitForElement(wnd, "//Button[@Name='Five']");
let btn6 = await findAndWaitForElement(wnd, "//Button[@Name='Six']");
let btn7 = await findAndWaitForElement(wnd, "//Button[@Name='Seven']");
let btn8 = await findAndWaitForElement(wnd, "//Button[@Name='Eight']");
let btn9 = await findAndWaitForElement(wnd, "//Button[@Name='Nine']");
let btnPlus = await findAndWaitForElement(wnd, "//Button[@Name='Plus']");
let btnEqual = await findAndWaitForElement(wnd, "//Button[@Name='Equals']");
let result = await findAndWaitForElement(wnd, "//Text[@AutomationId='CalculatorResults']");

// Enter 123
btn1.Click();
btn2.Click();
btn3.Click();

// Click "+" sign
btnPlus.Click();

// Enter 4057
btn4.Click();
btn0.Click();
btn5.Click();
btn7.Click();

// Click "=" sign
btnEqual.Click();

// Print the result
// output: Result:  Display is 4,180
console.log('Result: ', result.Name);

// Just to see the result on screen
await sleep(5000); 
app.Close();

Run the file with Node.js

node calculator.mjs

NOTE this code was tested with Node.js v21.2.0 and NPM v10.2.3 on OS Windows 11 64-bit.

npm.io

Support

Support can be obtained by submitting Issues here on Gitlab.

Roadmap

We follow the upstream FlaUI project - if new features are applicable to our use case we will implement them.

Contributing

All contributions to this project are welcome: use cases, documentation, code, patches, bug reports, feature requests, etc. Any and all contributions may be made by submitting Issues and Pull Requests here on GitLab.

Please note that by submitting a pull request or otherwise contributing to this project, you warrant that each of your contributions is an original work and that you have full authority to grant rights to said contribution and by so doing you grant the owners of this project, and those who receive the contribution directly or indirectly, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable licence to make, have made, use, offer to sell, sell and import or otherwise dispose of the contributions alone or with this project in its entirety.

Third-Party Softwares

See ThirdPartyNotices

Licence

This work is licensed under the MIT license. See LICENSE file for details.

0.1.0

24 days ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

8 months ago