WPF code sample (in Java)

End-to-End: Reserve a flight using WPF objects

The example below demonstrates how to create a program which simulates a flight booking on the Flight GUI sample application.

The example includes a SetSecure step for logging in.

public void testFlightSampleApplication() throws GeneralLeanFtException, ParseException {
	flightGUIAapplicationWindow = Desktop.describe(Window.class, new WindowDescription.Builder().objectName("Micro Focus MyFlight Sample")
		.fullType("window").windowTitleRegExp("Micro Focus MyFlight Sample").build());

private void performLogin() throws GeneralLeanFtException{
	// Sample showing how to perform the actions to login in to the Flight GUI sample application
	// Identify the user name field
	EditField userNameEdit = flightGUIAapplicationWindow.describe(EditField.class, new EditFieldDescription.Builder()
	userNameEdit.setText("john"); // Fill in the user name field
	// Identify the password field
	EditField passwordEdit = flightGUIAapplicationWindow.describe(EditField.class, new EditFieldDescription.Builder()
	// Fill in the password field. You should use the encryption utility to find out the encrypted string (see the LeanFT documentation). 
	// Here, for sample and clarity, we use plain text.
	// Identify the OK button
	Button okButton = flightGUIAapplicationWindow.describe(Button.class, new ButtonDescription.Builder()
	okButton.click(); // Click on the OK button
private void searchForFlight() throws GeneralLeanFtException, ParseException{

private void chooseFlightSourceAndDestination() throws GeneralLeanFtException{
	// Identify the "from city" combobox
	ComboBox fromCityComboBox = flightGUIAapplicationWindow.describe(ComboBox.class, new ComboBoxDescription.Builder()
	// Select a combobox item using a numeric index. The index of "Los Angeles" in the combobox is 3 (The combobox indexes are 0 based).

	// Identify the "to city" combobox
	ComboBox toCityComboBox = flightGUIAapplicationWindow.describe(ComboBox.class, new ComboBoxDescription.Builder()
	// Select a combobox item using a string value. We will select the item with the string "London"

private void chooseFlightDate() throws GeneralLeanFtException, ParseException{
	// Identify the date picker control.
	Calendar flightDatePicker = flightGUIAapplicationWindow.describe(Calendar.class, new CalendarDescription.Builder()
	SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
	Date date = sdf.parse("1/8/2025");
	flightDatePicker.setDate(date); // Choose flight date - choose August 1st, 2025
private void chooseFlightClassAndNumberOfTickets() throws GeneralLeanFtException{
	// Identify the flight class combobox
	ComboBox flightClassCombobox = flightGUIAapplicationWindow.describe(ComboBox.class, new ComboBoxDescription.Builder()
		.objectName("Class").fullType("combo box").build());
	// Identify the number of tickets combobox
	ComboBox numOfTickets = flightGUIAapplicationWindow.describe(ComboBox.class, new ComboBoxDescription.Builder()
	numOfTickets.select("2"); // Choose 2 tickets to buy
private void openFlightsTable() throws GeneralLeanFtException{
	// Identify the "FIND FLIGHTS" button
	Button findFlightsButton = flightGUIAapplicationWindow.describe(Button.class, new ButtonDescription.Builder()
		.text("FIND FLIGHTS").objectName("FIND FLIGHTS").build());
	findFlightsButton.click(); // click on the button
private void selectFlight() throws GeneralLeanFtException{
	// Identify the flights data grid
	Table flightsDataGrid = flightGUIAapplicationWindow.describe(Table.class, new TableDescription.Builder()
	flightsDataGrid.selectRow(2); // Select the third row in the data grid

	Button selectFlightButton = flightGUIAapplicationWindow.describe(Button.class, new ButtonDescription.Builder()
		.text("SELECT FLIGHT").objectName("selectFlightBtn").build());
	selectFlightButton.click(); // Click on the "Select Flight" button
private void finishOrder() throws GeneralLeanFtException{
	// Identify the passenger name edit field
	EditField passengerNameField = flightGUIAapplicationWindow.describe(EditField.class, new EditFieldDescription.Builder()
	passengerNameField.setText("John Doe"); // Enter the passenger name

	// Identify the total price field
	UiObject totalPrice = flightGUIAapplicationWindow.describe(UiObject.class, new UiObjectDescription.Builder().objectName("totalPrice").build());
	String expectedPrice = "$652.00";
	String actualPrice = totalPrice.getText();
	Verify.areEqual(expectedPrice, actualPrice, "Verify Total Price", "Verify that the total price is correct ($652.00)."); // Verify the price is $652.00
	// Identify the "Order" button
	Button oderButton = flightGUIAapplicationWindow.describe(Button.class, new ButtonDescription.Builder().text("ORDER").objectName("orderBtn").build());
	oderButton.click(); // Click on the "Order" button to perform the flight reservation
private void verifyOrderCompleted() throws GeneralLeanFtException{
	// Identify the order completed text
	UiObject orderCompletedControl = flightGUIAapplicationWindow.describe(UiObject.class, new UiObjectDescription.Builder().objectName("orderCompleted").build());
	WaitUntilEvaluator<UiObject> evaluator = new WaitUntilEvaluator<UiObject>() {
		public boolean evaluate(UiObject testObject) {
			try {
				return testObject.isVisible();
			} catch (GeneralLeanFtException e) {
			return false;
	boolean result = waitUntil(orderCompletedControl, evaluator, 5000);
	Verify.isTrue(result, "Verify Order Completed Control Exists", "Wait to verify the order completed control appears.");
	String orderCompletedControlText = orderCompletedControl.getText(); // Get the "order completed" control's text

	Verify.isTrue(orderCompletedControlText.endsWith("completed"), "Verify Order Completed Control Text", "Verify that the order completed control contains the text 'completed'.");
private void exitFlightApp(){

Back to top

Change a toggle button state

This example locates a toggle button and changes the toggle button state.

public void testWpfToggleButton() throws GeneralLeanFtException {
	// Identify the application that has the toggle button.
	Window appMainWindow = Desktop.describe(Window.class, new WindowDescription.Builder().objectName("MainWindow").fullType("window").windowTitleRegExp("MainWindow").build());

	// Identify the button that supports the WPF toggle mechanism.
	Button buttonWithToggleButtonSupport = appMainWindow.describe(Button.class, new ButtonDescription.Builder().text("Toggle Button").objectName("Button4").build());
	ToggleButton toggleButton = buttonWithToggleButtonSupport.getToggleButton();
	toggleButton.set(CheckedState.CHECKED); // Example for setting the toggle button's state to checked

	// Change the toggle button state.
	if (toggleButton.isChecked()) {
	} else {

Back to top

See also: