001: package org.ddsteps.web;
002:
003: import java.io.File;
004:
005: import net.sourceforge.jwebunit.ExpectedTable;
006:
007: import org.ddsteps.web.jwebunit.JWebUnitWebBrowser;
008:
009: /**
010: * Interface for all toolkits that implement a stateful web browser.
011: * <p>
012: * This interface keeps the WebBrowser implementation and the teststeps that
013: * delegate to them in sync.
014: * <p>
015: * In 1.1 there is only (@link {@link JWebUnitWebBrowser} but soon we'll be
016: * adding Selenium too.
017: *
018: * @author adamskogman
019: */
020: public interface WebBrowser {
021:
022: /**
023: * Assert that a button is present and disabled.
024: *
025: * @param buttonId
026: */
027: public void assertButtonDisabled(String buttonId);
028:
029: /**
030: * Assert that a button is present and enabled.
031: *
032: * @param buttonId
033: */
034: public void assertButtonEnabled(String buttonId);
035:
036: /**
037: * Assert that a button with a given id is not present.
038: *
039: * @param buttonId
040: */
041: public abstract void assertButtonNotPresent(String buttonId);
042:
043: /**
044: * Assert that a button with a given id is present.
045: *
046: * @param buttonId
047: */
048: public abstract void assertButtonPresent(String buttonId);
049:
050: /**
051: * Assert that a specific checkbox is not selected.
052: *
053: * @param checkBoxName
054: */
055: public abstract void assertCheckboxNotSelected(String checkBoxName);
056:
057: /**
058: * Assert that a specific checkbox is selected.
059: *
060: * @param checkBoxName
061: */
062: public abstract void assertCheckboxSelected(String checkBoxName);
063:
064: /**
065: * Checks to see if a cookie is present in the response. Contributed by
066: * Vivek Venugopalan.
067: *
068: * @param cookieName
069: * The cookie name
070: */
071: public abstract void assertCookiePresent(String cookieName);
072:
073: /**
074: * Assert the value of a cookie.
075: *
076: * @param cookieName
077: * @param expectedValue
078: */
079: public abstract void assertCookieValueEquals(String cookieName,
080: String expectedValue);
081:
082: /**
083: * Assert that an element with a given id is not present.
084: *
085: * @param anID
086: * element id to test for.
087: */
088: public abstract void assertElementNotPresent(String anID);
089:
090: /**
091: * Assert that an element with a given id is present.
092: *
093: * @param anID
094: * element id to test for.
095: */
096: public abstract void assertElementPresent(String anID);
097:
098: /**
099: * Assert that a form element had no value / is empty.
100: *
101: * @param formElementName
102: */
103: public abstract void assertFormElementEmpty(String formElementName);
104:
105: /**
106: * Assert that a specific form element has an expected value.
107: *
108: * @param formElementName
109: * @param expectedValue
110: */
111: public abstract void assertFormElementEquals(
112: String formElementName, String expectedValue);
113:
114: /**
115: * Assert that a form input element with a given name is not present.
116: *
117: * @param formElementName
118: */
119: public abstract void assertFormElementNotPresent(
120: String formElementName);
121:
122: /**
123: * Assert that a form element is not present or disabled.
124: *
125: * @param formElementName
126: * name of the form element
127: */
128: public void assertFormElementNotPresentOrDisabled(
129: String formElementName);
130:
131: /**
132: * Assert that a form input element with a given label is not present.
133: *
134: * @param formElementLabel
135: * label preceding form element.
136: * @see #setFormElementWithLabel(String,String)
137: */
138: public abstract void assertFormElementNotPresentWithLabel(
139: String formElementLabel);
140:
141: /**
142: * Assert that a form input element with a given name is present.
143: *
144: * @param formElementName
145: */
146: public abstract void assertFormElementPresent(String formElementName);
147:
148: /**
149: * Assert that a form element is present and enabled.
150: *
151: * @param formElementName
152: * name of the form element
153: */
154: public void assertFormElementPresentAndEnabled(
155: String formElementName);
156:
157: /**
158: * Assert that a form input element with a given label is present.
159: *
160: * @param formElementLabel
161: * label preceding form element.
162: * @see #setFormElementWithLabel(String,String)
163: */
164: public abstract void assertFormElementPresentWithLabel(
165: String formElementLabel);
166:
167: /**
168: * Assert that there is not a form present.
169: *
170: */
171: public abstract void assertFormNotPresent();
172:
173: /**
174: * Assert that there is not a form with the specified name or id present.
175: *
176: * @param nameOrID
177: */
178: public abstract void assertFormNotPresent(String nameOrID);
179:
180: /**
181: * Assert that there is a form present.
182: *
183: */
184: public abstract void assertFormPresent();
185:
186: /**
187: * Assert that there is a form with the specified name or id present.
188: *
189: * @param nameOrID
190: */
191: public abstract void assertFormPresent(String nameOrID);
192:
193: /**
194: * Assert that a frame with the given name is present.
195: *
196: * @param frameName
197: */
198: public abstract void assertFramePresent(String frameName);
199:
200: /**
201: * Assert that the value of a given web resource is present in a specific
202: * table.
203: *
204: * @param tableSummaryOrId
205: * summary or id attribute value of table
206: * @param key
207: * web resource name
208: */
209: public abstract void assertKeyInTable(String tableSummaryOrId,
210: String key);
211:
212: /**
213: * Assert that the value of a given web resource is not present in a
214: * specific table.
215: *
216: * @param tableSummaryOrId
217: * summary or id attribute value of table
218: * @param key
219: * web resource name
220: */
221: public abstract void assertKeyNotInTable(String tableSummaryOrId,
222: String key);
223:
224: /**
225: * Assert that a web resource's value is not present.
226: *
227: * @param key
228: * web resource name
229: */
230: public abstract void assertKeyNotPresent(String key);
231:
232: /**
233: * Assert that a web resource's value is present.
234: *
235: * @param key
236: * web resource name
237: */
238: public abstract void assertKeyPresent(String key);
239:
240: /**
241: * Assert that the values of a set of web resources are all present in a
242: * specific table.
243: *
244: * @param tableSummaryOrId
245: * summary or id attribute value of table
246: * @param keys
247: * Array of web resource names.
248: */
249: public abstract void assertKeysInTable(String tableSummaryOrId,
250: String[] keys);
251:
252: /**
253: * Assert that no link with the given id is present in the response.
254: *
255: * @param linkId
256: */
257: public abstract void assertLinkNotPresent(String linkId);
258:
259: /**
260: * Assert that a link containing a specified image is not present.
261: *
262: * @param imageFileName
263: * A suffix of the image's filename; for example, to match
264: * <tt>"images/my_icon.png"</tt>, you could just pass in
265: * <tt>"my_icon.png"</tt>.
266: */
267: public abstract void assertLinkNotPresentWithImage(
268: String imageFileName);
269:
270: /**
271: * Assert that no link containing the supplied text is present.
272: *
273: * @param linkText
274: */
275: public abstract void assertLinkNotPresentWithText(String linkText);
276:
277: /**
278: * Assert that no link containing the supplied text is present.
279: *
280: * @param linkText
281: * @param index
282: * The 0-based index, when more than one link with the same text
283: * is expected.
284: */
285: public abstract void assertLinkNotPresentWithText(String linkText,
286: int index);
287:
288: /**
289: * Assert that a link with a given id is present in the response.
290: *
291: * @param linkId
292: */
293: public abstract void assertLinkPresent(String linkId);
294:
295: /**
296: * Assert that a link containing a specified image is present.
297: *
298: * @param imageFileName
299: * A suffix of the image's filename; for example, to match
300: * <tt>"images/my_icon.png"</tt>, you could just pass in
301: * <tt>"my_icon.png"</tt>.
302: */
303: public abstract void assertLinkPresentWithImage(String imageFileName);
304:
305: /**
306: * Assert that a link containing the supplied text is present.
307: *
308: * @param linkText
309: */
310: public abstract void assertLinkPresentWithText(String linkText);
311:
312: /**
313: * Assert that a link containing the supplied text is present.
314: *
315: * @param linkText
316: * @param index
317: * The 0-based index, when more than one link with the same text
318: * is expected.
319: */
320: public abstract void assertLinkPresentWithText(String linkText,
321: int index);
322:
323: /**
324: * Assert that the currently selected display value of a select box matches
325: * a given value.
326: *
327: * @param selectName
328: * name of the select element.
329: * @param option
330: * expected display value of the selected option.
331: */
332: public abstract void assertOptionEquals(String selectName,
333: String option);
334:
335: /**
336: * @param selectId
337: * The select tag.
338: * @param selectedValue
339: * The VALUE that should be selected.
340: */
341: public void assertOptionIsSelectedByValue(String selectId,
342: String selectedValue);
343:
344: /**
345: * Assert that the display values of a select element's options match a
346: * given array of strings.
347: *
348: * @param selectName
349: * name of the select element.
350: * @param expectedOptions
351: * expected display values for the select box, may be null.
352: */
353: public abstract void assertOptionsEqual(String selectName,
354: String[] expectedOptions);
355:
356: /**
357: * Assert that the display values of a select element's options do not match
358: * a given array of strings.
359: *
360: * @param selectName
361: * name of the select element.
362: * @param expectedOptions
363: * expected display values for the select box.
364: */
365: public abstract void assertOptionsNotEqual(String selectName,
366: String[] expectedOptions);
367:
368: /**
369: * @param selectId
370: * @param value
371: */
372: public void assertOptionValuePresent(String selectId, String value);
373:
374: /**
375: * Assert that the values of a select element's options match a given array
376: * of strings.
377: *
378: * @param selectName
379: * name of the select element.
380: * @param expectedValues
381: * expected values for the select box.
382: */
383: public abstract void assertOptionValuesEqual(String selectName,
384: String[] expectedValues);
385:
386: /**
387: * Assert that the values of a select element's options do not match a given
388: * array of strings.
389: *
390: * @param selectName
391: * name of the select element.
392: * @param optionValues
393: * expected values for the select box.
394: */
395: public abstract void assertOptionValuesNotEqual(String selectName,
396: String[] optionValues);
397:
398: /**
399: * Assert that a specific option is not present in a radio group.
400: *
401: * @param name
402: * radio group name.
403: * @param radioOption
404: * option to test for.
405: */
406: public abstract void assertRadioOptionNotPresent(String name,
407: String radioOption);
408:
409: /**
410: * Assert that a specific option is not selected in a radio group.
411: *
412: * @param name
413: * radio group name.
414: * @param radioOption
415: * option to test for selection.
416: */
417: public abstract void assertRadioOptionNotSelected(String name,
418: String radioOption);
419:
420: /**
421: * Assert that a specific option is present in a radio group.
422: *
423: * @param name
424: * radio group name.
425: * @param radioOption
426: * option to test for.
427: */
428: public abstract void assertRadioOptionPresent(String name,
429: String radioOption);
430:
431: /**
432: * Assert that a specific option is selected in a radio group.
433: *
434: * @param name
435: * radio group name.
436: * @param radioOption
437: * option to test for selection.
438: */
439: public abstract void assertRadioOptionSelected(String name,
440: String radioOption);
441:
442: /**
443: * Assert that a submit button with a given name is not present.
444: *
445: * @param buttonName
446: */
447: public abstract void assertSubmitButtonNotPresent(String buttonName);
448:
449: /**
450: * Assert that a submit button with a given name is present.
451: *
452: * @param buttonName
453: */
454: public abstract void assertSubmitButtonPresent(String buttonName);
455:
456: /**
457: * Assert that a submit button with a given name and value is present.
458: *
459: * @param buttonName
460: * @param expectedValue
461: */
462: public abstract void assertSubmitButtonValue(String buttonName,
463: String expectedValue);
464:
465: /**
466: * Assert that a specific table matches an ExpectedTable.
467: *
468: * @param tableSummaryOrId
469: * summary or id attribute value of table
470: * @param expectedTable
471: * represents expected values (colspan supported).
472: */
473: public abstract void assertTableEquals(String tableSummaryOrId,
474: ExpectedTable expectedTable);
475:
476: /**
477: * Assert that a specific table matches a matrix of supplied text values.
478: *
479: * @param tableSummaryOrId
480: * summary or id attribute value of table
481: * @param expectedCellValues
482: * double dimensional array of expected values
483: */
484: public abstract void assertTableEquals(String tableSummaryOrId,
485: String[][] expectedCellValues);
486:
487: /**
488: * Assert that a table with a given summary or id value is not present.
489: *
490: * @param tableSummaryOrId
491: * summary or id attribute value of table
492: */
493: public abstract void assertTableNotPresent(String tableSummaryOrId);
494:
495: /**
496: * Assert that a table with a given summary or id value is present.
497: *
498: * @param tableSummaryOrId
499: * summary or id attribute value of table
500: */
501: public abstract void assertTablePresent(String tableSummaryOrId);
502:
503: /**
504: * Assert that a range of rows for a specific table matches a matrix of
505: * supplied text values.
506: *
507: * @param tableSummaryOrId
508: * summary or id attribute value of table
509: * @param startRow
510: * index of start row for comparison
511: * @param expectedTable
512: * represents expected values (colspan supported).
513: */
514: public abstract void assertTableRowsEqual(String tableSummaryOrId,
515: int startRow, ExpectedTable expectedTable);
516:
517: /**
518: * Assert that a range of rows for a specific table matches a matrix of
519: * supplied text values.
520: *
521: * @param tableSummaryOrId
522: * summary or id attribute value of table
523: * @param startRow
524: * index of start row for comparison
525: * @param expectedCellValues
526: * double dimensional array of expected values
527: */
528: public abstract void assertTableRowsEqual(String tableSummaryOrId,
529: int startRow, String[][] expectedCellValues);
530:
531: /**
532: * Assert that a given element contains specific text.
533: *
534: * @param elementID
535: * id of element to be inspected.
536: * @param text
537: * to check for.
538: */
539: public abstract void assertTextInElement(String elementID,
540: String text);
541:
542: /**
543: * If the list has any non blanks strings, the element must exist and have
544: * all the non blank strings in it.
545: *
546: * @param elementId
547: * @param texts
548: */
549: public void assertTextInElement(String elementId, String[] texts);
550:
551: /**
552: * Assert that supplied text is present in a specific table.
553: *
554: * @param tableSummaryOrId
555: * summary or id attribute value of table
556: * @param text
557: */
558: public abstract void assertTextInTable(String tableSummaryOrId,
559: String text);
560:
561: /**
562: * Assert that a set of text values are all present in a specific table.
563: *
564: * @param tableSummaryOrId
565: * summary or id attribute value of table
566: * @param text
567: * Array of expected text values.
568: */
569: public abstract void assertTextInTable(String tableSummaryOrId,
570: String[] text);
571:
572: /**
573: * Assert that the given text is NOT in (contained in) the given element.
574: *
575: * @param elementID
576: * Id of element
577: * @param text
578: * The text to check for.
579: */
580: public abstract void assertTextNotInElement(String elementID,
581: String text);
582:
583: /**
584: * Assert that supplied text is not present in a specific table.
585: *
586: * @param tableSummaryOrId
587: * summary or id attribute value of table
588: * @param text
589: */
590: public abstract void assertTextNotInTable(String tableSummaryOrId,
591: String text);
592:
593: /**
594: * Assert that none of a set of text values are present in a specific table.
595: *
596: * @param tableSummaryOrId
597: * summary or id attribute value of table
598: * @param text
599: * Array of text values
600: */
601: public abstract void assertTextNotInTable(String tableSummaryOrId,
602: String[] text);
603:
604: /**
605: * Assert that supplied text is not present.
606: *
607: * @param text
608: */
609: public abstract void assertTextNotPresent(String text);
610:
611: /**
612: * Assert that supplied text is present.
613: *
614: * @param text
615: */
616: public abstract void assertTextPresent(String text);
617:
618: /**
619: * Assert title of current html page in conversation matches an expected
620: * value.
621: *
622: * @param title
623: * expected title value
624: */
625: public abstract void assertTitleEquals(String title);
626:
627: /**
628: * Assert title of current html page matches the value of a specified web
629: * resource.
630: *
631: * @param titleKey
632: * web resource key for title
633: */
634: public abstract void assertTitleEqualsKey(String titleKey);
635:
636: /**
637: * Assert that a window with the given name is open.
638: *
639: * @param windowName
640: */
641: public abstract void assertWindowPresent(String windowName);
642:
643: /**
644: * Begin conversation at a url relative to the application root.
645: *
646: * @param relativeURL
647: */
648: public abstract void beginAt(String relativeURL);
649:
650: /**
651: * Select a specified checkbox.
652: *
653: * @param checkBoxName
654: * name of checkbox to be deselected.
655: */
656: public abstract void checkCheckbox(String checkBoxName);
657:
658: /**
659: * Check a checkbox and set a specific value.
660: *
661: * @param checkBoxName
662: * @param value
663: */
664: public abstract void checkCheckbox(String checkBoxName, String value);
665:
666: /**
667: * Click the button with the given id.
668: *
669: * @param buttonId
670: */
671: public abstract void clickButton(String buttonId);
672:
673: /**
674: * Navigate by selection of a link with given id.
675: *
676: * @param linkId
677: * id of link
678: */
679: public abstract void clickLink(String linkId);
680:
681: /**
682: * Navigate by selection of a link with a given image.
683: *
684: * @param imageFileName
685: * A suffix of the image's filename; for example, to match
686: * <tt>"images/my_icon.png"</tt>, you could just pass in
687: * <tt>"my_icon.png"</tt>.
688: */
689: public abstract void clickLinkWithImage(String imageFileName);
690:
691: /**
692: * Navigate by selection of a link containing given text.
693: *
694: * @param linkText
695: */
696: public abstract void clickLinkWithText(String linkText);
697:
698: /**
699: * Navigate by selection of a link containing given text.
700: *
701: * @param linkText
702: * @param index
703: * The 0-based index, when more than one link with the same text
704: * is expected.
705: */
706: public abstract void clickLinkWithText(String linkText, int index);
707:
708: /**
709: * Search for labelText in the document, then search forward until finding a
710: * link called linkText. Click it.
711: *
712: * @param linkText
713: * @param labelText
714: */
715: public abstract void clickLinkWithTextAfterText(String linkText,
716: String labelText);
717:
718: /**
719: * End a trail.
720: */
721: public abstract void endTrail();
722:
723: /**
724: * Gets the LABEL of the selected option in a select box.
725: *
726: * @param selectName
727: * @return The label
728: */
729: public String getDefaultOption(String selectName);
730:
731: /**
732: * Return the value of a web resource based on its key. This translates to a
733: * property file lookup with the locale based on the current TestContext.
734: *
735: * @param key
736: * name of the web resource.
737: * @return value of the web resource, encoded according to TestContext.
738: */
739: public abstract String getMessage(String key);
740:
741: /**
742: * Get all the option values for a select tag.
743: *
744: * @param selectId
745: * The ID of the select tag.
746: * @return Array of options.
747: */
748: public String[] getOptionValues(String selectId);
749:
750: /**
751: * Gets the LABEL of the selected option in a select box.
752: *
753: * @param selectName
754: * The NAME of the select tag.
755: * @return The label
756: */
757: public String getSelectedOptionValue(String selectName);
758:
759: /**
760: * @return Returns the trailFolder.
761: */
762: public abstract File getTrailFolder();
763:
764: /**
765: * Make the named frame active (current response will be frame's contents).
766: *
767: * @param frameName
768: */
769: public abstract void gotoFrame(String frameName);
770:
771: /**
772: * Goto a specific URL, regardless of the base URL.
773: *
774: * @param url
775: * The URL.
776: */
777: public abstract void gotoPage(String url);
778:
779: /**
780: * Make the root window active.
781: */
782: public abstract void gotoRootWindow();
783:
784: /**
785: * Make a given window active (current response will be window's contents).
786: *
787: * @param windowName
788: */
789: public abstract void gotoWindow(String windowName);
790:
791: /**
792: * @return Returns the trailEnabled.
793: */
794: public abstract boolean isTrailEnabled();
795:
796: /**
797: * Reset the current form.
798: */
799: public abstract void reset();
800:
801: /**
802: * Select an option with a given display value in a select element.
803: *
804: * @param selectName
805: * name of select element.
806: * @param option
807: * display value of option to be selected.
808: */
809: public abstract void selectOption(String selectName, String option);
810:
811: /**
812: * Select an option using the value, not the key.
813: *
814: * @param selectId
815: * The id of the select tag.
816: * @param value
817: * The value
818: */
819: public void selectOptionByValue(String selectId, String value);
820:
821: /**
822: * Set the value of a form input element.
823: *
824: * @param formElementName
825: * name of form element.
826: * @param value
827: */
828: public abstract void setFormElement(String formElementName,
829: String value);
830:
831: /**
832: * Overload to enable setting multiple form elements with the same name.
833: *
834: * @param formElementName
835: * name of the form element
836: * @param values
837: * the values to set
838: */
839: public void setFormElement(String formElementName, String[] values);
840:
841: /**
842: * @param trailEnabled
843: * The trailEnabled to set.
844: */
845: public abstract void setTrailEnabled(boolean trailEnabled);
846:
847: /**
848: * @param trailFolder
849: * The trailFolder to set.
850: */
851: public abstract void setTrailFolder(File trailFolder);
852:
853: /**
854: * Set the base URL for the tested web application.
855: * <p>
856: * Delegate method - sets the baseUrl on the test context.
857: *
858: * @param url
859: * The base url, typically the context url of your web
860: * application.
861: */
862: public abstract void setUrl(String url);
863:
864: /**
865: * Begin interaction with a specified form. If form interaction methods are
866: * called without explicitly calling this method first, jWebUnit will
867: * attempt to determine itself which form is being manipulated.
868: *
869: * It is not necessary to call this method if their is only one form on the
870: * current page.
871: *
872: * @param nameOrId
873: * name or id of the form to work with.
874: */
875: public abstract void setWorkingForm(String nameOrId);
876:
877: /**
878: * Finds the form with the specified field in, and sets that form as the
879: * working form. The form does not need to have a name or id.
880: * <p>
881: * This method does use a bit of evil reflection magic to force itself on
882: * HttpUnit, so you really should concider adding a name or id to your form.
883: * <p>
884: * Fails if there are more than one form with that parameter.
885: *
886: * @param fieldName
887: * The field name
888: */
889: public void setWorkingFormByFieldName(String fieldName);
890:
891: /**
892: * Finds the form with the specified field in with a specific value, and
893: * sets that form as the working form. The form does not need to have a name
894: * or id. Very useful for choosing between many different forms that differ
895: * only by the value of a hidden field.
896: * <p>
897: * This method does use a bit of evil reflection magic to force itself on
898: * HttpUnit, so you really should concider adding a name or id to your form.
899: * <p>
900: * It will use the FIRST form it finds with the requested combo.
901: *
902: * @param fieldName
903: * The field name
904: * @param value
905: * The field value
906: */
907: public void setWorkingFormByFieldNameAndValue(String fieldName,
908: String value);
909:
910: /**
911: * Start a new trail. If you start a new trail without ending the last one,
912: * a new trail will be started with no problems.
913: *
914: * @param trailName
915: * Typically the test case name.
916: */
917: public abstract void startTrail(String trailName);
918:
919: /**
920: * Submit form - default submit button will be used (unnamed submit button,
921: * or named button if there is only one on the form.
922: */
923: public abstract void submit();
924:
925: /**
926: * Submit form by pressing named button.
927: *
928: * @param buttonName
929: * name of button to submit form with.
930: */
931: public abstract void submit(String buttonName);
932:
933: /**
934: * Deselect a specified checkbox.
935: *
936: * @param checkBoxName
937: * name of checkbox to be deselected.
938: */
939: public abstract void uncheckCheckbox(String checkBoxName);
940:
941: /**
942: * Deselect a specified checkbox. Sets the value.
943: *
944: * @param checkBoxName
945: * @param value
946: */
947: public abstract void uncheckCheckbox(String checkBoxName,
948: String value);
949:
950: /**
951: * Write the current page to a file, regardless of any current trail or if
952: * trailing is enabled or not.
953: * <p>
954: * If you want a full trail of everything the test sees, use the trail
955: * functionality instead.
956: *
957: * @param filename
958: * Relative filename in the trail folder, or a full file name.
959: */
960: public void writePage(String filename);
961:
962: /**
963: * Your web test steps should call this to write suiteable pages to the
964: * trail.
965: * <p>
966: * If trailing is disabled (default) nothing will happen.
967: *
968: * @param pageName
969: * A page name to prepend to the file name. Useful for the end
970: * user to find out what is happening.
971: */
972: public abstract void writeTrail(String pageName);
973:
974: /**
975: * Push a submit button based on the name and value of it.
976: *
977: * @param buttonName
978: * @param value
979: */
980: public void submit(String buttonName, String value);
981:
982: }
|