Terminal Emulator code samples

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.

@Test
public void testWaitForText() throws GeneralLeanFtException {
	//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 we 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.
	Screen screen = Desktop.describe(com.hp.lft.sdk.te.Window.class, new WindowDescription.Builder()
		.protocol(com.hp.lft.sdk.te.Protocol.PR5250).build()).describe(Screen.class, new ScreenDescription.Builder()
		.label("screen10365").build());
	//Identify Field based on descriptive properties.
	Field field = screen.describe(Field.class, new FieldDescription.Builder()
		.attachedText("User").isProtected(false).build());

	//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.
	boolean isText = screen.waitForText(new RegExpProperty("Something"), 500);
	Assert.assertTrue(isText);

	//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.
	boolean onscreen = screen.waitForText(new RegExpProperty("Program/procedure"), new Area(8, 17, 8, 33), 500);
	Assert.assertTrue(onscreen);

	//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.
	boolean notonscreen = screen.waitForText("12352", new Area(8, 17, 8, 33), 500);
	Assert.assertFalse(notonscreen);
}

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

@Test
public void testSendTEKeys() throws GeneralLeanFtException {
	// 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.
	Screen screen = Desktop.describe(com.hp.lft.sdk.te.Window.class, new WindowDescription.Builder()
		.protocol(com.hp.lft.sdk.te.Protocol.PR5250).build()).describe(Screen.class, new ScreenDescription.Builder()
		.label("screen10365").build());


	//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" + com.hp.lft.sdk.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.
	boolean isText = screen.waitForText(new RegExpProperty("Somethin"), 500);
	Assert.assertTrue(isText);
}

Back to top