View Javadoc

1   /*
2       Jiffie Plugin for Jameleon - An Internet Explorer plug-in for Jameleon
3       Copyright (C) 2004-2006 Christian W. Hargraves (engrean@hotmail.com) and
4                          Matthias Marschall (matthias@marschalls.de)
5   
6       This program is free software; you can redistribute it and/or modify
7       it under the terms of the GNU General Public License as published by
8       the Free Software Foundation; either version 2 of the License, or
9       (at your option) any later version.
10  
11      This program is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.
15  
16      You should have received a copy of the GNU General Public License
17      along with this program; if not, write to the Free Software
18      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  package net.sf.jameleon.plugin.jiffie;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.Iterator;
25  import java.util.List;
26  import java.util.NoSuchElementException;
27  
28  import junit.framework.Assert;
29  import net.sf.jameleon.function.FunctionTag;
30  import net.sf.jameleon.plugin.jiffie.util.DocumentDelegate;
31  import net.sf.jameleon.plugin.jiffie.util.IHTMLElementFinder;
32  import net.sf.jameleon.util.AssertLevel;
33  import net.sf.jameleon.util.Configurator;
34  import net.sf.jameleon.util.JameleonUtility;
35  
36  import org.jaxen.JaxenException;
37  import org.jaxen.XPath;
38  
39  import com.jacob.com.ComFailException;
40  import net.sf.jiffie.BlockingClickThread;
41  import net.sf.jiffie.ElementContainer;
42  import net.sf.jiffie.ElementFactory;
43  import net.sf.jiffie.ElementList;
44  import net.sf.jiffie.IHTMLAnchorElement;
45  import net.sf.jiffie.IHTMLDOMNode;
46  import net.sf.jiffie.IHTMLDocument2;
47  import net.sf.jiffie.IHTMLElement;
48  import net.sf.jiffie.IHTMLFormElement;
49  import net.sf.jiffie.IHTMLFrameBase2;
50  import net.sf.jiffie.IHTMLInputElement;
51  import net.sf.jiffie.IHTMLOptionElement;
52  import net.sf.jiffie.IHTMLSelectElement;
53  import net.sf.jiffie.IHTMLTextAreaElement;
54  import net.sf.jiffie.InternetExplorer;
55  import net.sf.jiffie.JiffieException;
56  import net.sf.jiffie.JiffieUtility;
57  import net.sf.jiffie.TrackingElementFactory;
58  import net.sf.jiffie.xpath.JiffieXPath;
59  
60  /***
61   * This is the base FunctionTag for the Jiffie Plug-in. 
62   * To create a custom functional point for the Jiffie Plug-in, simply create a class that extends this class. To make it
63   * functional, simply implement the FunctionTag.testBlock method.
64   */
65  public abstract class IEFunctionTag extends FunctionTag implements DocumentDelegate{
66      /***
67       * Whether or not to wait for a response. Use this attribute if you need to click on something
68       * that brings up a prompt window. Just remember that this setting is for the entire duration of the
69       * tag. Which means if you click on a link and then try to validate something within the same tag, then
70       * it will likely fail. Use with care!
71       * @jameleon.attribute default="true"
72       */
73      protected boolean WAIT = true;
74  
75      /***
76       * The session within which the function tag is running
77       */
78      protected IESessionTag session = null;
79  
80      /***
81       * Defines whether the InternetExplorer windows shall be visible or not
82       */
83      protected boolean visible = false;
84      /***
85       * Whether or not to highlight the currently active HTML element.
86       * This attribute can be set in jameleon.conf via jiffie-plugin.highlightActiveElement
87       * @jameleon.attribute default="true"
88       */
89      protected boolean highlightActiveElement = true;
90      /***
91       * The name attribute of the frame or iframe to act upon. This can also be a comma-separated list of names.
92       * @jameleon.attribute
93       */
94      protected String frameName;
95      /***
96       * The id attribute of the frame or iframe to act upon. This can also be a comma-separated list of ids.
97       * @jameleon.attribute
98       */
99      protected String frameId;
100     /***
101      * The src attribute of the frame or iframe to act upon. This can also be a comma-separated list of src attributes.
102      * @jameleon.attribute
103      */
104     protected String frameSrc;
105     
106     /***
107      * The reference to the current instance of the Internet Explorer. This is the current IE window.
108      */
109     protected InternetExplorer ie;
110 
111     /***
112      * The current form to do submits and value setting
113      */
114     protected IHTMLFormElement workingForm;
115 
116     /***
117      * Used for some helper methods to find elements.
118      */
119     protected IHTMLElementFinder elementFinder;
120 
121     private ElementFactory originalFactory;
122 
123     /***
124      * Gets the references of the session and the test results from the parent TestCase
125      * This method gets called once all attributes are set from the macro language. Any required
126      * setup should go here.
127      */
128     public void setupEnvironment() {
129         super.setupEnvironment();
130 
131         TrackingElementFactory factory = new TrackingElementFactory();
132         originalFactory = JiffieUtility.setElementFactory(factory);
133 
134         elementFinder = new IHTMLElementFinder(this);
135         Object obj = findAncestorWithClass(IESessionTag.class);
136         if (obj instanceof IESessionTag) {
137             session = (IESessionTag) obj;
138         } else {
139             throw new ClassCastException("Can only execute an Internet Explorer function tag under the IE session tag ( ie-session )! " +
140                     "Please change the session tag surrounding function point " + getClass().getName());
141         }
142         ie = session.getCurrentIE();
143         visible = session.getVisible();
144         Configurator config = Configurator.getInstance();
145         String highlight = config.getValue("jiffie-plugin.highlightActiveElement");
146 
147         if (highlight != null && highlight.trim().length() > 0) {
148             highlightActiveElement = new Boolean(highlight).booleanValue();
149         }
150     }
151 
152     //Storable Method
153     public void store(String fName, int event) throws IOException {
154         try {
155             String html = null;
156             String filename = fName + ".html";
157 
158             IHTMLDocument2 doc = null;
159             String tmpFrameName = frameName;
160             String tmpFrameId = frameId;
161             try{
162                 doc = getDocument();
163                 if (doc != null) {
164                     html = doc.getBody().getParentElement().getOuterHtml();
165                 }else{
166                     frameName = null;
167                     frameId = null;
168                     doc = getDocument();
169                     if (doc != null) {
170                         html = doc.getBody().getParentElement().getOuterHtml();
171                     }
172                 }
173             }catch(JiffieException je){
174                 log.debug("couldn't get html contents!");
175                 log.debug(JameleonUtility.getStack(je));
176             }finally{
177                 if (doc != null) {
178                     doc.release();
179                 }
180                 frameName = tmpFrameName;
181                 frameId = tmpFrameId;
182             }
183 
184             if (html != null && html.length() > 0) {
185                 File f = new File(filename);
186                 JameleonUtility.recordResultsToFile(f, html);
187                 getFunctionResults().setErrorFile(f);
188             } else {
189                 log.debug("Not writing results to file because there is no html to be written.");
190             }
191 
192         } catch (IOException ioe){
193             throw new IOException(JameleonUtility.createErrMsg("Unable to get response to store to file in function <" + functionId + ">:\n\r " + JameleonUtility.getStack(ioe)));
194         } catch (RuntimeException re) {
195             re.printStackTrace();
196             throw new IOException(JameleonUtility.createErrMsg("Unable to get response to store to file in function <" + functionId + ">:\n\r " + JameleonUtility.getStack(re)));
197         }
198     }
199     //End Storable Method
200 
201     public IHTMLDocument2 getDocument(){
202         IHTMLDocument2 doc = null;
203         try{
204             if (ie != null && !ie.isReleased()) {
205                 doc = ie.getDocument(WAIT);
206                 if (frameName != null && frameName.trim().length() > 0 && doc != null) {
207                     Object obj = elementFinder.getFrameWithName(doc, frameName);
208                     if (obj != null && obj instanceof IHTMLFrameBase2) {
209                         doc  = ((IHTMLFrameBase2)obj).getDocument(WAIT);
210                     }
211                     if (obj == null ){
212                         throw new RuntimeException("Could not find a frame with the given name '"+frameName+"'!");
213                     }
214                 }else if (frameId != null && frameId.trim().length() > 0 && doc != null) {
215                     Object obj = elementFinder.getFrameWithId(doc, frameId);
216                     if (obj != null && obj instanceof IHTMLFrameBase2) {
217                         doc  = ((IHTMLFrameBase2)obj).getDocument(WAIT);
218                     }
219                     if (obj == null ){
220                         throw new RuntimeException("Could not find a frame with the given id '"+frameId+"'!");
221                     }
222                 }else if (frameSrc != null && frameSrc.trim().length() > 0 && doc != null) {
223                     Object obj = elementFinder.getFrameWithSrc(doc, frameSrc);
224                     if (obj != null && obj instanceof IHTMLFrameBase2) {
225                         doc  = ((IHTMLFrameBase2)obj).getDocument(WAIT);
226                     }
227                     if (obj == null ){
228                         throw new RuntimeException("Could not find a frame with the given src '"+frameSrc+"'!");
229                     }
230                 }
231             }
232         }catch(ComFailException cfe){
233             traceMsg("Couldn't get the current document: ");
234             traceMsg(JameleonUtility.getStack(cfe));
235         }catch(JiffieException je){
236             traceMsg("Trouble getting the current document: ");
237             traceMsg(JameleonUtility.getStack(je));
238         }catch(NullPointerException npe){
239             traceMsg("Couldn't get the current document: ");
240             traceMsg(JameleonUtility.getStack(npe));
241         }
242 
243         return doc;
244     }
245 
246     public boolean highlightActiveElement(){
247         return highlightActiveElement;
248     }
249 
250     /***
251      * Activates the browser that was opened the nth time.
252      * For those that are keeping track of the order of windows 
253      * opened, this window will be moved to the top of the list. 
254      * This method is useful for when there are several windows 
255      * opened and some of the windows share the same title or 
256      * when the desired window doesn't have a title.
257      * @param browserIndex - the index of the browser. The first browser is 0.
258      */
259     public void activateBrowserWithIndex(int browserIndex) {
260         InternetExplorer matchingWindow = session.getBrowserAt(browserIndex);
261         if (matchingWindow != null) {
262             session.removeBrowser(matchingWindow);
263             session.addBrowser(matchingWindow);
264             activateLastNewWindow();
265         }else{
266             throw new RuntimeException("Could not activate window located at the provided index - '"+browserIndex+"'!");
267         }
268     }
269 
270     /***
271      * Activates the browser with the provided title. 
272      * This method is mostly useful for when multiple windows have been spawned and 
273      * the desire window in somewhere in the middle. For those that are keeping track of
274      * the order of windows opened, this window will be moved to the top of the list.
275      * @param title - the title of the desired window to gain focus for.
276      */
277     public void activateBrowserWithTitle(String title) {
278         InternetExplorer matchingWindow = session.getBrowserWithTitle(title);
279         if (matchingWindow != null) {
280             session.removeBrowser(matchingWindow);
281             session.addBrowser(matchingWindow);
282             activateLastNewWindow();
283         }else{
284             throw new RuntimeException("Could not activate window with the provided title - '"+title+"'!");
285         }
286     }
287 
288     /***
289      * If a new window has been opened by a tag and within the same tag you want to access that popup, you've to use
290      * this method to get it. Following tags will automatically get the topmost window without the need to call this
291      * method.
292      */
293     public void activateLastNewWindow() {
294         try{
295             if (ie.getNewWindowCount() > 0) {
296                 // The new window has been added to the list of all open browser windows automatically by the newWindow2
297                 // event handler so we only have to update our IE from the session to get the one of the new popup
298                 ie = session.getCurrentIE();
299                 ie.waitWhileBusy();
300             }
301         }catch(JiffieException je){
302             traceMsg("Couldn't activate new window");
303             traceMsg(JameleonUtility.getStack(je));
304         }
305     }
306 
307     /***
308      * Checks that a checkbox in the workingForm is checked or unchecked.
309      *
310      * @param checkBoxName - The name of the checkbox
311      * @param checked      - Whether the checkbox should be checked or unchecked.
312      */
313     public void assertCheckboxChecked(final String checkBoxName, final boolean checked) {
314         String msg = "assertCheckboxChecked: " + checkBoxName + " was ";
315         if (checked) {
316             msg += "not checked!";
317         } else {
318             msg += "checked!";
319         }
320         int assertLevel = AssertLevel.NO_LEVEL;
321         assertCheckboxChecked(msg, checkBoxName, checked, assertLevel);
322     }
323 
324     /***
325      * Checks that a checkbox in the workingForm is checked or unchecked.
326      *
327      * @param checkBoxName - The name of the checkbox
328      * @param checked      - Whether the checkbox should be checked or unchecked.
329      * @param assertLevel  - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
330      */
331     public void assertCheckboxChecked(final String checkBoxName, final boolean checked, int assertLevel) {
332         String msg = "assertCheckboxChecked: " + checkBoxName + " was ";
333         if (checked) {
334             msg += "not checked!";
335         } else {
336             msg += "checked!";
337         }
338         assertCheckboxChecked(msg, checkBoxName, checked, assertLevel);
339     }
340 
341     /***
342      * Checks that a checkbox in the workingForm is checked or unchecked.
343      * If the test fails display the given <code>message</code>
344      *
345      * @param msg          - The message to display if test fails.
346      * @param checkBoxName - The name of the checkbox
347      * @param checked      - Whether the checkbox should be checked or unchecked.
348      */
349     public void assertCheckboxChecked(final String msg, final String checkBoxName, final boolean checked) {
350         int assertLevel = AssertLevel.NO_LEVEL;
351         assertCheckboxChecked(msg, checkBoxName, checked, assertLevel);
352     }
353 
354     /***
355      * Checks that a checkbox in the workingForm is checked or unchecked.
356      * Checks that a a checkbox in the workingForm is checked or unchecked.
357      * If the test fails display the given <code>message</code>
358      *
359      * @param msg          - The message to display if test fails.
360      * @param checkBoxName - The name of the checkbox
361      * @param checked      - Whether the checkbox should be checked or unchecked.
362      * @param assertLevel  - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
363      */
364     public void assertCheckboxChecked(final String msg, final String checkBoxName, final boolean checked, int assertLevel) {
365         if (checkBoxName == null) {
366             fail("assertCheckBoxChecked: The checkbox field name was null!!", assertLevel);
367         }
368         assertMethodWithLevel(new Runnable() {
369             public void run() {
370                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertCheckBoxChecked: The checkbox field name was null!!"), checkBoxName);
371                 IHTMLInputElement checkbox = getCheckbox(checkBoxName);
372                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), checkbox);
373                 try{
374                     if (checked) {
375                         Assert.assertTrue(JameleonUtility.createErrMsg(msg), checkbox.getChecked());
376                     } else {
377                         Assert.assertFalse(JameleonUtility.createErrMsg(msg), checkbox.getChecked());
378                     }
379                 }finally{
380                     checkbox.release();
381                 }
382 
383             }
384         }, assertLevel);
385     }
386 
387     /***
388      * Checks that a checkbox with a given name and value in the workingForm is checked or unchecked.
389      * If the test fails display the given <code>message</code>
390      *
391      * @param checkBoxName - The name of the checkbox
392      * @param checkBoxValue - The value of the checkbox
393      * @param checked      - Whether the checkbox should be checked or unchecked.
394      */
395     public void assertCheckboxWithNameAndValueChecked(final String checkBoxName, final String checkBoxValue, final boolean checked) {
396         String msg = "assertCheckboxWithNameAndValueChecked: " + checkBoxName + " was ";
397         if (checked) {
398             msg += "not checked!";
399         } else {
400             msg += "checked!";
401         }
402         int assertLevel = AssertLevel.NO_LEVEL;
403         assertCheckboxWithNameAndValueChecked(msg, checkBoxName, checkBoxValue, checked, assertLevel);
404     }
405 
406     /***
407      * Checks that a checkbox with a given name and value in the workingForm is checked or unchecked.
408      * If the test fails display the given <code>message</code>
409      *
410      * @param checkBoxName - The name of the checkbox
411      * @param checkBoxValue - The value of the checkbox
412      * @param checked      - Whether the checkbox should be checked or unchecked.
413      */
414     public void assertCheckboxWithNameAndValueChecked(final String checkBoxName, final String checkBoxValue, final boolean checked, int assertLevel) {
415         String msg = "assertCheckboxWithNameAndValueChecked: " + checkBoxName + " was ";
416         if (checked) {
417             msg += "not checked!";
418         } else {
419             msg += "checked!";
420         }
421         assertCheckboxWithNameAndValueChecked(msg, checkBoxName, checkBoxValue, checked, assertLevel);
422     }
423 
424     /***
425      * Checks that a checkbox with a given name and value in the workingForm is checked or unchecked.
426      * If the test fails display the given <code>message</code>
427      *
428      * @param msg          - The message to display if test fails.
429      * @param checkBoxName - The name of the checkbox
430      * @param checkBoxValue - The value of the checkbox
431      * @param checked      - Whether the checkbox should be checked or unchecked.
432      */
433     public void assertCheckboxWithNameAndValueChecked(final String msg, final String checkBoxName, final String checkBoxValue, final boolean checked) {
434         int assertLevel = AssertLevel.NO_LEVEL;
435         assertCheckboxWithNameAndValueChecked(msg, checkBoxName, checkBoxValue, checked, assertLevel);
436     }
437 
438     /***
439      * Checks that a checkbox with a given name and value in the workingForm is checked or unchecked.
440      * If the test fails display the given <code>message</code>
441      *
442      * @param msg          - The message to display if test fails.
443      * @param checkBoxName - The name of the checkbox
444      * @param checkBoxValue - The value of the checkbox
445      * @param checked      - Whether the checkbox should be checked or unchecked.
446      * @param assertLevel  - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
447      */
448     public void assertCheckboxWithNameAndValueChecked(final String msg, final String checkBoxName, final String checkBoxValue, final boolean checked, int assertLevel) {
449         assertMethodWithLevel(new Runnable() {
450             public void run() {
451                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertCheckboxWithNameAndValueChecked: The checkbox field name was null!!"), checkBoxName);
452                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertCheckboxWithNameAndValueChecked: The checkbox field value was null!!"), checkBoxValue);
453                 IHTMLInputElement checkbox = getCheckboxWithNameAndValue(checkBoxName, checkBoxValue);
454                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), checkbox);
455                 try{
456                     if (checked) {
457                         Assert.assertTrue(JameleonUtility.createErrMsg(msg), checkbox.getChecked());
458                     } else {
459                         Assert.assertFalse(JameleonUtility.createErrMsg(msg), checkbox.getChecked());
460                     }
461                 }finally{
462                     checkbox.release();
463                 }
464 
465             }
466         }, assertLevel);
467     }
468 
469     /***
470      * Checks that a link with given text is present in the current html.
471      * See {@link #getLink(java.lang.String)} for information onw how <code>linkText</code> is used to
472      * find the link.
473      *
474      * @param linkText - The text, name, id or alt text to click
475      */
476     public void assertLinkPresent(final String linkText) {
477         String msg = "assertLinkPresent: '" + linkText + "' not found!";
478         int assertLevel = AssertLevel.NO_LEVEL;
479         assertLinkPresent(msg, linkText, assertLevel);
480     }
481 
482 
483     /***
484      * Checks that a link with given text is present in the current html.
485      * See {@link #getLink(java.lang.String)} for information onw how <code>linkText</code> is used to
486      * find the link.
487      * If the test fails display the given <code>message</code>
488      *
489      * @param msg      - The message to display if <code>text</code> is not in the response.
490      * @param linkText - The text, name, id or alt text to click
491      */
492     public void assertLinkPresent(final String msg, final String linkText) {
493         int assertLevel = AssertLevel.NO_LEVEL;
494         assertLinkPresent(msg, linkText, assertLevel);
495     }
496 
497 
498     /***
499      * Checks that a link with given text is present in the current html.
500      * See {@link #getLink(java.lang.String)} for information onw how <code>linkText</code> is used to
501      * find the link.
502      *
503      * @param linkText    - The text, name, id or alt text to click
504      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
505      */
506     public void assertLinkPresent(final String linkText, int assertLevel) {
507         String msg = "assertLinkPresent: '" + linkText + "' not found!";
508         assertLinkPresent(msg, linkText, assertLevel);
509     }
510 
511     public abstract class TagRunnable implements Runnable {
512         public IHTMLAnchorElement anchor;
513         public IHTMLAnchorElement getAnchor() {
514             return anchor;
515         }
516     };
517 
518     /***
519      * Checks that a link with given text is present in the current html.
520      * See {@link #getLink(java.lang.String)} for information onw how <code>linkText</code> is used to
521      * find the link.
522      * If the test fails display the given <code>message</code>
523      *
524      * @param msg         - The message to display if <code>text</code> is not in the response.
525      * @param linkText    - The text, name, id or alt text to click
526      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
527      */
528     public void assertLinkPresent(final String msg, final String linkText, int assertLevel) {
529         TagRunnable runnable = new TagRunnable() {
530             public void run() {
531                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertLinkPresent: Link Text was null!!"), linkText);
532                 anchor = getLink(linkText);
533                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), anchor);
534                 anchor.release();
535             }
536         };
537         assertMethodWithLevel(runnable, assertLevel);
538     }
539 
540     public IHTMLAnchorElement assertLinkWithHrefPresent(final String href, final String linkText) {
541         String msg = "assertLinkPresentWithHrefPresent: '" + linkText + "' not found!";
542         int assertLevel = AssertLevel.NO_LEVEL;
543         return assertLinkWithHrefPresent(msg, linkText, href, assertLevel);
544     }
545 
546     /***
547      * Checks that a link with given text is present in the current html.
548      * See {@link #getLink(java.lang.String)} for information onw how <code>linkText</code> is used to
549      * find the link.
550      * If the test fails display the given <code>message</code>
551      *
552      * @param msg         - The message to display if <code>text</code> is not in the response.
553      * @param linkText    - The text, name, id or alt text to click
554      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
555      */
556     public IHTMLAnchorElement assertLinkWithHrefPresent(final String msg, final String linkText, final String href, int assertLevel) {
557         TagRunnable runnable = new TagRunnable() {
558                     public void run() {
559                         Assert.assertNotNull(JameleonUtility.createErrMsg("assertLinkPresentWithHrefPresent: Link Text was null!!"), linkText);
560                         anchor = getLinkWithHref(href, linkText);
561                         Assert.assertNotNull(JameleonUtility.createErrMsg(msg), anchor);
562                     }
563         };
564         assertMethodWithLevel(runnable, assertLevel);
565         return runnable.getAnchor();
566     }
567 
568     /***
569      * Checks the value of the password field.
570      *
571      * @param fieldName - The name of the password field.
572      * @param value     - The expected value.
573      */
574     public void assertPasswordFieldValueEquals(final String fieldName, final String value) {
575         String msg = "assertPasswordFieldValueEquals: " + fieldName;
576         int assertLevel = AssertLevel.NO_LEVEL;
577         assertPasswordFieldValueEquals(msg, fieldName, value, assertLevel);
578     }
579 
580     /***
581      * Checks the value of the password field.
582      *
583      * @param fieldName   - The name of the password field.
584      * @param value       - The expected value.
585      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
586      */
587     public void assertPasswordFieldValueEquals(final String fieldName, final String value, int assertLevel) {
588         String msg = "assertPasswordFieldValueEquals: " + fieldName;
589         assertPasswordFieldValueEquals(msg, fieldName, value, assertLevel);
590     }
591 
592     /***
593      * Checks the value of the password field.
594      * If the test fails display the given <code>msg</code>
595      *
596      * @param msg       - The message to display if test fails.
597      * @param fieldName - The name of the password field.
598      * @param value     - The expected value.
599      */
600     public void assertPasswordFieldValueEquals(final String msg, final String fieldName, final String value) {
601         int assertLevel = AssertLevel.NO_LEVEL;
602         assertPasswordFieldValueEquals(msg, fieldName, value, assertLevel);
603     }
604 
605     /***
606      * Checks the value of the password field.
607      * If the test fails display the given <code>msg</code>
608      *
609      * @param msg         - The message to display if test fails.
610      * @param fieldName   - The name of the password field.
611      * @param value       - The expected value.
612      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
613      */
614     public void assertPasswordFieldValueEquals(final String msg, final String fieldName, final String value, int assertLevel) {
615         assertMethodWithLevel(new Runnable() {
616             public void run() {
617                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertPasswordFieldValueEquals: The password field name was null!!"), fieldName);
618                 IHTMLInputElement password = getPasswordField(fieldName);
619                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), password);
620                 try{
621                     Assert.assertEquals(JameleonUtility.createErrMsg(msg), value, password.getValue());
622                 }finally{
623                     password.release();
624                 }
625             }
626         }, assertLevel);
627     }
628 
629     /***
630      * Checks that the given radio button has the provided value selected
631      *
632      * @param fieldName - The name of the radio button.
633      * @param value     - The expected value.
634      */
635     public void assertRadioButtonChecked(final String fieldName, final String value) {
636         String msg = "assertRadioButtonChecked: " + fieldName;
637         int assertLevel = AssertLevel.NO_LEVEL;
638         assertRadioButtonChecked(msg, fieldName, value, assertLevel);
639     }
640 
641     /***
642      * Checks that the given radio button has the provided value selected
643      *
644      * @param fieldName   - The name of the radio button.
645      * @param value       - The expected value.
646      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
647      */
648     public void assertRadioButtonChecked(final String fieldName, final String value, int assertLevel) {
649         String msg = "assertRadioButtonChecked: " + fieldName;
650         assertRadioButtonChecked(msg, fieldName, value, assertLevel);
651     }
652 
653     /***
654      * Checks that the given radio button has the provided value selected
655      * If the test fails display the given <code>msg</code>
656      *
657      * @param msg       - The message to display if test fails.
658      * @param fieldName - The name of the radio button.
659      * @param value     - The expected value.
660      */
661     public void assertRadioButtonChecked(final String msg, final String fieldName, final String value) {
662         int assertLevel = AssertLevel.NO_LEVEL;
663         assertRadioButtonChecked(msg, fieldName, value, assertLevel);
664     }
665 
666     /***
667      * Checks that the given radio button has the provided value selected
668      * If the test fails display the given <code>msg</code>
669      *
670      * @param msg         - The message to display if test fails.
671      * @param fieldName   - The name of the radio button.
672      * @param value       - The expected value.
673      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
674      */
675     public void assertRadioButtonChecked(final String msg, final String fieldName, final String value, int assertLevel) {
676         assertMethodWithLevel(new Runnable() {
677             public void run() {
678                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertPasswordFieldValueEquals: The radio button name was null!!"), fieldName);
679                 IHTMLInputElement radioButton = getRadioButton(fieldName, value);
680                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), radioButton);
681                 try{
682                     Assert.assertTrue(JameleonUtility.createErrMsg(msg), radioButton.getChecked());
683                 }finally{
684                     radioButton.release();
685                 }
686             }
687         }, assertLevel);
688     }
689 
690     /***
691      * Checks that the given select field has the provided index selected
692      *
693      * @param fieldName  - The name of the select field.
694      * @param index     - The expected value.
695      */
696     public void assertSelectFieldOptionIndexEquals(final String fieldName, final int index) {
697         String msg = "assertSelectFieldOptionIndexEquals: " + fieldName;
698         int assertLevel = AssertLevel.NO_LEVEL;
699         assertSelectFieldOptionIndexEquals(msg, fieldName, index, assertLevel);
700     }
701 
702     /***
703      * Checks that the given select field has the provided index selected
704      *
705      * @param fieldName   - The name of the select field.
706      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
707      */
708     public void assertSelectFieldOptionIndexEquals(final String fieldName, final int index, int assertLevel) {
709         String msg = "assertSelectFieldOptionIndexEquals: " + fieldName;
710         assertSelectFieldOptionIndexEquals(msg, fieldName, index, assertLevel);
711     }
712 
713     /***
714      * Checks that the given select field has the provided index selected
715      * If the test fails display the given <code>msg</code>
716      *
717      * @param msg       - The message to display if test fails.
718      * @param fieldName - The name of the select field.
719      */
720     public void assertSelectFieldOptionIndexEquals(final String msg, final String fieldName, final int index) {
721         int assertLevel = AssertLevel.NO_LEVEL;
722         assertSelectFieldOptionIndexEquals(msg, fieldName, index, assertLevel);
723     }
724 
725     /***
726      * Checks that the given select field has the provided index selected
727      * If the test fails display the given <code>msg</code>
728      *
729      * @param msg         - The message to display if test fails.
730      * @param fieldName   - The name of the select field.
731      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
732      */
733     public void assertSelectFieldOptionIndexEquals(final String msg, final String fieldName, final int index, int assertLevel) {
734         assertMethodWithLevel(new Runnable() {
735             public void run() {
736                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertSelectFieldOptionIndexEquals: The select field name was null!!"), fieldName);
737                 IHTMLSelectElement select = getSelectField(fieldName);
738                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), select);
739                 try{
740                     Assert.assertEquals(JameleonUtility.createErrMsg(msg), index, select.getSelectedIndex());
741                 }finally{
742                     select.release();
743                 }
744             }
745         }, assertLevel);
746     }
747 
748     /***
749      * Checks that the given select field has the provided indexes selected
750      *
751      * @param fieldName - The name of the select field.
752      * @param indexes   - The expected values.
753      */
754     public void assertSelectFieldOptionIndexesEqual(final String fieldName, final int[] indexes) {
755         String msg = "assertSelectFieldOptionIndexEquals: " + fieldName;
756         int assertLevel = AssertLevel.NO_LEVEL;
757         assertSelectFieldOptionIndexesEqual(msg, fieldName, indexes, assertLevel);
758     }
759 
760     /***
761      * Checks that the given select field has the provided indexes selected
762      *
763      * @param fieldName   - The name of the select field.
764      * @param indexes     - The expected values.
765      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
766      */
767     public void assertSelectFieldOptionIndexesEqual(final String fieldName, final int[] indexes, int assertLevel) {
768         String msg = "assertSelectFieldOptionIndexesEqual: " + fieldName;
769         assertSelectFieldOptionIndexesEqual(msg, fieldName, indexes, assertLevel);
770     }
771 
772     /***
773      * Checks that the given select field has the provided index selected
774      * If the test fails display the given <code>msg</code>
775      *
776      * @param msg       - The message to display if test fails.
777      * @param fieldName - The name of the select field.
778      * @param indexes   - The expected values.
779      */
780     public void assertSelectFieldOptionIndexesEqual(final String msg, final String fieldName, final int[] indexes) {
781         int assertLevel = AssertLevel.NO_LEVEL;
782         assertSelectFieldOptionIndexesEqual(msg, fieldName, indexes, assertLevel);
783     }
784 
785     /***
786      * Checks that the given select field has the provided index selected
787      * If the test fails display the given <code>msg</code>
788      *
789      * @param msg         - The message to display if test fails.
790      * @param fieldName   - The name of the radio button.
791      * @param indexes     - The expected values.
792      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
793      */
794     public void assertSelectFieldOptionIndexesEqual(final String msg, final String fieldName, final int[] indexes, final int assertLevel) {
795         
796         assertMethodWithLevel(new Runnable() {
797             public void run() {
798                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertSelectFieldOptionIndexesEqual: The select field name was null"), fieldName);
799                 IHTMLSelectElement select = getSelectField(fieldName);
800                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), select);
801                 try{
802                     ElementList options = select.getElementListByTag("option");
803                     IHTMLOptionElement option = null;
804                     try{
805                         for (int i = 0; i < options.size(); i++) {
806                             option = (IHTMLOptionElement) options.get(i);
807                             boolean foundInList = false;
808                             for (int j = 0; !foundInList && j < indexes.length; j++) {
809                                 if (indexes[j] == i) {
810                                     foundInList = true;
811                                 }
812                             }
813                             try{
814                                 if (foundInList) {
815                                     Assert.assertTrue(JameleonUtility.createErrMsg(msg), option.getSelected());
816                                 }else{
817                                     Assert.assertFalse(JameleonUtility.createErrMsg(msg), option.getSelected());
818                                 }
819                             }finally{
820                                 if (option != null) {
821                                     option.release();
822                                 }
823                             }
824                         }
825                     }finally{
826                         if (option != null) {
827                             option.release();
828                         }
829                     }
830                 }catch(JiffieException je){
831                     fail("Could not validate select field '"+fieldName+"' for the following reason: "+je.getMessage());
832                 }
833                 finally{
834                     select.release();
835                 }
836             }
837         }, assertLevel);
838     }
839 
840     /***
841      * Checks that the given select field has the provided displayed text value selected
842      *
843      * @param fieldName - The name of the radio button.
844      * @param textValue     - The expected value.
845      */
846     public void assertSelectFieldOptionTextEquals(final String fieldName, final String textValue) {
847         String msg = "assertSelectFieldOptionTextEquals: " + fieldName;
848         int assertLevel = AssertLevel.NO_LEVEL;
849         assertSelectFieldOptionTextEquals(msg, fieldName, textValue, assertLevel);
850     }
851 
852     /***
853      * Checks that the given select field has the provided displayed text value selected
854      *
855      * @param fieldName   - The name of the radio button.
856      * @param textValue     - The expected value.
857      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
858      */
859     public void assertSelectFieldOptionTextEquals(final String fieldName, final String textValue, int assertLevel) {
860         String msg = "assertSelectFieldOptionTextEquals: " + fieldName;
861         assertSelectFieldOptionTextEquals(msg, fieldName, textValue, assertLevel);
862     }
863 
864     /***
865      * Checks that the given select field has the provided displayed text value selected
866      * If the test fails display the given <code>msg</code>
867      *
868      * @param msg       - The message to display if test fails.
869      * @param fieldName - The name of the radio button.
870      * @param textValue - The expected value.
871      */
872     public void assertSelectFieldOptionTextEquals(final String msg, final String fieldName, final String textValue) {
873         int assertLevel = AssertLevel.NO_LEVEL;
874         assertSelectFieldOptionTextEquals(msg, fieldName, textValue, assertLevel);
875     }
876 
877     /***
878      * Checks that the given select field has the provided displayed text value selected
879      * If the test fails display the given <code>msg</code>
880      *
881      * @param msg         - The message to display if test fails.
882      * @param fieldName   - The name of the radio button.
883      * @param textValue   - The expected value.
884      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
885      */
886     public void assertSelectFieldOptionTextEquals(final String msg, final String fieldName, final String textValue, int assertLevel) {
887         assertMethodWithLevel(new Runnable() {
888             public void run() {
889                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertSelectFieldOptionValueEquals: The select field name was null!!"), fieldName);
890                 IHTMLOptionElement selectedOption = getSelectedOptionField(fieldName);
891                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), selectedOption);
892                 try{
893                     Assert.assertEquals(JameleonUtility.createErrMsg(msg), textValue, selectedOption.getInnerText().trim());
894                 }finally{
895                     selectedOption.release();
896                 }
897             }
898         }, assertLevel);
899     }
900 
901     /***
902      * Checks that the given select field has the provided displayed text values selected
903      *
904      * @param fieldName   - The name of the select field.
905      * @param textValues  - The expected values.
906      */
907     public void assertSelectFieldOptionTextValuesEqual(final String fieldName, final List textValues) {
908         String msg = "assertSelectFieldOptionTextValuesEqual: " + fieldName;
909         int assertLevel = AssertLevel.NO_LEVEL;
910         assertSelectFieldOptionTextValuesEqual(msg, fieldName, textValues, assertLevel);
911     }
912 
913     /***
914      * Checks that the given select field has the provided displayed text values selected
915      *
916      * @param fieldName   - The name of the select field.
917      * @param textValues     - The expected values.
918      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
919      */
920     public void assertSelectFieldOptionTextValuesEqual(final String fieldName, final List textValues, int assertLevel) {
921         String msg = "assertSelectFieldOptionTextValuesEqual: " + fieldName;
922         assertSelectFieldOptionTextValuesEqual(msg, fieldName, textValues, assertLevel);
923     }
924 
925     /***
926      * Checks that the given select field has the provided displayed text values selected
927      * If the test fails display the given <code>msg</code>
928      *
929      * @param msg       - The message to display if test fails.
930      * @param fieldName   - The name of the select field.
931      * @param textValues - The expected values.
932      */
933     public void assertSelectFieldOptionTextValuesEqual(final String msg, final String fieldName, final List textValues) {
934         int assertLevel = AssertLevel.NO_LEVEL;
935         assertSelectFieldOptionTextValuesEqual(msg, fieldName, textValues, assertLevel);
936     }
937 
938     /***
939      * Checks that the given select field has the provided displayed text values selected
940      * If the test fails display the given <code>msg</code>
941      *
942      * @param msg         - The message to display if test fails.
943      * @param fieldName   - The name of the select field.
944      * @param textValues   - The expected values.
945      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
946      */
947     public void assertSelectFieldOptionTextValuesEqual(final String msg, final String fieldName, final List textValues, int assertLevel) {
948         assertMethodWithLevel(new Runnable() {
949             public void run() {
950                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertSelectFieldOptionTextValuesEqual: The select field name was null!!"), fieldName);
951                 IHTMLSelectElement select = null;
952                 ElementList options = null;
953                 try{
954                     select = getSelectField(fieldName);
955                     options = select.getElementListByTag("option");
956                     Iterator it = options.iterator();
957                     IHTMLOptionElement option = null;
958                     String actualText = null;
959                     while (it.hasNext()) {
960                         option = (IHTMLOptionElement) it.next();
961                         actualText = option.getInnerText().trim();
962                         boolean selected = option.getSelected();
963                         if (textValues.contains(actualText)) {
964                             Assert.assertTrue(JameleonUtility.createErrMsg(msg), selected);
965                         }else{
966                             Assert.assertFalse(JameleonUtility.createErrMsg(msg), selected);
967                         }
968                         option.release();
969                     }
970                 }catch(JiffieException je){
971                     fail(JameleonUtility.createErrMsg(msg+ ": "+je.getMessage()));
972                 }finally{
973                     if (select != null) {
974                         select.release();
975                     }
976                     if (options != null) {
977                         options.release();
978                     }
979                 }
980             }
981         }, assertLevel);
982     }
983 
984     /***
985      * Checks that the given select field has the provided value selected
986      *
987      * @param fieldName - The name of the radio button.
988      * @param value     - The expected value.
989      */
990     public void assertSelectFieldOptionValueEquals(final String fieldName, final String value) {
991         String msg = "assertSelectFieldOptionValueEquals: " + fieldName;
992         int assertLevel = AssertLevel.NO_LEVEL;
993         assertSelectFieldOptionValueEquals(msg, fieldName, value, assertLevel);
994     }
995 
996     /***
997      * Checks that the given select field has the provided value selected
998      *
999      * @param fieldName   - The name of the radio button.
1000      * @param value       - The expected value.
1001      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1002      */
1003     public void assertSelectFieldOptionValueEquals(final String fieldName, final String value, int assertLevel) {
1004         String msg = "assertSelectFieldOptionValueEquals: " + fieldName;
1005         assertSelectFieldOptionValueEquals(msg, fieldName, value, assertLevel);
1006     }
1007 
1008     /***
1009      * Checks that the given select field has the provided value selected
1010      * If the test fails display the given <code>msg</code>
1011      *
1012      * @param msg       - The message to display if test fails.
1013      * @param fieldName - The name of the radio button.
1014      * @param value     - The expected value.
1015      */
1016     public void assertSelectFieldOptionValueEquals(final String msg, final String fieldName, final String value) {
1017         int assertLevel = AssertLevel.NO_LEVEL;
1018         assertSelectFieldOptionValueEquals(msg, fieldName, value, assertLevel);
1019     }
1020 
1021     /***
1022      * Checks that the given select field has the provided value selected
1023      * If the test fails display the given <code>msg</code>
1024      *
1025      * @param msg         - The message to display if test fails.
1026      * @param fieldName   - The name of the radio button.
1027      * @param value       - The expected value.
1028      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1029      */
1030     public void assertSelectFieldOptionValueEquals(final String msg, final String fieldName, final String value, int assertLevel) {
1031         assertMethodWithLevel(new Runnable() {
1032             public void run() {
1033                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertSelectFieldOptionValueEquals: The select field name was null!!"), fieldName);
1034                 IHTMLSelectElement select = getSelectField(fieldName);
1035                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), select);
1036                 try{
1037                     Assert.assertEquals(JameleonUtility.createErrMsg(msg), value, select.getValue());
1038                 }finally{
1039                     select.release();
1040                 }
1041             }
1042         }, assertLevel);
1043     }
1044 
1045     /***
1046      * Checks that the given select field has the provided values selected
1047      *
1048      * @param fieldName - The name of the radio button.
1049      * @param values     - The expected values.
1050      */
1051     public void assertSelectFieldOptionValuesEqual(final String fieldName, final List values) {
1052         String msg = "assertSelectFieldOptionValuesEqual: " + fieldName;
1053         int assertLevel = AssertLevel.NO_LEVEL;
1054         assertSelectFieldOptionValuesEqual(msg, fieldName, values, assertLevel);
1055     }
1056 
1057     /***
1058      * Checks that the given select field has the provided values selected
1059      *
1060      * @param fieldName   - The name of the radio button.
1061      * @param values       - The expected values.
1062      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1063      */
1064     public void assertSelectFieldOptionValuesEqual(final String fieldName, final List values, int assertLevel) {
1065         String msg = "assertSelectFieldOptionValuesEqual: " + fieldName;
1066         assertSelectFieldOptionValuesEqual(msg, fieldName, values, assertLevel);
1067     }
1068 
1069     /***
1070      * Checks that the given select field has the provided values selected
1071      * If the test fails display the given <code>msg</code>
1072      *
1073      * @param msg       - The message to display if test fails.
1074      * @param fieldName - The name of the radio button.
1075      * @param values     - The expected values.
1076      */
1077     public void assertSelectFieldOptionValuesEqual(final String msg, final String fieldName, final List values) {
1078         int assertLevel = AssertLevel.NO_LEVEL;
1079         assertSelectFieldOptionValuesEqual(msg, fieldName, values, assertLevel);
1080     }
1081 
1082     /***
1083      * Checks that the given select field has the provided values selected
1084      * If the test fails display the given <code>msg</code>
1085      *
1086      * @param msg         - The message to display if test fails.
1087      * @param fieldName   - The name of the radio button.
1088      * @param values       - The expected values.
1089      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1090      */
1091     public void assertSelectFieldOptionValuesEqual(final String msg, final String fieldName, final List values, int assertLevel) {
1092         assertMethodWithLevel(new Runnable() {
1093             public void run() {
1094                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertSelectFieldOptionValueEquals: The select field name was null!!"), fieldName);
1095                 IHTMLSelectElement select = null;
1096                 ElementList options = null;
1097                 try{
1098                     select = getSelectField(fieldName);
1099                     options = select.getElementListByTag("option");
1100                     Iterator it = options.iterator();
1101                     IHTMLOptionElement option = null;
1102                     String actualValue = null;
1103                     while (it.hasNext()) {
1104                         option = (IHTMLOptionElement) it.next();
1105                         actualValue = option.getValue();
1106                         boolean selected = option.getSelected();
1107                         if (values.contains(actualValue)) {
1108                             Assert.assertTrue(JameleonUtility.createErrMsg(msg), selected);
1109                         }else{
1110                             Assert.assertFalse(JameleonUtility.createErrMsg(msg), selected);
1111                         }
1112                         option.release();
1113                     }
1114                 }catch(JiffieException je){
1115                     fail(JameleonUtility.createErrMsg(msg+ ": "+je.getMessage()));
1116                 }finally{
1117                     if (select != null) {
1118                         select.release();
1119                     }
1120                     if (options != null) {
1121                         options.release();
1122                     }
1123                 }
1124             }
1125         }, assertLevel);
1126     }
1127 
1128     /***
1129      * Checks the value of the text area.
1130      *
1131      * @param fieldName - The name of the text area.
1132      * @param value     - The expected value.
1133      */
1134     public void assertTextAreaValueEquals(final String fieldName, final String value) {
1135         String msg = "assertTextAreaValueEquals: " + fieldName;
1136         int assertLevel = AssertLevel.NO_LEVEL;
1137         assertTextAreaValueEquals(msg, fieldName, value, assertLevel);
1138     }
1139 
1140     /***
1141      * Checks the value of the text area.
1142      *
1143      * @param fieldName   - The name of the text area.
1144      * @param value       - The expected value.
1145      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1146      */
1147     public void assertTextAreaValueEquals(final String fieldName, final String value, int assertLevel) {
1148         String msg = "assertTextAreaValueEquals: " + fieldName;
1149         assertTextAreaValueEquals(msg, fieldName, value, assertLevel);
1150     }
1151 
1152     /***
1153      * Checks the value of the text area.
1154      * If the test fails display the given <code>msg</code>
1155      *
1156      * @param msg       - The message to display if test fails.
1157      * @param fieldName - The name of the text area.
1158      * @param value     - The expected value.
1159      */
1160     public void assertTextAreaValueEquals(final String msg, final String fieldName, final String value) {
1161         int assertLevel = AssertLevel.NO_LEVEL;
1162         assertTextAreaValueEquals(msg, fieldName, value, assertLevel);
1163     }
1164 
1165     /***
1166      * Checks the value of the text area.
1167      * If the test fails display the given <code>msg</code>
1168      *
1169      * @param msg         - The message to display if test fails.
1170      * @param fieldName   - The name of the text area.
1171      * @param value       - The expected value.
1172      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1173      */
1174     public void assertTextAreaValueEquals(final String msg, final String fieldName, final String value, int assertLevel) {
1175         assertMethodWithLevel(new Runnable() {
1176             public void run() {
1177                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertTextAreaValueEquals: The text area name was null!!"), fieldName);
1178                 IHTMLTextAreaElement text = getTextArea(fieldName);
1179                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), text);
1180                 try{
1181                     Assert.assertEquals(JameleonUtility.createErrMsg(msg), value, text.getInnerText());
1182                 }finally{
1183                     text.release();
1184                 }
1185             }
1186         }, assertLevel);
1187     }
1188 
1189     /***
1190      * Checks the value of the text field.
1191      *
1192      * @param fieldName - The name of the text field.
1193      * @param value     - The expected value.
1194      */
1195     public void assertTextFieldValueEquals(final String fieldName, final String value) {
1196         String msg = "assertTextFieldValueEquals: " + fieldName;
1197         int assertLevel = AssertLevel.NO_LEVEL;
1198         assertTextFieldValueEquals(msg, fieldName, value, assertLevel);
1199     }
1200 
1201     /***
1202      * Checks the value of the text field.
1203      *
1204      * @param fieldName   - The name of the text field.
1205      * @param value       - The expected value.
1206      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1207      */
1208     public void assertTextFieldValueEquals(final String fieldName, final String value, int assertLevel) {
1209         String msg = "assertTextFieldValueEquals: " + fieldName;
1210         assertTextFieldValueEquals(msg, fieldName, value, assertLevel);
1211     }
1212 
1213     /***
1214      * Checks the value of the text field.
1215      * If the test fails display the given <code>msg</code>
1216      *
1217      * @param msg       - The message to display if test fails.
1218      * @param fieldName - The name of the text field.
1219      * @param value     - The expected value.
1220      */
1221     public void assertTextFieldValueEquals(final String msg, final String fieldName, final String value) {
1222         int assertLevel = AssertLevel.NO_LEVEL;
1223         assertTextFieldValueEquals(msg, fieldName, value, assertLevel);
1224     }
1225 
1226     /***
1227      * Checks the value of the text field.
1228      * If the test fails display the given <code>msg</code>
1229      *
1230      * @param msg         - The message to display if test fails.
1231      * @param fieldName   - The name of the text field.
1232      * @param value       - The expected value.
1233      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1234      */
1235     public void assertTextFieldValueEquals(final String msg, final String fieldName, final String value, int assertLevel) {
1236         assertMethodWithLevel(new Runnable() {
1237             public void run() {
1238                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertTextFieldValueEquals: The text field name was null!!"), fieldName);
1239                 IHTMLInputElement text = getTextField(fieldName);
1240                 Assert.assertNotNull(JameleonUtility.createErrMsg(msg), text);
1241                 try{
1242                     Assert.assertEquals(JameleonUtility.createErrMsg(msg), value, text.getValue());
1243                 }finally{
1244                     text.release();
1245                 }
1246             }
1247         }, assertLevel);
1248     }
1249 
1250     /***
1251      * Validates that a given XPATH returns at least one result
1252      * @param xpath2evaluate - the XPATH to evaluate
1253      */
1254     public void assertXPath(final String xpath2evaluate) {
1255         assertMethodWithLevel(new Runnable() {
1256             public void run() {
1257                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertXPath: xpath2evaluate was null!!"), xpath2evaluate);
1258                 XPath xpath = null;
1259                 try {
1260                     xpath = new JiffieXPath(xpath2evaluate);
1261                     // get nodes for given xpath
1262                     List results = xpath.selectNodes(getDocument());
1263                     // assert that we found at least one node for the given xpath
1264                     Assert.assertTrue(JameleonUtility.createErrMsg("Expected xpath '" + xpath2evaluate + "' not found!"), results.size() > 0);
1265                     Iterator it = results.iterator();
1266                     Object obj;
1267                     while (it.hasNext()) {
1268                         obj = it.next();
1269                         if (obj instanceof Boolean) {
1270                             Boolean value = (Boolean)obj;
1271                             Assert.assertTrue(JameleonUtility.createErrMsg("Expected xpath '" + xpath2evaluate + "' not found!"), value.booleanValue());
1272                         }
1273                     }
1274                 } catch (JaxenException e) {
1275                     fail("Jaxen was not able to evaluate xpath: '" + xpath2evaluate + "'");
1276                 }
1277             }
1278         }, AssertLevel.NO_LEVEL);
1279     }
1280 
1281     /***
1282      * Validates that a given XPATH returns a provided number of results
1283      * @param xpath2evaluate - the XPATH to evaluate
1284      * @param numOfResults   - the number of expected results
1285      */
1286     public void assertXPathResultsSizeEquals(final String xpath2evaluate, final int numOfResults) {
1287         String msg = "assertXPathNodesSizeEquals: '"+xpath2evaluate+"'";
1288         assertXPathResultsSizeEquals(msg, xpath2evaluate, numOfResults);
1289     }
1290 
1291     /***
1292      * Validates that a given XPATH returns a provided number of results
1293      * @param msg - The message to display when an error occurs.
1294      * @param xpath2evaluate - the XPATH to evaluate
1295      * @param numOfResults   - the number of expected results
1296      */
1297     public void assertXPathResultsSizeEquals(final String msg, final String xpath2evaluate, final int numOfResults) {
1298         assertMethodWithLevel(new Runnable() {
1299             public void run() {
1300                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertXPathResultsSizeEquals: xpath2evaluate was null!!"), xpath2evaluate);
1301                 XPath xpath = null;
1302                 try {
1303                     xpath = new JiffieXPath(xpath2evaluate);
1304                     // get nodes for given xpath
1305                     List results = xpath.selectNodes(getDocument());
1306                     // assert that we found at least one node for the given xpath
1307                     if (results.size() == 1 && numOfResults == 1) {
1308                         Object obj = results.get(0);
1309                         if (obj instanceof Boolean) {
1310                             Boolean bool = (Boolean) obj;
1311                             Assert.assertTrue(msg, bool.booleanValue());
1312                         }
1313                         //No need to check for any other type since we already know only one result was returned
1314                     }else{
1315                         Assert.assertEquals(msg, numOfResults, results.size());
1316                     }
1317                 } catch (JaxenException e) {
1318                     fail("Jaxen was not able to evaluate xpath: '" + xpath2evaluate + "'");
1319                 }
1320             }
1321         }, AssertLevel.NO_LEVEL);
1322     }
1323 
1324     /***
1325      * Asserts that supplied text is present and if <code>regex</code> is set to true,
1326      * then text is a Perl5 style regular expression (evaluated using jakarta ORO package). See
1327      * <a href="http://www.savarese.org/oro/docs/OROMatcher/Syntax.html">
1328      * http://www.savarese.org/oro/docs/OROMatcher/Syntax.html
1329      * </a> for details about the syntax.
1330      *
1331      * @param text  - The text that should be in the response
1332      * @param regex - If set to true, then use <code>text</code> as a regular expression to find
1333      *              a pattern in the HTML.
1334      */
1335     public void assertTextPresent(final String text, final boolean regex) {
1336         if (regex) {
1337             String html = getHTMLSource();
1338             assertRegexMatches("assertTextPresent: regular expression '" + text + "' not found", html, text);
1339         } else {
1340             assertTextPresent(text);
1341         }
1342     }
1343 
1344     /***
1345      * Asserts that supplied text is present.
1346      *
1347      * @param text - The text that should be in the response
1348      */
1349     public void assertTextPresent(final String text) {
1350         String msg = "assertTextPresent: <" + text + "> not found!";
1351         int assertLevel = AssertLevel.NO_LEVEL;
1352         assertTextPresent(msg, text, assertLevel);
1353     }
1354 
1355     /***
1356      * Asserts that supplied text is present.
1357      * If the test fails display the given <code>message</code>
1358      *
1359      * @param msg  - The message to display if <code>text</code> is not in the response.
1360      * @param text - The text that should be in the response
1361      */
1362     public void assertTextPresent(final String msg, final String text) {
1363         int assertLevel = AssertLevel.NO_LEVEL;
1364         assertTextPresent(msg, text, assertLevel);
1365     }
1366 
1367     /***
1368      * Asserts that supplied text is present.
1369      *
1370      * @param text        - The text that should be in the response
1371      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1372      */
1373     public void assertTextPresent(final String text, int assertLevel) {
1374         String msg = "assertTextPresent: <" + text + "> not found!";
1375         assertTextPresent(msg, text, assertLevel);
1376     }
1377 
1378     /***
1379      * Asserts that supplied text is present.
1380      * If the test fails display the given <code>message</code>
1381      *
1382      * @param msg         - The message to display if <code>text</code> is not in the response.
1383      * @param text        - The text that should be in the response
1384      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1385      * todo retry if ComFailException has been caught.
1386      */
1387     public void assertTextPresent(final String msg, final String text, int assertLevel) {
1388         assertMethodWithLevel(new Runnable() {
1389             public void run() {
1390                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertTextPresent: Text was null!!"), text);
1391                 try {
1392                     Assert.assertTrue(JameleonUtility.createErrMsg(msg), elementFinder.isTextInPage(text));
1393                 } catch (ComFailException e) {
1394                     Assert.fail(JameleonUtility.createErrMsg("Communication to Internet Explorer failed. Please re-run test!"));
1395                 }
1396             }
1397         }, assertLevel);
1398     }
1399 
1400     /***
1401      * Asserts that the supplied text is not present in the reponse.
1402      *
1403      * @param text - the text to NOT be found in the response
1404      */
1405     public void assertTextNotPresent(final String text) {
1406         String msg = "assertTextNotPresent: <" + text + "> NOT expected!";
1407         int assertLevel = AssertLevel.NO_LEVEL;
1408         assertTextNotPresent(msg, text, assertLevel);
1409     }
1410 
1411     /***
1412      * Asserts that the supplied text is not present in the reponse.
1413      *
1414      * @param text - the text to NOT be found in the response
1415      * @param msg  - a message that will be displayed if the test fails.
1416      */
1417     public void assertTextNotPresent(final String msg, final String text) {
1418         int assertLevel = AssertLevel.NO_LEVEL;
1419         assertTextNotPresent(msg, text, assertLevel);
1420     }
1421 
1422     /***
1423      * Asserts that the supplied text is not present in the reponse.
1424      *
1425      * @param text        - the text to NOT be found in the response
1426      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1427      */
1428     public void assertTextNotPresent(final String text, int assertLevel) {
1429         String msg = "assertTextNotPresent: <" + text + "> NOT expected!";
1430         assertTextNotPresent(msg, text, assertLevel);
1431     }
1432 
1433     /***
1434      * Asserts that the supplied text is not present in the reponse.
1435      *
1436      * @param text        - the text to NOT be found in the response
1437      * @param msg         - a message that will be displayed if the test fails.
1438      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1439      */
1440     public void assertTextNotPresent(final String msg, final String text, int assertLevel) {
1441         assertMethodWithLevel(new Runnable() {
1442             public void run() {
1443                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertTextNotPresent: Text was null!!"), text);
1444                 boolean success = false;
1445                 int passes = 0;
1446                 while (!success && passes < 5) {
1447                     try {
1448                         Assert.assertFalse(JameleonUtility.createErrMsg(msg), elementFinder.isTextInPage(text));
1449                         success = true;
1450                     } catch (ComFailException e) {
1451                         //Assert.fail(JameleonUtility.createErrMsg("Communication to Internet Explorer failed. Please re-run test!"));
1452                         success = false;
1453                         passes++;
1454                     }
1455                 }
1456             }
1457         }, assertLevel);
1458     }
1459 
1460     /***
1461      * Checks that the title of the current html page matches the expected value, <code>title</code>
1462      * If the test fails display the given <code>message</code>
1463      *
1464      * @param msg         - The message to display if <code>text</code> is not in the response.
1465      * @param title       - Expected title value
1466      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1467      */
1468     public void assertTitleEquals(final String msg, final String title, int assertLevel) {
1469         assertMethodWithLevel(new Runnable() {
1470             public void run() {
1471                 Assert.assertNotNull(JameleonUtility.createErrMsg("assertTitleEquals: Title was null!!"), title);
1472                 Assert.assertTrue(JameleonUtility.createErrMsg(msg), title.equals(getDocument().getTitle()));
1473             }
1474         }, assertLevel);
1475     }
1476 
1477     /***
1478      * Checks that the title of the current html page matches the expected value, <code>title</code>
1479      * Leading and trailing whitespace is not to be included in the compare.
1480      *
1481      * @param title - Expected title value
1482      */
1483     public void assertTitleEquals(final String title) {
1484         assertTitleEquals(title, true);
1485     }
1486 
1487     /***
1488      * Checks that the title of the current html page matches the expected value, <code>title</code>
1489      * Leading and trailing whitespace is not to be included in the compare.
1490      *
1491      * @param title - Expected title value
1492      */
1493     public void assertTitleEquals(final String msg, final String title) {
1494         assertTitleEquals(msg, title, true);
1495     }
1496 
1497     /***
1498      * Checks that the title of the current html page matches the expected value, <code>title</code>
1499      *
1500      * @param title          - Expected title value
1501      * @param trimWhitespace - Set to true if leading and trailing whitespace is not to be included in the compare.
1502      */
1503     public void assertTitleEquals(final String title, boolean trimWhitespace) {
1504         String msg = "assertTitleEquals: title was not <" + title + ">";
1505         int assertLevel = AssertLevel.NO_LEVEL;
1506         assertTitleEquals(msg, title, assertLevel, trimWhitespace);
1507     }
1508 
1509     /***
1510      * Checks that the title of the current html page matches the expected value, <code>title</code>
1511      * If the test fails display the given <code>message</code>
1512      *
1513      * @param msg            - The message to display if <code>text</code> is not in the response.
1514      * @param title          - Expected title value
1515      * @param trimWhitespace - Set to true if leading and trailing whitespace is not to be included in the compare.
1516      */
1517     public void assertTitleEquals(final String msg, final String title, boolean trimWhitespace) {
1518         int assertLevel = AssertLevel.NO_LEVEL;
1519         assertTitleEquals(msg, title, assertLevel, trimWhitespace);
1520     }
1521 
1522     /***
1523      * Checks that the title of the current html page matches the expected value, <code>title</code>
1524      *
1525      * @param title          - Expected title value
1526      * @param assertLevel    - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1527      * @param trimWhitespace - Set to true if leading and trailing whitespace is not to be included in the compare.
1528      */
1529     public void assertTitleEquals(final String title, int assertLevel, boolean trimWhitespace) {
1530         String msg = "assertTitleEquals: was not <" + title + ">";
1531         assertTitleEquals(msg, title, assertLevel, trimWhitespace);
1532     }
1533 
1534     /***
1535      * Checks that the title of the current html page matches the expected value, <code>title</code>
1536      * If the test fails display the given <code>message</code>
1537      *
1538      * @param msg            - The message to display if <code>text</code> is not in the response.
1539      * @param title          - Expected title value
1540      * @param assertLevel    - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1541      * @param trimWhitespace - Set to true if leading and trailing whitespace is not to be included in the compare.
1542      */
1543     public void assertTitleEquals(final String msg, final String title, int assertLevel, boolean trimWhitespace) {
1544         if (trimWhitespace) {
1545             assertMethodWithLevel(new Runnable() {
1546                 public void run() {
1547                     Assert.assertNotNull(JameleonUtility.createErrMsg("assertTitleEquals: Title was null!!"), title);
1548                     IHTMLDocument2 doc = null;
1549                     try{
1550                         doc = getDocument();
1551                         String actualTitle = null;
1552                         if (doc != null) {
1553                             actualTitle = doc.getTitle();
1554                             if (actualTitle != null) {
1555                                 actualTitle = actualTitle.trim();
1556                             }
1557                         }
1558                         Assert.assertEquals(JameleonUtility.createErrMsg(msg), title, actualTitle);
1559                     }finally{
1560                         if (doc != null) {
1561                             doc.release();
1562                         }
1563                     }
1564                 }
1565             }, assertLevel);
1566 
1567         } else {
1568             assertTitleEquals(msg, title, assertLevel);
1569         }
1570     }
1571 
1572     /***
1573      * Checks that the title of the current html page does not matche the expected value, <code>title</code>
1574      *
1575      * @param title - Expected title value
1576      */
1577     public void assertTitleNotEquals(final String title) {
1578         String msg = "assertTitleNotEquals: was <" + title + ">";
1579         int assertLevel = AssertLevel.NO_LEVEL;
1580         assertTitleNotEquals(msg, title, assertLevel);
1581     }
1582 
1583     /***
1584      * Checks that the title of the current html page does not matche the expected value, <code>title</code>
1585      * If the test fails display the given <code>message</code>
1586      *
1587      * @param msg   - The message to display if <code>text</code> is not in the response.
1588      * @param title - Expected title value
1589      */
1590     public void assertTitleNotEquals(final String msg, final String title) {
1591         int assertLevel = AssertLevel.NO_LEVEL;
1592         assertTitleNotEquals(msg, title, assertLevel);
1593     }
1594 
1595     /***
1596      * Checks that the title of the current html page does not matche the expected value, <code>title</code>
1597      *
1598      * @param title       - Expected title value
1599      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1600      */
1601     public void assertTitleNotEquals(final String title, int assertLevel) {
1602         String msg = "assertTitleNotEquals: was '" + title + "'";
1603         assertTitleNotEquals(msg, title, assertLevel);
1604     }
1605 
1606     /***
1607      * Checks that the title of the current html page does not matche the expected value, <code>title</code>
1608      * If the test fails display the given <code>message</code>
1609      *
1610      * @param msg         - The message to display if <code>text</code> is not in the response.
1611      * @param title       - Expected title value
1612      * @param assertLevel - Only run this test under the assertLevel as described in {@link net.sf.jameleon.util.AssertLevel}
1613      */
1614     public void assertTitleNotEquals(final String msg, final String title, int assertLevel) {
1615         assertMethodWithLevel(new Runnable() {
1616             public void run() {
1617                 Assert.assertFalse(JameleonUtility.createErrMsg(msg), getDocument().getTitle().equals(title));
1618             }
1619         }, assertLevel);
1620     }
1621 
1622     /***
1623      * Closes the current Internet Explorer window by sending a quit event to it. The IEEventListener will take care of
1624      * removing it from the list of open browser windows in BrowserCache.
1625      */
1626     public void closeBrowserWindow() {
1627         closeBrowserWindow(1000);
1628     }
1629 
1630     /***
1631      * Closes the current Internet Explorer window by sending a quit event to it. The IEEventListener will take care of
1632      * removing it from the list of open browser windows in BrowserCache.
1633      */
1634     public void closeBrowserWindow(long timeInMillis) {
1635         final long MAX_COUNT = timeInMillis / 100L;
1636         try {
1637             int browserCount = session.getBrowserCache().size();
1638             if (ie == null) {
1639                 ie = session.getCurrentIE();
1640             }
1641             ie.quit();
1642             // wait, till the onQuit event handler has done it's job
1643             int counter = 0;
1644             while (browserCount == session.getBrowserCache().size()) {
1645                 Thread.sleep(100); // 100 ms
1646                 counter++;
1647                 if (counter > MAX_COUNT) {  // 1 s
1648                     throw new InterruptedException("Timeout on waiting for onQuit event.");
1649                 }
1650             }
1651             ie = session.getCurrentIE();
1652         } catch (InterruptedException e) {
1653             throw new RuntimeException(JameleonUtility.createErrMsg("closeBrowserWindow: Waited more than one second for IE to close the window"), e);
1654         } catch (NoSuchElementException e){
1655             throw new RuntimeException(JameleonUtility.createErrMsg("closeBrowserWindow: No current browser window found!"), e);
1656         }
1657     }
1658 
1659     /***
1660      * Clears the currently selected options of the provided select field
1661      * @param selectField - The Select Field to clear all values
1662      */
1663     public void clearSelectFieldValues(IHTMLSelectElement selectField){
1664         assertNotNull("selectField parameter must not be null", selectField);
1665         ElementList options = null;
1666         try{
1667             options = selectField.getElementListByTag("option");
1668             Iterator it = options.iterator();
1669             IHTMLOptionElement option = null;
1670             while (it.hasNext()) {
1671                 try{
1672                     option = (IHTMLOptionElement)it.next();
1673                     option.setSelected(false);
1674                 }finally{
1675                     option.release();
1676                 }
1677             }
1678         }catch(JiffieException je){
1679             throw new RuntimeException(JameleonUtility.createErrMsg("clearSelectFieldValues: Could not clear select field, '"+selectField+"'"), je);
1680         }finally{
1681             if (options != null) {
1682                 options.release();
1683             }
1684         }
1685     }
1686 
1687     /***
1688      * Clicks on an IHTMLElement by using the jiffie provided BlockingClickThread. 
1689      * This method is for use on objects that act like a link, but aren't links. Like
1690      * and <code>&lt;area/&gt;</code> HTML element with an <code>href</code> attribute.
1691      * @param element - The IHTMLElement to click on
1692      */
1693     public void clickIHTMLElement(IHTMLElement element){
1694         assertNotNull(JameleonUtility.createErrMsg("clickIHTMLElement: element was null!"), element);
1695         BlockingClickThread thread = new BlockingClickThread(element);
1696         thread.start();
1697     }
1698 
1699     public void clickLink(final IHTMLAnchorElement anchor, boolean ignoreTarget) {
1700         executeClickLink(anchor, ignoreTarget);
1701     }
1702 
1703     /***
1704      * Finds a link via the {@link #getLink(java.lang.String)} method and clicks on it.
1705      *
1706      * @param link - see {@link #getLink(java.lang.String)} for more information.
1707      */
1708     public void clickLink(final String link) {
1709         executeClickLink(getLink(link), false);
1710     }
1711 
1712     /***
1713      * Finds a link via the {@link #getLinkWithHref(java.lang.String, java.lang.String)} method and clicks on it.
1714      *
1715      * @param link - see {@link #getLink(java.lang.String)} for more information.
1716      */
1717     public void clickLinkWithHref(String href, String link) {
1718         executeClickLink(getLinkWithHref(href, link), false);
1719     }
1720 
1721     /***
1722      * Finds a link via the {@link #getLink(java.lang.String)} method and clicks on it.
1723      *
1724      * @param link         - see {@link #getLink(java.lang.String)} for more information.
1725      * @param ignoreTarget - if set, will not open link in new window (if the link has a target).
1726      */
1727     public void clickLink(final String link, boolean ignoreTarget) {
1728         executeClickLink(getLink(link), ignoreTarget);
1729     }
1730 
1731     /***
1732      * Navigate by selection of a link with given id.
1733      *
1734      * @param linkId - The id attribute defined in the link to click.
1735      */
1736     public void clickLinkWithId(final String linkId) {
1737         if (linkId == null) {
1738             throw new NullPointerException(JameleonUtility.createErrMsg("clickLinkWithId: linkId must not be null!!"));
1739         }
1740 
1741         IHTMLAnchorElement link = null;
1742         try {
1743             link = getLinkWithID(linkId);
1744             if (link != null) {
1745                 link.click(WAIT);
1746             }else{
1747                 throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithId: Could not click on Link with the id " + linkId));
1748             }
1749         } catch (JiffieException e) {
1750             throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithId: Could not click on Link with the id " + linkId), e);
1751         } finally{
1752             if (link != null) {
1753                 link.release();
1754             }
1755         }
1756     }
1757 
1758     /***
1759      * Navigate by selection of a link with a given alt text.
1760      *
1761      * @param altText - The alt text for the image contained by the link
1762      */
1763     public void clickImageLinkWithAltText(final String altText) {
1764         if (altText == null) {
1765             throw new NullPointerException(JameleonUtility.createErrMsg("clickLinkWithImage: altText must not be null!!"));
1766         }
1767         IHTMLAnchorElement link = null;
1768         try {
1769             link = getImageLinkWithAltText(altText);
1770             if (link != null) {
1771                 link.click(WAIT);
1772             }else{
1773                 throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithImage: Could not find link with img alt " + altText));
1774             }
1775         } catch (JiffieException e) {
1776             throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithImage: Could not find link with img alt " + altText), e);
1777         } finally{
1778             if (link != null) {
1779                 link.release();
1780             }
1781         }
1782     }
1783 
1784     /***
1785      * Navigate by selection of a link with a given src.
1786      *
1787      * @param src - The src attribute of an image. This source simply needs to
1788      *            be in the actual image source. For example, if the image
1789      *            source was /images/foo/bar.jpg and the <code>src</code> parameter
1790      *            was set to /foo, then it would click on the first link
1791      *            with that matched. If you want more exact behavior, be sure
1792      *            to pass the full path to the image.
1793      */
1794     public void clickLinkWithImageSrc(final String src) {
1795         if (src == null) {
1796             throw new NullPointerException
1797                     (JameleonUtility.createErrMsg("clickLinkWithImageSrc: src must not be null!!"));
1798         }
1799         IHTMLAnchorElement link = null;
1800         try {
1801             link = getLinkWithImageSrc(src);
1802             if (link != null) {
1803                 link.click(WAIT);
1804             }else{
1805                 throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithImage: Could not find link with image src " + src));
1806             }
1807         } catch (JiffieException e) {
1808             throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithImage: Could not find link with image src " + src), e);
1809         } finally{
1810             if (link != null) {
1811                 link.release();
1812             }
1813         }
1814     }
1815 
1816     /***
1817      * Navigate by selection of a link containing the given text.
1818      *
1819      * @param linkText - the text that shows as a link on the browser.
1820      */
1821     public void clickLinkWithText(final String linkText) {
1822         if (linkText == null) {
1823             throw new NullPointerException(JameleonUtility.createErrMsg("clickLinkWithText: linkText must not be null!!"));
1824         }
1825 
1826         IHTMLAnchorElement link = null;
1827         try {
1828             link = getLinkWith(linkText);
1829             if (link != null) {
1830                 link.click(WAIT);
1831             }else{
1832                 throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithText: Could not click Link with the text " + linkText));
1833             }
1834         } catch (JiffieException e) {
1835             throw new RuntimeException(JameleonUtility.createErrMsg("clickLinkWithText: Could not click Link with the text " + linkText), e);
1836         } finally{
1837             if (link != null) {
1838                 link.release();
1839             }
1840         }
1841 
1842     }
1843 
1844     /***
1845      * Clicks on the submit button in the current working form with the provided name
1846      * @param submitButtonName - the name of the submit button
1847      */
1848     public void clickSubmitButtonWithName(String submitButtonName){
1849         IHTMLInputElement submitButton = getSubmitButtonWithName(submitButtonName);
1850         try{
1851             submitButton.click(WAIT);
1852         }catch (JiffieException je){
1853             fail("Could not submit the working form");
1854         }finally{
1855             if (submitButton != null) {
1856                 submitButton.release();
1857             }
1858         }
1859     }
1860 
1861     /***
1862      * Fires a an event against the provided HTML element
1863      * @param element - The element to fire the event on
1864      * @param eventToFire - The even to fire. Some examples of this might be 'onchange', 'onsubmit', 'onmouseover'
1865      */
1866     public void fireEvent(IHTMLElement element, String eventToFire){
1867         if (eventToFire != null && eventToFire.trim().length() > 0) {
1868             if (element != null) {
1869                 try{
1870                     element.fireEvent(eventToFire, WAIT);
1871                 }catch (JiffieException je){
1872                     traceMsg(JameleonUtility.getStack(je));
1873                 }
1874             }
1875         }
1876     }
1877 
1878     /***
1879      * Gets the area HTML tag with the given alt text
1880      * @param altText - the alt text that the desired area tag should have
1881      * @return A matching area tag
1882      */
1883     public IHTMLElement getAreaElementByAltText(String altText){
1884         return elementFinder.getAreaElementByAltText(altText);
1885     }
1886 
1887     /***
1888      * This method returns the IHTMLDOMNode identified by the given xpath. The IHTMLDOMNode could be either an
1889      * IHTMLElement, an IHTMLDOMAttribute or an IHTMLDOMTextNode.
1890      * @param xpath2evaluate - The xpath identifying the wanted node in the DOM.
1891      * @return Depending on the given xpath either IHTMLElement, IHTMLDOMAttribute or IHTMLDOMTextNode.
1892      */
1893     public IHTMLDOMNode getByXPath(String xpath2evaluate){
1894         return elementFinder.getByXPath(xpath2evaluate);
1895     }
1896 
1897     /***
1898      * Gets the checkbox given by it's field name
1899      *
1900      * @param checkboxFieldName - the name of the checkbox
1901      * @return the checkbox representing the field name.
1902      * @throws RuntimeException if the field does not exist in the form.
1903      */
1904     public IHTMLInputElement getCheckbox(String checkboxFieldName) {
1905         return elementFinder.getCheckbox(checkboxFieldName);
1906     }
1907 
1908     /***
1909      * Gets the checkbox given by it's field name and value
1910      *
1911      * @param name - the name of the checkbox
1912      * @param value - the value of the checkbox
1913      * @return the checkbox representing the field name.
1914      * @throws RuntimeException if the field does not exist in the form.
1915      */
1916     public IHTMLInputElement getCheckboxWithNameAndValue(String name, String value){
1917         return elementFinder.getCheckboxWithNameAndValue(name, value);
1918     }
1919 
1920     /***
1921      * @param xpath2evaluate - The XPath identifying the element
1922      * @return The IHTMLElement identified by the given XPath. Null if the XPath does not identify any element.
1923      */
1924     public IHTMLElement getElementByXPath(String xpath2evaluate) {
1925         return elementFinder.getElementByXPath(xpath2evaluate);
1926     }
1927 
1928     /***
1929      * @param xpath2evaluate - The XPath identifying the element
1930      * @return A list of matching elements.
1931      */
1932     public List getElementsByXPath(String xpath2evaluate) {
1933         return elementFinder.getElementsByXPath(xpath2evaluate);
1934     }
1935 
1936     /***
1937      * Gets a frame by the name attribute
1938      * @param frameName - the name of the frame
1939      * @return the frame represented by the frame name
1940      */
1941     public IHTMLFrameBase2 getFrameWithName(String frameName){
1942         IHTMLFrameBase2 frame = elementFinder.getFrameWithName(frameName);
1943         return frame;
1944     }
1945 
1946     /***
1947      * Gets a frame by the id attribute
1948      * @param frameId - the id of the frame
1949      * @return the frame represented by the frame id
1950      */
1951     public IHTMLFrameBase2 getFrameWithId(String frameId){
1952         return elementFinder.getFrameWithId(frameName);
1953     }
1954 
1955     /***
1956      * Gets a frame by the src attribute
1957      * @param frameSrc - the src of the frame
1958      * @return the frame represented by the frame src
1959      */
1960     public IHTMLFrameBase2 getFrameWithSrc(String frameSrc){
1961         return elementFinder.getFrameWithSrc(frameSrc);
1962     }
1963 
1964     /***
1965      * Tries to get a form via the following methods in order.
1966      * <ol>
1967      * <li><code>getFormWithId()</code> - Gets a form with the expected id attribute
1968      * <li><code>getFormWithName()</code> - Gets a form with the expected name attribute
1969      * <li><code>getFormWithIndex()</code> - The parameter is converted to a number, representing
1970      * the index of the form on the page.
1971      * <li><code>getFormWithXPath</code> - Gets a form with the expected XPath
1972      * </ol>
1973      *
1974      * @param formInfo - The form id or name or index or XPath identifying the form
1975      * @return the first form that corresponds to the above mentioned or <code>null</code> if no <code>Form</code> is found.
1976      */
1977     public IHTMLFormElement getForm(String formInfo) {
1978         return elementFinder.getForm(formInfo);
1979     }
1980 
1981     /***
1982      * Tries to get a form with the name attribute provided
1983      *
1984      * @param name - The name of the form to be returned.
1985      * @return a form with corresponding to the given name.
1986      */
1987     public IHTMLFormElement getFormWithName(String name) {
1988         return elementFinder.getFormWithName(name);
1989     }
1990 
1991     /***
1992      * Tries to get a form with the id attribute provided
1993      *
1994      * @param id - The name of the form to be returned.
1995      * @return a form with corresponding to the given name.
1996      */
1997     public IHTMLFormElement getFormWithId(String id) {
1998         return elementFinder.getFormWithId(id);
1999     }
2000 
2001     /***
2002      * Tries to get the nth form on the page. When a form has no id or name attribute defined,
2003      * this method gets all of the forms on the page and returns the nth form, defined by index
2004      *
2005      * @param index - The number representing the (n-1)th form. The first form would be 0
2006      * @return a form with corresponding to the given name.
2007      */
2008     public IHTMLFormElement getFormWithIndex(int index) {
2009         return elementFinder.getFormWithIndex(index);
2010     }
2011 
2012     public IHTMLFormElement getFormWithXPath(String xpath) {
2013         return elementFinder.getFormWithXPath(xpath);
2014     }
2015 
2016     /***
2017      * Gets the hidden field by the name provided
2018      * @param fieldName - the name of the hidden field
2019      * @return the matching hidden field or null if not found
2020      */
2021     public IHTMLInputElement getHiddenField(String fieldName){
2022         return elementFinder.getHiddenField(fieldName);
2023     }
2024 
2025     /***
2026      * Gets the HTML source from the current page.
2027      * @return the HTML source from the current page.
2028      */
2029     public String getHTMLSource(){
2030         String html = "";
2031         try{
2032             html = getDocument().getBody().getParentElement().getOuterHtml();
2033         }catch(JiffieException je){
2034             throw new RuntimeException("Couldn't get text on current page", je);
2035         }
2036         return html;
2037     }
2038 
2039     /***
2040      * Gets the first matching IHTMLElement with the given html tag, attribute and attribute value
2041      * @param container - The ElementContainer to use to get the attributes out of.
2042      * @param htmlTag - The HTML tag to get back.
2043      * @param attributeName - the attibute in the HTML element
2044      * @param attributeValue - the value of attibute in the HTML element
2045      * @return the first matching IHTMLElement with the given html tag, attribute and attribute value
2046      */
2047     public IHTMLElement getIHTMLElement(ElementContainer container, String htmlTag, String attributeName, String attributeValue){
2048         return elementFinder.getIHTMLElement(container,htmlTag,attributeName,attributeValue);
2049     }
2050 
2051     /***
2052      * Gets the first matching IHTMLElement with the given html tag, attribute and attribute value
2053      * @param htmlTag - The HTML tag to get back.
2054      * @param attributeName - the attibute in the HTML element
2055      * @param attributeValue - the value of attibute in the HTML element
2056      * @return the first matching IHTMLElement with the given html tag, attribute and attribute value
2057      */
2058     public IHTMLElement getIHTMLElement(String htmlTag, String attributeName, String attributeValue){
2059         return elementFinder.getIHTMLElement(htmlTag, attributeName, attributeValue);
2060     }
2061 
2062     /***
2063      * Gets the first matching IHTMLElement with the given html tag, attributes and attribute values
2064      * @param container - The ElementContainer to use to get the attributes out of.
2065      * @param htmlTag - The HTML tag to get back.
2066      * @param attributeNames - a list of attibutes in the HTML element
2067      * @param attributeValues - a list of values of attibutes in the same order as the names
2068      * @return the first matching IHTMLElement with the given html tag, attribute and attribute value
2069      */
2070     public IHTMLElement getIHTMLElement(ElementContainer container, String htmlTag, String[] attributeNames, String[] attributeValues){
2071         return elementFinder.getIHTMLElement(container,htmlTag,attributeNames,attributeValues);
2072     }
2073 
2074     /***
2075      * Gets the first matching IHTMLElement with the given html tag, attributes and attribute values
2076      * @param htmlTag - The HTML tag to get back.
2077      * @param attributeNames - a list of attibutes in the HTML element
2078      * @param attributeValues - a list of values of attibutes in the same order as the names
2079      * @return the first matching IHTMLElement with the given html tag, attribute and attribute value
2080      */
2081     public IHTMLElement getIHTMLElement(String htmlTag, String[] attributeNames, String[] attributeValues){
2082         return elementFinder.getIHTMLElement(htmlTag, attributeNames, attributeValues);
2083     }
2084 
2085     /***
2086      * Gets a List of matching IHTMLElements with the given html tag, attribute and attribute value
2087      * @param container - The ElementContainer to use to get the attributes out of.
2088      * @param htmlTag - The HTML tag to get back.
2089      * @param attributeName - the attibute in the HTML element
2090      * @param attributeValue - the value of attibute in the HTML element
2091      * @return a List of matching IHTMLElements with the given html tag, attribute and attribute value
2092      */
2093     public List getIHTMLElements(ElementContainer container, String htmlTag, String attributeName, String attributeValue){
2094         return elementFinder.getIHTMLElements(container,htmlTag,attributeName,attributeValue);
2095     }
2096 
2097     /***
2098      * Gets a List of matching IHTMLElements with the given html tag, attribute and attribute value
2099      * @param htmlTag - The HTML tag to get back.
2100      * @param attributeName - the attibute in the HTML element
2101      * @param attributeValue - the value of attibute in the HTML element
2102      * @return a List of matching IHTMLElements with the given html tag, attribute and attribute value
2103      */
2104     public List getIHTMLElements(String htmlTag, String attributeName, String attributeValue){
2105         return elementFinder.getIHTMLElements(htmlTag, attributeName, attributeValue);
2106     }
2107 
2108     /***
2109      * Gets a List of matching IHTMLElements with the given html tag, attributes and attribute values
2110      * @param container - The ElementContainer to use to get the attributes out of.
2111      * @param htmlTag - The HTML tag to get back.
2112      * @param attributeNames - a list of attibutes in the HTML element
2113      * @param attributeValues - a list of values of attibutes in the same order as the names
2114      * @return a List of matching IHTMLElements with the given html tag, attribute and attribute value
2115      */
2116     public List getIHTMLElements(ElementContainer container, String htmlTag, String[] attributeNames, String[] attributeValues){
2117         return elementFinder.getIHTMLElements(container,htmlTag,attributeNames,attributeValues);
2118     }
2119 
2120     /***
2121      * Gets a List of matching IHTMLElements with the given html tag, attributes and attribute values
2122      * @param htmlTag - The HTML tag to get back.
2123      * @param attributeNames - a list of attibutes in the HTML element
2124      * @param attributeValues - a list of values of attibutes in the same order as the names
2125      * @return a List of matching IHTMLElements with the given html tag, attribute and attribute value
2126      */
2127     public List getIHTMLElements(String htmlTag, String[] attributeNames, String[] attributeValues){
2128         return elementFinder.getIHTMLElements(htmlTag, attributeNames, attributeValues);
2129     }
2130 
2131 
2132     /***
2133      * Gets an input field by name. This method does not care what type of
2134      * input field it is. Only that it is type="input"
2135      *
2136      * @param inputFieldName - The name of the input field that exists in the current working form
2137      * @return the first element with the provided name.
2138      */
2139     public IHTMLInputElement getInputFieldByName(String inputFieldName){
2140         return elementFinder.getInputFieldByName(inputFieldName);
2141     }
2142 
2143 
2144     /***
2145      * Tries to get a link via the following methods in order.
2146      * <ol>
2147      * <li><code>getLinkWith()</code> - Gets a link with the diplayed text
2148      * <li><code>getLinkWithID()</code> - Gets a link with the <code>id</code> attribute set.
2149      * <li><code>getImageLinkWithAltText</code> - Gets a link with the alt attribute or alt text.
2150      * <li><code>getLinkWithName()</code> - Gets a link with the name attribute set.
2151      * </ol>
2152      *
2153      * @param text - The link text or the link id or the alt text or the link name.
2154      * @return the first link that corresponds to the above mentioned or <code>null</code> if no <code>WebLink</code> is found.
2155      * todo order should be id, name, label, imageText.
2156      */
2157     public IHTMLAnchorElement getLink(String text) {
2158         return elementFinder.getLink(text);
2159     }
2160 
2161     /***
2162      * Helper method to find a link with contained text
2163      *
2164      * @param text - The text contained by the link
2165      * @return The IHTMLAnchorElement for the link
2166      */
2167     public IHTMLAnchorElement getLinkWith(String text) {
2168         return elementFinder.getLinkWith(text);
2169     }
2170 
2171     /***
2172      * Helper method to find a link with the given regex
2173      * contained in the href attribute.
2174      *
2175      * @param text - The text contained by the link
2176      * @return The IHTMLAnchorElement for the link
2177      */
2178     public IHTMLAnchorElement getLinkWithHref(String href, String text) {
2179         return elementFinder.getLinkWithHref(href, text);
2180     }
2181 
2182     /***
2183      * Helper method to find all links with the contained text
2184      *
2185      * @param text - The text contained by the links
2186      * @return The IHTMLAnchorElement for the link
2187      */
2188     public List getLinksWith(String text) {
2189         return elementFinder.getLinksWith(text);
2190     }
2191 
2192     /***
2193      * Helper method to find a link with given id
2194      *
2195      * @param id - The id of the link
2196      * @return The IHTMLAnchorElement for the link
2197      */
2198     public IHTMLAnchorElement getLinkWithID(String id) {
2199         return elementFinder.getLinkWithID(id);
2200     }
2201 
2202     /***
2203      * Helper method to find a link with given img src attribute
2204      *
2205      * @param src - The part of the src attribute of the img contained by the link
2206      * @return The IHTMLAnchorElement for the link
2207      */
2208     public IHTMLAnchorElement getLinkWithImageSrc(String src)  {
2209         return elementFinder.getLinkWithImageSrc(src);
2210     }
2211 
2212     /***
2213      * Helper method to find a link with given img alt text
2214      *
2215      * @param text - The alt text of the img contained by the link
2216      * @return The IHTMLAnchorElement for the link
2217      */
2218     public IHTMLAnchorElement getImageLinkWithAltText(String text) {
2219         return elementFinder.getImageLinkWithAltText(text);
2220     }
2221 
2222     /***
2223      * Helper method to find a link with given name
2224      *
2225      * @param name - The name of the link to find
2226      * @return The IHTMLAnchorElement for the link
2227      */
2228     public IHTMLAnchorElement getLinkWithName(String name) {
2229         return elementFinder.getLinkWithName(name);
2230     }
2231 
2232     /***
2233      * Gets the text field given by it's field name
2234      *
2235      * @param passwordFieldName - the name of the password field
2236      * @return the password field representing the field name.
2237      * @throws RuntimeException if the field does not exist in the form.
2238      */
2239     public IHTMLInputElement getPasswordField(String passwordFieldName) {
2240         return elementFinder.getPasswordField(passwordFieldName);
2241     }
2242 
2243     /***
2244      * Gets the radio button with the specified name and value
2245      *
2246      * @param radioButtonName - the name of the radio button
2247      * @param value           - the value to set the radio button to.
2248      * @return a radio button with the specified name and valud
2249      */
2250     public IHTMLInputElement getRadioButton(String radioButtonName, String value) {
2251         return elementFinder.getRadioButton(radioButtonName, value);
2252     }
2253 
2254     /***
2255      * Gets the select field defined by <code>selectFieldName</code>
2256      *
2257      * @param selectFieldName - the name of the select field
2258      * @return the select field matching the <code>selectFieldName</code>.
2259      */
2260     public IHTMLSelectElement getSelectField(String selectFieldName) {
2261         return elementFinder.getSelectField(selectFieldName);
2262     }
2263 
2264     /***
2265      * Gets the currently selected option from the given select field defined by <code>selectFieldName</code>
2266      *
2267      * @param selectFieldName - the name of the select field
2268      * @return the select option currently selected.
2269      */
2270     public IHTMLOptionElement getSelectedOptionField(String selectFieldName) {
2271         return elementFinder.getSelectedOptionField(selectFieldName);
2272     }
2273 
2274     /***
2275      * Tries to get a submit element in the following order.
2276      * <br/>
2277      * <ol>
2278      * <li>&lt;input type="submit" value="...">
2279      * <li>&lt;input type="image" src="...">
2280      * <li>&lt;input type="button" value="...">
2281      * </ol>
2282      *
2283      * @param name - The identifying name of the submit element to find. It will try to match it with the value attribute
2284      *             in case of input type=submit and type=button. It will try to mathc it with the src attribute in case of
2285      *             input type=image.
2286      * @return The input element.
2287      * todo support find <button>...</button>.
2288      */
2289     public IHTMLInputElement getSubmit(String name) {
2290         return elementFinder.getSubmit(name);
2291     }
2292 
2293 
2294     /***
2295      * Gets the submit button identified by it's value (the label shown in the browser). Supported ways of finding a
2296      * submit are:<br/>
2297      * &lt;input type="submit" value="some value"><br />
2298      * &lt;input type="image" src="jameleon.jpg" alt="alt text"><br />
2299      * &lt;input type="button" value="some value" onclick="some javascript call"><br />
2300      * &lt;button id="button tag" type="submit">button tag&lt;/button><br />
2301      *
2302      * @param type  - type of submit field 'submit', 'image' or 'button'
2303      * @param value - the value of the submit field (this is the label of the submit button shown in the browser)
2304      * @return the input field representing the submit button or null if not found.
2305      * @throws RuntimeException if the field does not exist in the form.
2306      * todo introduce constants for supported types.
2307      */
2308     public IHTMLInputElement getSubmit(String type, String value) {
2309         return elementFinder.getSubmit(type, value);
2310     }
2311 
2312     /***
2313      * Gets the first submit button by it's name from the working form
2314      *
2315      * @param buttonName - the name of the submit button
2316      * @return the submit button with the provided <code>buttonName</code>
2317      * @throws RuntimeException if the desired submit button isn't found in the working form.
2318      */
2319     public IHTMLInputElement getSubmitButtonWithName(String buttonName) {
2320         return elementFinder.getSubmitButtonWithName(buttonName);
2321     }
2322 
2323     /***
2324      * Gets the first submit button by it's name and value from the working form
2325      *
2326      * @param buttonName - the name of the submit button
2327      * @param value - the value attribute of the button
2328      * @return the submit button with the provided <code>buttonName</code> and <code>value</code>.
2329      * @throws RuntimeException if the desired submit button isn't found in the working form.
2330      */
2331     public IHTMLInputElement getSubmitButtonWithNameAndValue(String buttonName, String value) {
2332         return elementFinder.getSubmitButtonWithNameAndValue(buttonName, value);
2333     }
2334 
2335     /***
2336      * Gets the first submit button by it's value from the working form
2337      *
2338      * @param value - the value attribute of the button
2339      * @return the submit button with the provided <code>buttonName</code> and <code>value</code>.
2340      * @throws RuntimeException if the desired submit button isn't found in the working form.
2341      */
2342     public IHTMLInputElement getSubmitButtonWithValue(String value) {
2343         return elementFinder.getSubmitButtonWithValue(value);
2344     }
2345 
2346     /***
2347      * Gets the text area given by it's field name
2348      *
2349      * @param fieldName - the name of the text area
2350      * @return the text area representing the field name.
2351      * @throws RuntimeException if the field does not exist in the form.
2352      */
2353     public IHTMLTextAreaElement getTextArea(String fieldName) {
2354         return elementFinder.getTextArea(fieldName);
2355     }
2356 
2357     /***
2358      * Gets the text field given by it's field name
2359      *
2360      * @param fieldName - the name of the text field
2361      * @return the text field representing the field name.
2362      * @throws RuntimeException if the field does not exist in the form.
2363      */
2364     public IHTMLInputElement getTextField(String fieldName) {
2365         return elementFinder.getTextField(fieldName);
2366     }
2367 
2368     /***
2369      * Gets the current working form used to set form values and submit
2370      *
2371      * @return the current working form used to set form values and submit
2372      */
2373     public IHTMLFormElement getWorkingForm() {
2374         return workingForm;
2375     }
2376 
2377     /***
2378      * Checks to see if the current page has the desired block of text
2379      * @param text - the expected text
2380      * @return True if the expected text is found
2381      */
2382     public boolean isTextInPage(String text){
2383         return elementFinder.isTextInPage(text);
2384     }
2385 
2386     /***
2387      * Navigates directly to the given URL
2388      * todo add handling of basic authentication.
2389      * todo add handling of relative URLs (relative to baseURL of IESession).
2390      *
2391      * @param url      - The fully qualified URL ( e.g. http://sourceforge.net )
2392      * @param username - Username for pages that require basic authentication.
2393      * @param password - Password for pages that require basic authentication.
2394      */
2395     public void navigate(String url, String username, String password) {
2396         try {
2397             ie.navigate(url, WAIT);
2398         } catch (JiffieException e) {
2399             throw new RuntimeException("Could not navigate to url: '" + url + "'");
2400         }
2401 
2402     }
2403 
2404     /***
2405      * Navigates directly to the given URL
2406      *
2407      * @param url      - The fully qualified URL ( e.g. http://www.google.com )
2408      */
2409     public void navigate(String url) {
2410         try {
2411             ie.navigate(url, WAIT);
2412         } catch (JiffieException e) {
2413             throw new RuntimeException("Could not navigate to url: '" + url + "'");
2414         }
2415 
2416     }
2417 
2418     /***
2419      * Sets the checkbox to checked or unchecked.
2420      *
2421      * @param checkboxFieldName - the name of the checkbox
2422      * @param checked           - will check box if set to true, will uncheck box if set to false;
2423      */
2424     public IHTMLInputElement setCheckbox(String checkboxFieldName, boolean checked) {
2425         IHTMLInputElement checkbox = getCheckbox(checkboxFieldName);
2426         if (checkbox != null) {
2427             checkbox.setChecked(checked);
2428         }else{
2429             throw new RuntimeException(checkboxFieldName + " does not exist as a checkbox field in the current form!");
2430         }
2431         return checkbox;
2432     }
2433 
2434     /***
2435      * Sets the checkbox to checked or unchecked given a name and value.
2436      *
2437      * @param checkboxFieldName - the name of the checkbox
2438      * @param checkboxValue - the value of the checkbox
2439      * @param checked           - will check box if set to true, will uncheck box if set to false;
2440      */
2441     public IHTMLInputElement setCheckboxWithNameAndValue(String checkboxFieldName, String checkboxValue, boolean checked) {
2442         if (checkboxFieldName == null) {
2443             throw new IllegalArgumentException("name of checkbox can not be null!");
2444         }
2445         if (checkboxValue == null) {
2446             throw new IllegalArgumentException("value of checkbox can not be null!");
2447         }
2448         IHTMLInputElement checkbox = getCheckboxWithNameAndValue(checkboxFieldName, checkboxValue);
2449         if (checkbox != null) {
2450             checkbox.setChecked(checked);
2451         }else{
2452             throw new RuntimeException(checkboxFieldName + " with value '" + checkboxValue + "' does not exist as a checkbox field in the current form!");
2453         }
2454         return checkbox;
2455     }
2456 
2457     /***
2458      * Sets the given hidden field (input type=hidden named <code>hiddenFieldName</code> to the value desired,
2459      * <code>value</code>
2460      *
2461      * @param hiddenFieldName the name of the hidden field.
2462      * @param value         the value to be set
2463      */
2464     public IHTMLInputElement setHiddenFieldValue(String hiddenFieldName, String value) {
2465         IHTMLInputElement hiddenField = getHiddenField(hiddenFieldName);
2466         if (hiddenField != null) {
2467             hiddenField.setValue(value);
2468         }else{
2469             throw new RuntimeException(hiddenFieldName +" does not exist as a hidden field in the current form!");
2470         }
2471         return hiddenField;
2472     }
2473 
2474     /***
2475      * Sets the index of a select or drop down.
2476      *
2477      * @param selectFieldName - the index of the select field. For example if you wanted to select the 3rd option,
2478      *                        then you would pass it 2.
2479      * @param index           - the index to set the select field to.
2480      */
2481     public IHTMLSelectElement setSelectFieldOptionIndex(String selectFieldName, int index) {
2482         IHTMLSelectElement select = getSelectField(selectFieldName);
2483         if (select != null) {
2484             select.setSelectedIndex(index);
2485         }else{
2486             throw new RuntimeException(selectFieldName +" does not exist as a select field in the current form!");
2487         }
2488         return select;
2489     }
2490 
2491     /***
2492      * Sets the indexes of a select or drop down.
2493      *
2494      * @param selectFieldName - the index of the select field. For example if you wanted to select the 3rd option,
2495      *                        then you would pass it 2.
2496      * @param indexes         - An array of indexes of which options to select.
2497      */
2498     public IHTMLSelectElement setSelectFieldOptionIndexes(String selectFieldName, int[] indexes) {
2499         IHTMLSelectElement select = getSelectField(selectFieldName);
2500         assertNotNull(selectFieldName +" does not exist as a select field in the current form/page!");
2501         clearSelectFieldValues(select);
2502         ElementList options = null;
2503         try{
2504             options = select.getElementListByTag("option");
2505             IHTMLOptionElement option = null;
2506 
2507             for (int i = 0; i < indexes.length; i++) {
2508                 option = (IHTMLOptionElement)options.get(indexes[i]);
2509                 option.setSelected(true);
2510                 option.release();
2511             }
2512         }catch(JiffieException je){
2513             throw new RuntimeException("setSelectFieldOptionIndexes: Could not set field values for '"+selectFieldName+"'", je);
2514         }finally{
2515             if (options != null) {
2516                 options.release();
2517             }
2518         }
2519         return select;
2520     }
2521 
2522     /***
2523      * Sets the value of a select or drop down to the value with the displayed text.
2524      *
2525      * @param selectFieldName - the name of the select field
2526      * @param displayedText   - the displayed text in the drop-down
2527      */
2528     public IHTMLSelectElement setSelectFieldOptionText(String selectFieldName, String displayedText) {
2529         IHTMLSelectElement select = getSelectField(selectFieldName);
2530         IHTMLOptionElement optionWithText = elementFinder.getSelectOptionWithText(selectFieldName,displayedText);
2531         if (optionWithText != null) {
2532             if (select != null) {
2533                 select.setValue(optionWithText.getValue());
2534             }else{
2535                 throw new RuntimeException(selectFieldName +" does not exist as a select field in the current form!");
2536             }
2537         }
2538         return select;
2539     }
2540 
2541     /***
2542      * Sets the values of a select or drop down to the values with the displayed text.
2543      *
2544      * @param selectFieldName       - the name of the select field
2545      * @param displayedTextValues   - A list of the displayed text in the drop-down
2546      */
2547     public IHTMLSelectElement setSelectFieldOptionTextValues(String selectFieldName, List displayedTextValues) {
2548         IHTMLSelectElement select = getSelectField(selectFieldName);
2549         assertNotNull("setSelectFieldOptionTextValues: no select field with the name '"+selectFieldName+"' found", select);
2550         clearSelectFieldValues(select);
2551         Iterator it = displayedTextValues.iterator();
2552         String text = null;
2553         IHTMLOptionElement optionWithText = null;
2554         while (it.hasNext()) {
2555             text = (String) it.next();
2556             optionWithText = elementFinder.getSelectOptionWithText(selectFieldName, text);
2557             assertNotNull("Couldn't find select option with '"+text+"'", optionWithText);
2558             optionWithText.setSelected(true);
2559             optionWithText.release();
2560         }
2561         return select;
2562     }
2563 
2564     /***
2565      * Sets the value of a select or drop down.
2566      *
2567      * @param selectFieldName - the name of the select field
2568      * @param value           - the value to set the select field to.
2569      */
2570     public IHTMLSelectElement setSelectFieldOptionValue(String selectFieldName, String value) {
2571         IHTMLSelectElement select = getSelectField(selectFieldName);
2572         if (select != null) {
2573             select.setValue(value);
2574         }else{
2575             throw new RuntimeException(selectFieldName +" does not exist as a select field in the current form!");
2576         }
2577         return select;
2578     }
2579 
2580     /***
2581      * Sets the values of a select or drop down.
2582      *
2583      * @param selectFieldName - the name of the select field
2584      * @param values           - the values to set the select field to.
2585      */
2586     public IHTMLSelectElement setSelectFieldOptionValues(String selectFieldName, List values) {
2587         IHTMLSelectElement select = getSelectField(selectFieldName);
2588         assertNotNull("setSelectFieldOptionValues: not select field with the name '"+selectFieldName+"' found", select);
2589         clearSelectFieldValues(select);
2590         ElementList options = null;
2591         try{
2592             options = select.getElementListByTag("option");
2593             Iterator it = options.iterator();
2594             String value = null;
2595             IHTMLOptionElement optionWithValue = null;
2596             while (it.hasNext()) {
2597                 optionWithValue = (IHTMLOptionElement) it.next();
2598                 value = optionWithValue.getValue();
2599                 if (values.contains(value)) {
2600                     optionWithValue.setSelected(true);
2601                 }
2602                 optionWithValue.release();
2603             }
2604         }catch(JiffieException je){
2605             throw new RuntimeException(selectFieldName +" does not exist as a select field in the current form!");
2606         }finally{
2607             if (options != null) {
2608                 options.release();
2609             }
2610         }
2611         return select;
2612     }
2613 
2614     /***
2615      * Sets the given password field, <code>passwordFieldName</code> to the value desired, <code>value</code>
2616      *
2617      * @param passwordFieldName - the name of the field value.
2618      * @param value             - the value to be set
2619      */
2620     public IHTMLInputElement setPasswordFieldValue(String passwordFieldName, String value) {
2621         IHTMLInputElement passwordField = getPasswordField(passwordFieldName);
2622 
2623         if (passwordField != null) {
2624             passwordField.setValue(value);
2625         }else{
2626             throw new RuntimeException(passwordFieldName +" does not exist as a password field in the current form!");
2627         }
2628         return passwordField;
2629     }
2630 
2631     /***
2632      * Sets the value of a radio button
2633      *
2634      * @param radioButtonName - the name of the radio button
2635      * @param value           - the value to set the radio button to.
2636      */
2637     public IHTMLInputElement setRadioButtonValue(String radioButtonName, String value) {
2638         IHTMLInputElement radioButton = getRadioButton(radioButtonName, value);
2639         if (radioButton == null) {
2640             throw new RuntimeException(radioButtonName +" does not exist as a radio button in the current form!");
2641         }
2642         if (value != null && value.equals(radioButton.getValue()) ) {
2643             radioButton.setChecked(true);
2644         }
2645         return radioButton;
2646     }
2647 
2648     /***
2649      * Sets the given text area named <code>textFieldName</code> to the value desired,
2650      * <code>value</code>
2651      *
2652      * @param textAreaName the name of the input field.
2653      * @param value        the value to be set
2654      */
2655     public IHTMLTextAreaElement setTextAreaValue(String textAreaName, String value) {
2656         IHTMLTextAreaElement textArea = getTextArea(textAreaName);
2657         if (textArea != null) {
2658             textArea.setValue(value);
2659         }else{
2660             throw new RuntimeException(textAreaName +" does not exist as a textarea field in the current form!");
2661         }
2662         return textArea;
2663     }
2664 
2665     /***
2666      * Sets the given text field (input type=text named <code>textFieldName</code> to the value desired,
2667      * <code>value</code>
2668      * This method follows the maxlength HTML attribute, by truncating the value to the maxlength
2669      * before setting the value.
2670      *
2671      * @param textFieldName the name of the input field.
2672      * @param value         the value to be set
2673      */
2674     public IHTMLInputElement setTextFieldValue(String textFieldName, String value) {
2675         IHTMLInputElement textField = getTextField(textFieldName);
2676         if (textField != null) {
2677             String valueToSet = new String(value);
2678             int maxLength = textField.getMaxLength();
2679             if (maxLength > 0 && value.length() > maxLength) {
2680                 valueToSet = value.substring(0, maxLength);
2681             }
2682             textField.setValue(valueToSet);
2683         }else{
2684             throw new RuntimeException(textFieldName +" does not exist as a text field in the current form!");
2685         }
2686         return textField;
2687     }
2688 
2689     /***
2690      * Sets the given text field (input type=text named <code>textFieldName</code> to the value desired,
2691      * <code>value</code>
2692      * This method follows the maxlength HTML attribute, by truncating the value to the maxlength
2693      * before setting the value.
2694      *
2695      * @param textFieldName     the name of the input field.
2696      * @param value             the value to be set
2697      * @param enforceMaxLength  Set to false to not truncate the value to the maxlength of the text field
2698      */
2699     public IHTMLInputElement setTextFieldValue(String textFieldName, String value, boolean enforceMaxLength) {
2700         IHTMLInputElement textField = null;
2701         if (enforceMaxLength) {
2702             textField = setTextFieldValue(textFieldName, value);
2703         }else if (!enforceMaxLength) {
2704             textField = getTextField(textFieldName);
2705             if (textFieldName != null) {
2706                 textField.setValue(value);
2707             }else{
2708                 throw new RuntimeException(textFieldName +" does not exist as a text field in the current form!");
2709             }
2710         }
2711         return textField;
2712     }
2713 
2714     /***
2715      * Sets the working form by the id of the form
2716      *
2717      * @param id = the id of the form (id attribute in the form element)
2718      */
2719     public void setWorkingFormById(String id) {
2720         if (id != null) {
2721             workingForm = getFormWithId(id);
2722         }
2723     }
2724 
2725     /***
2726      * Sets the working form by the order it is in the actual HTML. This should be used
2727      * when the form has no name or id attributes set. The first form on the page is 0.
2728      * For example, if the form desired is the 5th form on the page, then you would pass it 4.
2729      *
2730      * @param index = the index of the form.
2731      */
2732     public void setWorkingFormByIndex(int index) {
2733         workingForm = getFormWithIndex(index);
2734     }
2735 
2736     /***
2737      * Sets the working form by the name of the form
2738      *
2739      * @param name = the name of the form (name attribute in the form element)
2740      */
2741     public void setWorkingFormByName(String name) {
2742         if (name != null) {
2743             workingForm = getFormWithName(name);
2744         }
2745     }
2746 
2747     /***
2748      * Sets the working form, using the following methods in order.
2749      * <ol>
2750      * <li>{@link #setWorkingFormById(java.lang.String)}</li>
2751      * <li>{@link #setWorkingFormByName(java.lang.String)}</li>
2752      * <li>{@link #setWorkingFormByIndex(int)}</li>
2753      * </ol>
2754      *
2755      * @param formIdNameOrIndex = the id, name or index of the form
2756      */
2757     public void setWorkingForm(String formIdNameOrIndex) {
2758         if (formIdNameOrIndex != null) {
2759             workingForm = getForm(formIdNameOrIndex);
2760         }
2761     }
2762 
2763     /***
2764      * Sets the working form to the provided IHTMLFormElement
2765      *
2766      * @param form The IHTMLFormElement to set the working for to
2767      */
2768     public void setWorkingForm(IHTMLFormElement form) {
2769         workingForm = form;
2770     }
2771 
2772     /***
2773      * Submits the current working form
2774      */
2775     public void submitWorkingForm() {
2776         if (workingForm != null) {
2777             try {
2778                 workingForm.submit(WAIT);
2779             } catch (JiffieException je) {
2780                 throw new RuntimeException("couldn't submit form", je);
2781             }
2782         }else{
2783             throw new RuntimeException("No working form to submit!");
2784         }
2785     }
2786 
2787     public void pluginTearDown() {
2788         ElementFactory elementFactory = JiffieUtility.getElementFactory();
2789         TrackingElementFactory factory;
2790         if (elementFactory instanceof TrackingElementFactory) {
2791             factory = (TrackingElementFactory)elementFactory;
2792             JiffieUtility.setElementFactory(originalFactory);
2793             factory.flushReleasedAndCount();
2794             factory.release();
2795         }
2796         if (workingForm != null) {
2797             workingForm.release();
2798             workingForm = null;
2799         }
2800         ie = null;
2801         elementFinder = null;
2802     }
2803 
2804     //PRIVATE METHODS
2805     /***
2806      * Helper method to execute the click on a given IHTMLAnchorElement found by one of the getLink... methods
2807      *
2808      * @param anchor       - The link to click
2809      * @param ignoreTarget - if set, will not open link in new window (if the link has a target).
2810      */
2811     private void executeClickLink(final IHTMLAnchorElement anchor, boolean ignoreTarget) {
2812         if (anchor == null) {
2813             throw new NullPointerException(JameleonUtility.createErrMsg("clickLink: cannot click on a null link!!"));
2814         }
2815         try {
2816             if (ignoreTarget && anchor.getStringProperty("target") != null && anchor.getStringProperty("target").trim().length() > 0) {
2817                 ie.navigate(anchor.getHref(), WAIT);
2818             } else {
2819                 anchor.click(WAIT);
2820             }
2821         } catch (NullPointerException npe) {
2822             throw new RuntimeException(JameleonUtility.createErrMsg("clickLink: Could not click on Link."), npe);
2823         } catch (JiffieException e) {
2824             throw new RuntimeException(JameleonUtility.createErrMsg("clickLink: Could not click on Link."), e);
2825         } finally{
2826             anchor.release();
2827         }
2828     }
2829 
2830 }