Terminal Emulator code samples (.NET SDK)

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()
{
	// 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 and for the text string use 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" exsists on the emulator screen.

	//Identify IWindow and IScreen based on descriptive properties.
	IScreen screen = Desktop.Describe<IWindow>(new WindowDescription
	{

		EmulatorStatus = HP.LFT.SDK.TE.EmulatorStatus.Ready,
		Protocol = HP.LFT.SDK.TE.Protocol.Pr5250

	}).Describe<IScreen>(new ScreenDescription
	{
		Label = @"screen10365"
	});

	//Identify IField based on descriptive properties.
	IField field = screen.Describe<IField>(new FieldDescription
	{
		AttachedText = @"User",
		IsProtected = false
	});

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

	//Call WaitForText method with the inserted text to find it on the emulator screen.
	//The method returns 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 searches in the whole screen.
	bool isText = screen.WaitForText(As.RegExp("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 returns a bool to indicate if the text was found or not. For this case,  we should have true.
	bool onscreen = screen.WaitForText(As.RegExp("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 returns a bool to indicate if the text was found or not. For this case, we should have false.
	bool 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()
{
	// 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 IWindow and IScreen based on descriptive properties.
	IScreen screen = Desktop.Describe<IWindow>(new WindowDescription
	{

		EmulatorStatus = HP.LFT.SDK.TE.EmulatorStatus.Ready,
		Protocol = HP.LFT.SDK.TE.Protocol.Pr5250

	}).Describe<IScreen>(new ScreenDescription
	{
		Label = @"screen10365"
	});

	//Call SendTEKeys method with a string and a TE Key
	//The method sends to the emulator screen (at the cursor position) the string text + the TE Key.
	screen.SendTEKeys("Something" + LFT.SDK.TE.Keys.BACKSPACE);
            
	//Call WaitForText method with inserted text to find it on the emulator screen.
	//The method returns 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 searches in the whole screen.
	bool isText = screen.WaitForText(As.RegExp("Something"), 500);
	Verify.IsTrue(isText, "Verify Screen Text", "Verify that the screen contains the text 'Something'.");
}

Back to top