#64 Keystrokes to insert Asserts into test scripts.

open
Timothy Wall
5
2005-08-12
2005-08-12
Jeff Grimshaw
No

It would be nice to be able to insert Assert statements
into a test script as I'm capturing the process of
going through my application. There are a small set of
Asserts that I use most of the time (e.g., isVisible(),
isEnabled(), getText().equals(), etc.). Even if I
wanted a different assertion at least this key stroke
would put an assert "place holder" in my test script
with a good reference to the component.

This feature is really needed when testing applications
with modal windows, but it would be useful with all
applications. For instance, on a screen with 10 text
fields, I could easily put the cursor over each field,
click Alt Shift T and Costello would insert an Assert
that checked that the text matched whatever was
currently in the text field.

Following the Alt Shift F1 standard, I propose:

Alt Shift E - Assert isEnabled() == sampledComp.isEnabled()
Alt Shift I - Assert getSelectedItem() ==
sampleComp.getSel...
Alt Shift S - Assert isSelected() ==
sampleComp.isSelected()
Alt Shift T - Assert getText() == sampledComp.getText()
Alt Shift V - Assert isVisible() == sampleComp.isVisible()

I was looking at abbot.editor.ScriptEditor for how I
might put this in, but I'm kind of stuck.

We have dozens of screens, many with over 20
components. This would speed up test script creation
significantly.

Thanks,
Jeff

Discussion

  • Logged In: NO

    I added the following to ScriptEditor's processEvent()
    method to test out the idea. It just handles isEnabled()
    and getText(). It's a little rough but it works pretty well.

    Sorry I haven't got CVS working so this is not a patch.

    -- Jeff

    /** The editor does many things with the event stream,
    including logging
    * events, passing them off to the recorder, and
    updating its internal
    * state.
    */
    private void processEvent(AWTEvent event) {
    ...

    // Record isEnabled on alt+shift+e
    else if (isKeyRelease(event, KeyEvent.VK_E,
    KeyEvent.SHIFT_MASK | KeyEvent.ALT_MASK)) {
    Log.debug("Insert isEnabled Assert into script");

    try {
    selectComponent(ultimateComponent, true);

    Class cls = ultimateComponent.getClass();

    Method method = cls.getMethod("isEnabled",
    new Class[0]);
    Object value = new
    Boolean(ultimateComponent.isEnabled());

    invertAssertions = false;

    addPropertyMethodCall(method, value, false);
    }
    catch (Exception e1) {
    e1.printStackTrace();
    }
    }

    // Record getText on alt+shift+t
    else if (isKeyRelease(event, KeyEvent.VK_T,
    KeyEvent.SHIFT_MASK | KeyEvent.ALT_MASK)) {
    Log.debug("Insert getText Assert into script");

    try {
    selectComponent(ultimateComponent, true);

    Class cls = ultimateComponent.getClass();

    Method method = cls.getMethod("getText", new
    Class[0]);

    Object value = null;

    if (ultimateComponent instanceof JLabel) {
    value = ((JLabel)
    ultimateComponent).getText();
    }
    else if (ultimateComponent instanceof
    JTextComponent) {
    value = ((JTextComponent)
    ultimateComponent).getText();
    }

    invertAssertions = false;

    addPropertyMethodCall(method, value, false);
    }
    catch (Exception e1) {
    e1.printStackTrace();
    }
    }

     
  • Jeff Grimshaw
    Jeff Grimshaw
    2005-08-19

    Logged In: YES
    user_id=552874

    I've created a CVS Patch with these changes.

    -- Jeff

     
  • Jeff Grimshaw
    Jeff Grimshaw
    2005-08-19

    Logged In: YES
    user_id=552874

    This time for sure.

     
  • Jeff Grimshaw
    Jeff Grimshaw
    2005-08-19

    ScriptEditorPatch with Keystroke insertion of Asserts.

     
  • Timothy Wall
    Timothy Wall
    2005-10-31

    Logged In: YES
    user_id=54098

    working on this one. I refactored the event handling in the editor to be
    much clearer.

     
  • Excellent post however I was wanting to know if you could write a litte more on this subject? I'd be very grateful if you could elaborate a little bit further. Appreciate it!
    north face jackets for women http://picaolwhol.hpage.com/

     
  • Thank you for any other informative blog. The place else may just I get that kind of information written in such a perfect way? I've a undertaking that I am just now operating on, and I've been at the look out for such info. Celine Outlet http://celineoutlet.v5s7.com