Automating message boxes (Java, SWT)

Last edited on


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():

    # 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

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

    # Added this line to the recorded script:"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