Open topic with navigation

# Terminal Emulator code samples (Java 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.

    @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 a text from the emulator screen that you want to wait for it. Example "Program/procedure". OR
    	//    The user can insert a 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 and for the text string we are using regular expression to find it.
    	// 6. The test has two cases, when the text exists on the screen and when not.
    	// 7. Use the Verify statement to verify that "Program/procedure" exists 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 a 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 tell 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);
    	Verify.isTrue(isText, "Verify Screen Text Step 1", "Verify that the screen contains the text 'Something'.");

    	//Call WaitForText method with below parameters to find the text on the emulator screen.
    	//The method will return a bool to tell 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);
    	Verify.isTrue(onscreen, "Verify Screen Text Step 1", "Verify that the screen in a certain screen area contains the text 'Program/procedure'.");

    	//Call WaitForText method with below parameters to find the text on the emulator screen.
    	//The method will return a bool to tell 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);
    	Verify.isFalse(notonscreen, "Verify Screen Text Step 1", "Verify that the screen in a certain screen area does not contain the text '12352'.");
    }

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 example "Something" and a TE Key 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 tell 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);
    	Verify.isTrue(isText, "Verify Screen Text", "Verify that the screen contains the text 'Something'.");
    }

Back to top