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);