TomWiedenhoeft - 2005-02-24

Hallo, again!

Here is a modified classes that might interest you.

Benefit:
FindTagHandler.java can block the program flow.
Examples:
- Wait until a Dialog has disappeared
- Wait until a label changes its text

If you think this modification is usefull for you or other users please intergrate it into the official version.
It would be very helpfull because we (at Siemens L&A PA) won't have any trouble if you come out with the next version of JFC-Unit.

Thanks a lot.
Tom Wiedenhoeft

P.S. Please note to modify the files XMLConstants.java as shown below.

---schnipp -- FindTagHandler.java ---

package junit.extensions.jfcunit.finder;

import junit.extensions.jfcunit.xml.JFCXMLConstants;

import junit.extensions.xml.IXMLTestCase;
import junit.extensions.xml.XMLException;
import junit.extensions.xml.XMLTagResourceBundle;
import junit.extensions.xml.elements.AbstractTagHandler;

import org.w3c.dom.Element;

/**
* This element helps locate objects within the gui. It
* uses the underlying JFCUnit finders to locate objects.
* The finders implementation may be extended via the
* TagMapping.properties file specified in the classpath.
*
* <h3>Description</h3>
* <p>
*   This creates a DialogFinder and executes the find.
* </p>
*
* <h3>Parameters</h3>
* <table border="1" cellpadding="2" cellspacing="0">
*   <tr>
*     <td valign="top"><b>Attribute</b></td>
*     <td valign="top"><b>Description</b></td>
*     <td align="center" valign="top"><b>Required</b></td>
*     <td valign="top"><b>Default</b></td>
*     <td valign="top"><b>Values</b></td>
*   </tr>
*   <tr>
*     <td valign="top">finder</td>
*     <td valign="top">This element specifies the finder implementation to use.</td>
*     <td valign="top" align="center">Yes</td>
*     <td valign="top">N/A</td>
*     <td valign="top">AbstractButtonFinder ComponentFinder DialogFinder FrameFinder
*     JLabelFinder JMenuItemFinder JWindowFinder NamedComponentFinder or other custom
*     finder tags specified in TagMapping.properties.</td>
*   </tr>
*   <tr>
*     <td valign="top">id</td>
*     <td valign="top">Id for the object found.</td>
*     <td valign="top" align="center">Yes</td>
*     <td valign="top">N/A</td>
*     <td valign="top">String</td>
*   </tr>
*   <tr>
*     <td valign="top">waitForDisappearing</td>
*     <td valign="top">maximum time the programm flow is blocked
*                      if the component does not disappear. Can be
*                         used to wait until a Dialog has disappeared
*                      or a label changes its text for example.</td>
*     <td valign="top" align="center">No</td>
*     <td valign="top">N/A</td>
*     <td valign="top">integer value, time in seconds</td>
*   </tr>
*   <tr>
*     <td valign="top">others</td>
*     <td valign="top">See corresponding tag handler implementation
*     for a definition of other attributes that may be required.</td>
*     <td valign="top" align="center">Yes</td>
*     <td valign="top">N/A</td>
*     <td valign="top">N/A</td>
*   </tr>
* </table>
* <h3>Example</h3>
* <blockquote><pre>
* &lt;find
*    finder=&quot;DialogFinder&quot;
*    id=&quot;MyDialog&quot;
*    title=&quot;^My dialog box$&quot;
* /&gt;
* </pre></blockquote>
* <p>
* The above uses the TagHandler associated with the DialogFinder tag in the
* TagMapping.properties file. In the default jfcUnit case this would be the
* junit.extensions.jfcunit.finder.DialogFinderTagMapping.
* </p>
*
* @see junit.extensions.jfcunit.finder.AbstractButtonFinderTagHandler
* @see junit.extensions.jfcunit.finder.ComponentFinderTagHandler
* @see junit.extensions.jfcunit.finder.DialogFinderTagHandler
* @see junit.extensions.jfcunit.finder.FrameFinderTagHandler
* @see junit.extensions.jfcunit.finder.JLabelFinderTagHandler
* @see junit.extensions.jfcunit.finder.JMenuItemFinderTagHandler
* @see junit.extensions.jfcunit.finder.JWindowFinderTagHandler
* @see junit.extensions.jfcunit.finder.NamedComponentFinderTagHandler
* @see junit.extensions.jfcunit.finder.JPopupMenuFinderTagHandler
* @see junit.extensions.jfcunit.finder.LabeledComponentFinderTagHander
* @author Kevin Wilson
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
* @author tom@smart-tail.com (Tom Wiedenhoeft, DV-Ratio acting under contract with Siemens L&A PA)
*/
public class FindTagHandler extends AbstractTagHandler
    implements JFCXMLConstants {
    /**
     * Constructor for FindTagHandler.
     *
     * @param element     The element to be processed
     * @param testCase    The IXMLTestCase that uses this element
     */
    public FindTagHandler(final Element element, final IXMLTestCase testCase) {
        super(element, testCase);
    }

    /**
     * Returns the value of the FINDER attribute for this element.
     * @return String  The value of the FINDER attribute.
     */
    public String getFinder() {
        return getString(FINDER);
    }

    /**
     * Returns the value of the NAME attribute for this element.
     * @return String  The value of the NAME attribute.
     */
    public String getName() {
        return getString(NAME);
    }

    /**
     * Get the Wait time for the finder. Default is 10 second.
     * @return Duration for the Finder to try again until the
     * object is found.
     */
    protected String getWaitForDisappearing() {
        return getString(WAIT_FOR_DISAPPEARING);
    }

    /**
     * @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
     */
    public void processElement() throws XMLException {
        this.validateElement();

        XMLTagResourceBundle.getTagHandler(
            getElement(),
            getXMLTestCase(),
            getFinder()).processElement();

        // If the waitForDisappearing attribute was given
        String disappearingTime = this.getWaitForDisappearing();
        if(disappearingTime != null && ! "".equals(disappearingTime))
        {
            // Take the start time.
            int block = Math.max(0, Integer.parseInt(disappearingTime));
            long date = System.currentTimeMillis() + (block * 1000);

            while (System.currentTimeMillis() < date)
            {
                // Was the component found?
                String id = this.getString(ID);
                Object o = getXMLTestCase().getProperty(id);
                // System.out.println(id + " - Flow not blocked.");
                // System.out.println(id + " - Was the component found?");
                if(o == null)
                {
                    // The component was not found. Do not block any longer.
                    // System.out.println(id + " - The component was not found (disappeared).");
                    return;
                }
                else
                {
                    // System.out.println(id + " - The component was found.");
                    // System.out.println(id + " - Finding the component again...");
                    // Can the component be found again?
                    // !!! WATCH THIS:
                    //     If the wait time (attribute wait) was set high
                    //     for example to 20 second and the component is not found...
                    XMLTagResourceBundle.getTagHandler(
                            getElement(),
                            getXMLTestCase(),
                            getFinder()).processElement();
                }
                /*try {
                    wait(50);
                } catch(InterruptedException e) {
                    e.printStackTrace();
                }*/
            }
        }
    }

    /**
     * @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
     */
    public void validateElement() throws XMLException {
        // do the default validations from the super class
        super.validateElement();

        // check the element tag name
        checkElementTagName(FIND);

        // required attribute: class
        checkRequiredAttribute(FINDER);
    }
}

---schnapp -- FindTagHandler.java ---

Please add in XMLConstants.java

---schnipp -- XMLConstants.java ---
    /** waitForDisappearing */
    String WAIT_FOR_DISAPPEARING = "waitForDisappearing";
---schnapp -- XMLConstants.java ---