Share this page

# Terminal Emulator code samples (JavaScript SDK)

In this topic:

## Wait for text in the emulator screen

This example demonstrates how to use terminal emulator objects and their respective properties to wait for a text in the emulator screen.

    it("Verify waitForText method",function(done) {
    	// Following is the program flow:
    	// 1. Need to have a Terminal Emulator configured.
    	// 2. Identify a TeScreen test object based on some descriptive properties.
    	// 3. Select text from the emulator screen that you want to wait for. Example "Program/procedure". OR
    	//    The user can insert text into a field and verify with WaitForText method if the text was inserted.
    	// 4. Define an Area() object where the text is located and select the timeout in milliseconds.
    	// 5. Call method WaitForText() with all above parameters. For the text string, use a regular expression to find it.
    	// 6. The test has two cases, when the text exists on the screen and when not.
    	// 7. Use the Assert statement to verify that "Program/procedure" exsits on the emulator screen.

    	//Identify Window and Screen based on descriptive properties.
    	var screen = Desktop.$(TE.Window({
    			shortName: "A"
    		}
    	)).$(TE.Screen({
    			label: "screen10365"
    		}
    	));
    	//Identify Field based on descriptive properties.
    	var field = screen.$(TE.Field({
    			attachedText: "User",
    			isProtected: false
    		}
    	));

    	//Insert dummy text to an unprotected field.
    	field.setText("Something");

    	//Call WaitForText method with inserted text to find it on the emulator screen.
    	//The method will return a bool to indicate if the text was found or not. For this case, we should have true.
    	//If we don't create an Area object, the method will search in whole screen.
    	screen.waitForText(new RegExp("Something"), 500).then(function (isText) {
    		assert.deepEqual(isText, true);
    	});

    	//Call WaitForText method with below parameters to find the text on the emulator screen.
    	//The method will return a bool to indicate if the text was found or not. For this case, we should have true.
    	screen.waitForText(new RegExp("Program/procedure"), {top: 8, left: 17, bottom: 8, right: 33}, 500).then(function (res) {
    		assert.deepEqual(res, true);
    	});

    	//Call WaitForText method with below parameters to find the text on the emulator screen.
    	//The method will return a bool to indicate if the text was found or not. For this case, we should have false.
    	screen.waitForText("12352", {top: 8, left: 17, bottom: 8, right: 33}, 500).then(function (res) {
    		assert.deepEqual(res, false);
    	});

    	LFT.whenDone(done);
    });

Back to top

## Send a TE Key on the screen

This example demonstrates how to use terminal emulator objects and their respective properties to send a TE Key on the screen

    it("Verify sendTEKeys method",function(done){
    	// Following is the program flow:
    	// 1. Need to have a Terminal Emulator configured.
    	// 2. Identify a TeScreen test object based on some descriptive properties.
    	// 3. Call method SendKey() with a string as parameter, for example "Something", and a TE Key, for example Backspace.
    	// 4. Call WaitForText() method to verify if the inserted text exists.

    	//Identify Window and Screen based on descriptive properties.
    	var screen = Desktop.$(TE.Window({
    			shortName:"A"
    		}
    	)).$(TE.Screen({
    			label:"screen10365"
    		}
    	));

    	//Call SendTEKeys method with a string and a TE Key
    	//The method will send to the emulator screen (at the cursor position) the string text + the TE Key.
    	screen.sendTEKeys("Something" + TE.Keys.backspace);

    	//Call WaitForText method with inserted text to find it on the emulator screen.
    	//The method will return a bool to indicate if the text was found or not. For this case, we should have true.
    	//If we don't create an Area object, the method will search in whole screen.
    	screen.waitForText(new RegExp("Somethin")).then(function (res) {
    		assert.deepEqual(res, true);
    	});

    	LFT.whenDone(done);
    });

Back to top

Tips to improve your search results... UFT Developer JavaScript SDK Reference Version 15.0-15.0.2 UFT Developer SDK Reference All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version: