Marathon Tutorial – v1.0.2 (part 2)

Jean Lazarou
January, 2008

Preface

I received some question about Marathon testing tool, I am not using it and do not consider myselt as a Marathon expert. Still, as the question didn't seem too complicated I decided to write this second part of the Marathon tutorial as a FAQ page.

See the main tutorial page here

Testing message in a message window.

Question: When the user clicks on some button, the application may displays some message in a message windows. Who can we validate that message?

The application

Let's first create a simple application implementing a button that, when clicked, show a message.

Create a frame window with a text and a button:

src/org/alef1/marathon/tutorial/dialog/Main.java
package ...

  public static void main(String[] args) {

    final JFrame frame = new JFrame();

      ...

      JButton execButton = new JButton("Execute");

      execButton.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(frame, "Execution was successful!");
      }

    });

    ...

  }
We present only the main parts... next picture is the main window the user sees.

We the user click the execute button, the application show a message window (see next picture).

Writing the test...

We skip the Marathon project creation and only show the testing script.

src/org/alef1/marathon/tutorial/dialog/Main.java
useFixture(default)

  def test():
    java_recorded_version = '1.6.0_01'

    if window('Main Window'):
      click('Execute')

      if window('Message'):
        assert_p('OptionPane.label', 'Text', 'Execution was successful!')
        click('OK')
      close()

    close()

The cleat effect is once we get the main window, we simulate the button click and then, if the message window appears, we assert that the label field inside the option pane contains the expected text.

Tip

Actually we helped ourselves by recording the script and then rewrote it. To record the assertion, we right-clicked on the text we wanted to test, while holding down the control key (on Windows).


Download

You can download the code here.