Share this page

# Standard Windows code samples (JavaScript SDK)

In this topic:

## End-to-End: Locate a Button Using Visual Relation Identification (VRI)

The following example uses Visual Relation Identification (VRI) to locate and click buttons in the standard Windows calculator.

    var assert = require("assert");
    var LFT = require("leanft");
    var expect = require("leanft/expect");
    var fs = require("fs");
    var exec = require('child_process').exec;
    var Web = LFT.Web;
    var ImageUtils = LFT.ImageUtils;
    var browser;

    jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

    describe("VRI examples",function(){
    	var calcAUTPath = "C:\\Windows\\System32\\calc.exe";
    	var AUT = null;

    	beforeAll(function(done){
    		LFT.init();
    	        LFT.whenDone(done);
    	});

    	beforeEach(function(done){
    		LFT.beforeTest();
    		AUT = exec(calcAUTPath);
    		LFT.whenDone(done);
    	});

    	it("Basic usage - click on the '1' button", function(done){
    		var calculator = LFT.Desktop.$(LFT.StdWin.Window({
    			windowClassRegExp:"CalcFrame",
    			windowTitleRegExp:"Calculator"
    		} ));

    		var button2 = calculator.$(LFT.StdWin.Button({
    			text:"",
    			windowId:132,
    			nativeClass:"Button"
    		}));

    		var button4 = calculator.$(LFT.StdWin.Button({
    			text:"",
    			windowId:134,
    			nativeClass:"Button"
    		}));

    		var button1 = calculator.$(LFT.StdWin.Button({
    			nativeClass:"Button",
    			vri:[{anchor: button2, horizontal: LFT.Horizontal.right, hInline: true},{anchor: button4, vertical: LFT.Vertical.above, vInline:true, proximity:LFT.Proximity.closestOnYAxis}],
    			}
    		));

    		button1.click();

    		LFT.whenDone(done);
    	});

    	afterEach(function(done){
    		LFT.afterTest();
    		if(browser){
    			browser.close();
    		}
    		LFT.whenDone(done);
    	});

    	afterAll(function(done){
    		AUT.kill();
    		LFT.cleanup();
    		LFT.whenDone(done);
    	});
    });

Back to top

## Low level keyboard and mouse operations

This example shows usage of the low level keyboard and mouse operations.

    var LFT = require("leanft");
    var expect = require("leanft/expect");
    var spawn = require('child_process').spawn;
    var StdWin = LFT.StdWin;
    var Desktop = LFT.Desktop;
    var Keyboard = LFT.Keyboard;
    var Mouse = LFT.Mouse;

    jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

    describe("Low level examples", function () {
    	beforeAll(function(done){
    		LFT.init();
    		LFT.whenDone(done);
    	});

    	beforeEach(function(done){
    		LFT.beforeTest();

    		LFT.whenDone(done);
    	});

    	// This example shows usage of the low level keyboard and mouse operations
    	it("Keyboard and Mouse operations test", function (done) {
    		// Following is the program flow:
    		// 1. Launch notepad.
    		// 2. Move the notepad window to the top left area of the screen
    		// 3. Open the Format menu item by low level clicking on the place where the "o" in Format appears
    		// 4. Select the Font menu item by low level clicking on the place where the "Font..." menu item should appear
    		// 5. Verify the Font dialog appears
    		// 6. Close the Font dialog by low level pressing on the ENTER keyboard key
    		// 7. Close notepad by low level double clicking the mouse on the area where the system menu icon exists

    		// Launch the Notepad application.
    		spawn('C:/Windows/System32/notepad.exe');

    		// Locate the Notepad window and assign it to a Window object.
    		var notepadWindow = Desktop.$(StdWin.Window({
    			windowClassRegExp:"Notepad",
    			windowTitleRegExp:" Notepad"
    		}));

    		// Move the notepad window to the top left area of the screen
    		notepadWindow.move(0, 0);

    		Mouse.click(90, 40); //Click on the area where the "o" in the Format menu item exists using low level mouse operation
    		Mouse.click(115, 82); //Click on the area where the "Font..." menu item exists using low level mouse operation

    		// Locate the Font dialog box and assign it to a Dialog object.
    		var notepadFontDialog = notepadWindow.$(StdWin.Dialog({windowTitleRegExp:"Font"}));

    		// Verify that the Font dialog box was opened
    		expect(notepadFontDialog.exists(2)).toBeTruthy();

    		var ENTER_KEY_SCAN_CODE = 28;
    		Keyboard.pressKey(ENTER_KEY_SCAN_CODE); // Close the Font dialog by low level pressing the ENTER key on the keyboard

    		Mouse.doubleClick(16, 16); //Double click using the low level mouse operation on the system menu icon area to close the notepad application

    		expect(notepadWindow.exists(2)).toBeFalsy();

    		LFT.whenDone(done);
    	});

    	afterEach(function(done){
    		LFT.afterTest();
    		LFT.whenDone(done);
    	});

    	afterAll(function(done){
    		LFT.cleanup();
    		LFT.whenDone(done);
    	});
    });

Back to top

See also:

- JavaScript SDK
- JavaScript SDK code samples

https://admhelp.microfocus.com Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: