Automating message boxes (Java, SWT)

Last edited on

Overview

While replay with Squish native SWT dialogs (including message boxes (org.eclipse.swt.widgets.MessageBox) are not being shown.

However, the message on such messages boxes can be verified by installing an event handler. Then, when the dialog would normally be shown, the event handler gets called with the message of the dialog as parameter.

import names

# Added this line to the recorded script:
last_messagebox_message = None

def main():
    startApplication("swt_control_example")

    # Added this line to the recorded script:
    installEventHandler("MessageBoxOpened", "event_messagebox_opened")

    ...

    # Added these two lines to the recorded script:
    global last_messagebox_message
    last_messagebox_message = None

    clickButton(waitForObject(names.Dialog_Type_Create_Dialog_Button))
    closeMessageBox(waitForObject(names.SWT), SWT.OK)

    # Added this line to the recorded script:
    test.compare("Example_string", last_messagebox_message)

# Added this function to the recorded script:
def event_messagebox_opened(message):
    global last_messagebox_message
    last_messagebox_message = message
test.py