1 /** 2 * Copyright (c) 2002-2015, JWebUnit team. 3 * 4 * This file is part of JWebUnit. 5 * 6 * JWebUnit is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * JWebUnit 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 Lesser General Public License 17 * along with JWebUnit. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 package net.sourceforge.jwebunit.junit; 20 21 import java.awt.Image; 22 import java.io.File; 23 import java.io.PrintStream; 24 import java.util.List; 25 import java.util.Map; 26 import java.net.URL; 27 28 import net.sourceforge.jwebunit.api.HttpHeader; 29 import net.sourceforge.jwebunit.api.IElement; 30 import net.sourceforge.jwebunit.api.ITestingEngine; 31 import net.sourceforge.jwebunit.exception.TestingEngineResponseException; 32 import net.sourceforge.jwebunit.html.Table; 33 import net.sourceforge.jwebunit.util.TestContext; 34 35 /** 36 * Utility class for JUnit 4 tests which provides web application navigation and 37 * JUnit assertions. This class uses and is generated from {@link net.sourceforge.jwebunit.junit.WebTester}. 38 * 39 * @author JavaCC 40 */ 41 public class JWebUnit { 42 private static InheritableThreadLocal<WebTester> tester = new InheritableThreadLocal<WebTester>() { 43 @Override 44 protected WebTester childValue(WebTester parentValue) { 45 //Create a new web tester for each child thread 46 WebTester webTester = new WebTester(); 47 //But initialize it with parent TestContext 48 webTester.setTestContext(parentValue.getTestContext()); 49 return webTester; 50 } 51 }; 52 53 private JWebUnit() { 54 //This class should not be instanciated, but instead used statically 55 } 56 57 /** 58 * Get internal WebTester. 59 */ 60 public static WebTester getTester() { 61 if (tester.get() == null) { 62 tester.set(new WebTester()); 63 } 64 return tester.get(); 65 } 66 67 /** 68 * Set a custom WebTester (for example your own subclass). 69 */ 70 public static void setCustomTester(WebTester tester) { 71 JWebUnit.tester.set(tester); 72 } 73 74 /** 75 * Provides access to the testing engine for subclasses - in case functionality not yet wrappered required by test. 76 * 77 * If the testing engine is not explicitly set the JWebUnit framework will default to using the orignal testing engine, 78 * which is, htmlunit. 79 * 80 * @return IJWebUnitDialog instance used to wrapper htmlunit conversation. 81 * @deprecated You should not use plugin specific functionality. Please ask for a new core feature instead. 82 */ 83 public static ITestingEngine getDialog() { 84 return getTester().getDialog(); 85 } 86 87 /** 88 * Set the base url for the test context. 89 * 90 * @param url Base url value - A trailing "/" is appended if not provided. 91 */ 92 public static void setBaseUrl(String url) { 93 getTester().setBaseUrl(url); 94 } 95 96 /** 97 * Set the base url for the test context. 98 * 99 * @param url Base url value - A trailing "/" is appended if not provided. 100 */ 101 public static void setBaseUrl(URL url) { 102 getTester().setBaseUrl(url); 103 } 104 105 /** 106 * Protected version of deprecated getDialog(). Not deprecated for internal use. 107 * 108 * @return IJWebUnitDialog instance. 109 */ 110 public static ITestingEngine getTestingEngine() { 111 return getTester().getTestingEngine(); 112 } 113 114 /** 115 * Close the current conversation. 116 */ 117 public static void closeBrowser() { 118 getTester().closeBrowser(); 119 } 120 121 /** 122 * Close the current window. 123 */ 124 public static void closeWindow() { 125 getTester().closeWindow(); 126 } 127 128 /** 129 * Set the testing engine. 130 * 131 * @param aIJWebUnitDialog Testing engine. 132 */ 133 public static void setDialog(ITestingEngine aIJWebUnitDialog) { 134 getTester().setDialog(aIJWebUnitDialog); 135 } 136 137 /** 138 * Provide access to test testContext. 139 * 140 * @return TestContext 141 */ 142 public static TestContext getTestContext() { 143 return getTester().getTestContext(); 144 } 145 146 /** 147 * Allows setting an external test testContext class that might be extended from TestContext. Example: 148 * setTestContext(new CompanyATestContext()); 149 * 150 * CompanyATestContext extends TestContext. 151 * 152 * @param aTestContext 153 */ 154 public static void setTestContext(TestContext aTestContext) { 155 getTester().setTestContext(aTestContext); 156 } 157 158 /** 159 * Begin conversation at a URL absolute or relative to base URL. Use 160 * {@link TestContext#setBaseUrl(String) getTestContext().setBaseUrl(String)} to define base URL. Absolute URL 161 * should start with "http://", "https://" or "www.". 162 * 163 * @param url absolute or relative URL (relative to base URL). 164 * @throws TestingEngineResponseException If something bad happend (404) 165 */ 166 public static void beginAt(String aRelativeURL)throws TestingEngineResponseException { 167 getTester().beginAt(aRelativeURL); 168 } 169 170 /** 171 * Return the value of a web resource based on its key. This translates to a property file lookup with the locale 172 * based on the current TestContext. 173 * 174 * @param key name of the web resource. 175 * @return value of the web resource, encoded according to TestContext. 176 */ 177 public static String getMessage(String key) { 178 return getTester().getMessage(key); 179 } 180 181 /** 182 * Return the value of a web resource based on its key, using MessageFormat 183 * to perform parametric substitution with formatting. 184 * 185 * @see MessageFormat 186 * @param key 187 * name of the web resource. 188 * @param args 189 * array of arguments to be formatted into message 190 * @return value of the web resource after formatting 191 */ 192 public static String getMessage(String key, Object[] args) { 193 return getTester().getMessage(key, args); 194 } 195 196 /** 197 * Assert that the page response has a particular code. 198 * 199 * @param status the expected status code 200 */ 201 public static void assertResponseCode(int status) { 202 getTester().assertResponseCode(status); 203 } 204 205 /** 206 * Assert that the page response has a particular code between lower and higher 207 * (<code>lower <= status <= higher</code>). 208 * 209 * @param lower the lower bound for the expected status code 210 * @param higher the upper bound for the expected status code 211 */ 212 public static void assertResponseCodeBetween(int lower, int higher) { 213 getTester().assertResponseCodeBetween(lower, higher); 214 } 215 216 /** 217 * Should the tester ignore failing status codes (300+)? Otherwise, 218 * failing status codes will throw an exception. 219 * 220 * @param ignore 221 */ 222 public static void setIgnoreFailingStatusCodes(boolean ignore) { 223 getTester().setIgnoreFailingStatusCodes(ignore); 224 } 225 226 /** 227 * Assert a header is present. 228 * 229 * @param name The header to find 230 */ 231 public static void assertHeaderPresent(String name) { 232 getTester().assertHeaderPresent(name); 233 } 234 235 /** 236 * Assert a header is NOT present. 237 * 238 * @param name The header to find 239 */ 240 public static void assertHeaderNotPresent(String name) { 241 getTester().assertHeaderNotPresent(name); 242 } 243 244 /** 245 * Assert a header is equal to a particular value. 246 * 247 * @param name Header to find 248 * @param value Value to compare against 249 */ 250 public static void assertHeaderEquals(String name, String value) { 251 getTester().assertHeaderEquals(name, value); 252 } 253 254 /** 255 * Assert a header matches a particular pattern. 256 * 257 * @param name Header to find 258 * @param regexp Pattern to compare against 259 */ 260 public static void assertHeaderMatches(String name, String regexp) { 261 getTester().assertHeaderMatches(name, regexp); 262 } 263 264 /** 265 * Get a particular header value. 266 * 267 * @param name Header to find 268 * @return The found header value, or null 269 */ 270 public static String getHeader(String name) { 271 return getTester().getHeader(name); 272 } 273 274 /** 275 * Get all response headers. 276 * 277 * @return A map of response headers 278 * @deprecated This method do not deal with several headers with same name. Use {@link #getResponseHeaders()} instead. 279 */ 280 @Deprecated 281 public static Map<String,String> getAllHeaders() { 282 return getTester().getAllHeaders(); 283 } 284 285 /** 286 * Return all HTTP headers that are in last response. It is possible to have several headers with same name. 287 * 288 * @return A list of {@link HttpHeader} elements. 289 */ 290 public static List<HttpHeader> getResponseHeaders() { 291 return getTester().getResponseHeaders(); 292 } 293 294 /** 295 * Assert title of current html page in conversation matches an expected 296 * value. 297 * 298 * @param title 299 * expected title value 300 */ 301 public static void assertTitleEquals(String title) { 302 getTester().assertTitleEquals(title); 303 } 304 305 /** 306 * Assert title of current html page in conversation is not 307 * equal to another value. 308 * 309 * @param title 310 * unexpected title value 311 * @deprecated Replaced by {@link #assertTitleNotEquals(String)} 312 */ 313 @Deprecated 314 public static void assertTitleNotSame(String title) { 315 getTester().assertTitleNotSame(title); 316 } 317 318 /** 319 * Assert title of current html page in conversation is not 320 * equal to another value. 321 * 322 * @param title 323 * unexpected title value 324 */ 325 public static void assertTitleNotEquals(String title) { 326 getTester().assertTitleNotEquals(title); 327 } 328 329 /** 330 * Assert title of current html page in conversation matches an expected regexp. 331 * 332 * @param regexp expected title regexp 333 */ 334 public static void assertTitleMatch(String regexp) { 335 getTester().assertTitleMatch(regexp); 336 } 337 338 /** 339 * Assert title of current html page matches the value of a specified web 340 * resource. 341 * 342 * @param titleKey 343 * web resource key for title 344 */ 345 public static void assertTitleEqualsKey(String titleKey) { 346 getTester().assertTitleEqualsKey(titleKey); 347 } 348 349 /** 350 * Assert title of current page matches formatted message resource 351 * 352 * @param titleKey 353 * @param args 354 */ 355 public static void assertTitleEqualsKey(String titleKey, Object[] args) { 356 getTester().assertTitleEqualsKey(titleKey, args); 357 } 358 359 /** 360 * Assert that a web resource's value is present. 361 * 362 * @param key 363 * web resource name 364 */ 365 public static void assertKeyPresent(String key) { 366 getTester().assertKeyPresent(key); 367 } 368 369 /** 370 * Assert that a web resource's value (with formatting) is present 371 * 372 * @param key 373 * @param args 374 */ 375 public static void assertKeyPresent(String key, Object[] args) { 376 getTester().assertKeyPresent(key, args); 377 } 378 379 /** 380 * Assert that supplied text is present. 381 * 382 * @param text 383 */ 384 public static void assertTextPresent(String text) { 385 getTester().assertTextPresent(text); 386 } 387 388 /** 389 * Assert that supplied regexp is matched in the text of a page. 390 * 391 * @param regexp 392 */ 393 public static void assertMatch(String regexp) { 394 getTester().assertMatch(regexp); 395 } 396 397 /** 398 * Assert a given string matches a given regular expression. 399 * 400 * @param regexp 401 * @param text 402 */ 403 public static void assertMatch(String regexp, String text) { 404 getTester().assertMatch(regexp, text); 405 } 406 407 /** 408 * Assert a given string does not match a given regular expression. 409 * 410 * @param regexp 411 * @param text 412 */ 413 public static void assertNotMatch(String regexp, String text) { 414 getTester().assertNotMatch(regexp, text); 415 } 416 417 /** 418 * Assert a given string matches a given regular expression. 419 * 420 * @param regexp 421 * @param text 422 */ 423 public static void assertMatch(String message, String regexp, String text) { 424 getTester().assertMatch(message, regexp, text); 425 } 426 427 /** 428 * Assert a given string does not match a given regular expression. 429 * 430 * @param regexp 431 * @param text 432 */ 433 public static void assertNotMatch(String message, String regexp, String text) { 434 getTester().assertNotMatch(message, regexp, text); 435 } 436 437 /** 438 * Assert that a web resource's value is not present. 439 * 440 * @param key web resource name 441 */ 442 public static void assertKeyNotPresent(String key) { 443 getTester().assertKeyNotPresent(key); 444 } 445 446 /** 447 * Assert that a web resource's formatted value is not present. 448 * 449 * @param key 450 * web resource name 451 */ 452 public static void assertKeyNotPresent(String key, Object[] args) { 453 getTester().assertKeyNotPresent(key, args); 454 } 455 456 /** 457 * Assert that supplied text is not present. 458 * 459 * @param text 460 */ 461 public static void assertTextNotPresent(String text) { 462 getTester().assertTextNotPresent(text); 463 } 464 465 /** 466 * Assert that supplied regexp is not present. 467 * 468 * @param regexp 469 */ 470 public static void assertNoMatch(String regexp) { 471 getTester().assertNoMatch(regexp); 472 } 473 474 /** 475 * 476 * @param tableSummaryNameOrId 477 * @return Object that represent a html table in a way independent from plugin. 478 */ 479 public static Table getTable(String tableSummaryNameOrId) { 480 return getTester().getTable(tableSummaryNameOrId); 481 } 482 483 /** 484 * Assert that a table with a given summary or id value is present. 485 * 486 * @param tableSummaryNameOrId summary, name or id attribute value of table 487 */ 488 public static void assertTablePresent(String tableSummaryNameOrId) { 489 getTester().assertTablePresent(tableSummaryNameOrId); 490 } 491 492 /** 493 * Assert that a table with a given summary or id value is not present. 494 * 495 * @param tableSummaryNameOrId summary, name or id attribute value of table 496 */ 497 public static void assertTableNotPresent(String tableSummaryNameOrId) { 498 getTester().assertTableNotPresent(tableSummaryNameOrId); 499 } 500 501 /** 502 * Assert that the value of a given web resource is present in a specific table. 503 * 504 * @param tableSummaryOrId summary or id attribute value of table 505 * @param key web resource name 506 */ 507 public static void assertKeyInTable(String tableSummaryOrId, String key) { 508 getTester().assertKeyInTable(tableSummaryOrId, key); 509 } 510 511 /** 512 * Assert that the value of a given web resource is present in a specific 513 * table. 514 * 515 * @param tableSummaryOrId 516 * summary or id attribute value of table 517 * @param key 518 * web resource name 519 */ 520 public static void assertKeyInTable(String tableSummaryOrId, String key, Object[] args) { 521 getTester().assertKeyInTable(tableSummaryOrId, key, args); 522 } 523 524 /** 525 * Assert that supplied text is present in a specific table. 526 * 527 * @param tableSummaryNameOrId 528 * summary, name or id attribute value of table 529 * @param text 530 */ 531 public static void assertTextInTable(String tableSummaryNameOrId, String text) { 532 getTester().assertTextInTable(tableSummaryNameOrId, text); 533 } 534 535 /** 536 * Assert that supplied regexp is matched in a specific table. 537 * 538 * @param tableSummaryNameOrId summary, name or id attribute value of table 539 * @param regexp 540 */ 541 public static void assertMatchInTable(String tableSummaryNameOrId, String regexp) { 542 getTester().assertMatchInTable(tableSummaryNameOrId, regexp); 543 } 544 545 /** 546 * Assert that the values of a set of web resources are all present in a specific table. 547 * 548 * @param tableSummaryOrId summary, name or id attribute value of table 549 * @param keys Array of web resource names. 550 */ 551 public static void assertKeysInTable(String tableSummaryOrId, String[] keys) { 552 getTester().assertKeysInTable(tableSummaryOrId, keys); 553 } 554 555 /** 556 * Assert that the values of a set of web resources are all present in a 557 * specific table. 558 * 559 * @param tableSummaryOrId 560 * summary or id attribute value of table 561 * @param keys 562 * Array of web resource names. 563 */ 564 public static void assertKeysInTable(String tableSummaryOrId, String[] keys, Object[][] args) { 565 getTester().assertKeysInTable(tableSummaryOrId, keys, args); 566 } 567 568 /** 569 * Assert that a set of text values are all present in a specific table. 570 * 571 * @param tableSummaryOrId 572 * summary, name or id attribute value of table 573 * @param text 574 * Array of expected text values. 575 */ 576 public static void assertTextInTable(String tableSummaryOrId, String[] text) { 577 getTester().assertTextInTable(tableSummaryOrId, text); 578 } 579 580 /** 581 * Assert that a set of regexp values are all matched in a specific table. 582 * 583 * @param tableSummaryOrId summary, name or id attribute value of table 584 * @param text Array of expected regexps to match. 585 */ 586 public static void assertMatchInTable(String tableSummaryOrId, String[] regexp) { 587 getTester().assertMatchInTable(tableSummaryOrId, regexp); 588 } 589 590 /** 591 * Assert that the value of a given web resource is not present in a specific table. 592 * 593 * @param tableSummaryOrId summary, name or id attribute value of table 594 * @param key web resource name 595 */ 596 public static void assertKeyNotInTable(String tableSummaryOrId, String key) { 597 getTester().assertKeyNotInTable(tableSummaryOrId, key); 598 } 599 600 /** 601 * Assert that supplied text is not present in a specific table. 602 * 603 * @param tableSummaryNameOrId summary, name or id attribute value of table 604 * @param text 605 */ 606 public static void assertTextNotInTable(String tableSummaryNameOrId, String text) { 607 getTester().assertTextNotInTable(tableSummaryNameOrId, text); 608 } 609 610 /** 611 * Assert that none of a set of text values are present in a specific table. 612 * 613 * @param tableSummaryNameOrId summary, name or id attribute value of table 614 * @param text Array of text values 615 */ 616 public static void assertTextNotInTable(String tableSummaryNameOrId, String[] text) { 617 getTester().assertTextNotInTable(tableSummaryNameOrId, text); 618 } 619 620 /** 621 * Assert that supplied regexp is not present in a specific table. 622 * 623 * @param tableSummaryNameOrId summary, name or id attribute value of table 624 * @param text 625 */ 626 public static void assertNoMatchInTable(String tableSummaryNameOrId, String regexp) { 627 getTester().assertNoMatchInTable(tableSummaryNameOrId, regexp); 628 } 629 630 /** 631 * Assert that none of a set of regexp values are present in a specific table. 632 * 633 * @param tableSummaryNameOrId summary, name or id attribute value of table 634 * @param text Array of text values 635 */ 636 public static void assertNoMatchInTable(String tableSummaryNameOrId, String[] regexp) { 637 getTester().assertNoMatchInTable(tableSummaryNameOrId, regexp); 638 } 639 640 /** 641 * Assert that a specific table matches an ExpectedTable. 642 * 643 * @param tableSummaryNameOrId summary, name or id attribute value of table 644 * @param expectedTable represents expected values (colspan supported). 645 */ 646 public static void assertTableEquals(String tableSummaryNameOrId, Table expectedTable) { 647 getTester().assertTableEquals(tableSummaryNameOrId, expectedTable); 648 } 649 650 /** 651 * Assert that a specific table matches a matrix of supplied text values. 652 * 653 * @param tableSummaryNameOrId summary, name or id attribute value of table 654 * @param expectedCellValues double dimensional array of expected values 655 */ 656 public static void assertTableEquals(String tableSummaryNameOrId, String[][] expectedCellValues) { 657 getTester().assertTableEquals(tableSummaryNameOrId, expectedCellValues); 658 } 659 660 /** 661 * Assert that a range of rows for a specific table matches a matrix of supplied text values. 662 * 663 * @param tableSummaryNameOrId summary, name or id attribute value of table 664 * @param startRow index of start row for comparison 665 * @param expectedTable represents expected values (colspan and rowspan supported). 666 */ 667 public static void assertTableRowsEqual(String tableSummaryNameOrId, int startRow, Table expectedTable) { 668 getTester().assertTableRowsEqual(tableSummaryNameOrId, startRow, expectedTable); 669 } 670 671 /** 672 * Assert that a range of rows for a specific table matches a matrix of supplied text values. 673 * 674 * @param tableSummaryNameOrId summary, name or id attribute value of table 675 * @param startRow index of start row for comparison 676 * @param expectedTable represents expected values (colspan and rowspan supported). 677 */ 678 public static void assertTableRowsEqual(String tableSummaryNameOrId, int startRow, String[][] expectedTable) { 679 getTester().assertTableRowsEqual(tableSummaryNameOrId, startRow, expectedTable); 680 } 681 682 /** 683 * Assert that the number of rows for a specific table equals expected value. 684 * 685 * @param tableSummaryNameOrId summary, name or id attribute value of table 686 * @param expectedRowCount expected row count. 687 */ 688 public static void assertTableRowCountEquals(String tableSummaryNameOrId, int expectedRowCount) { 689 getTester().assertTableRowCountEquals(tableSummaryNameOrId, expectedRowCount); 690 } 691 692 /** 693 * Assert that a specific table matches an ExpectedTable. 694 * 695 * @param tableSummaryOrId summary or id attribute value of table 696 * @param expectedTable represents expected regexps (colspan supported). 697 */ 698 public static void assertTableMatch(String tableSummaryOrId, Table expectedTable) { 699 getTester().assertTableMatch(tableSummaryOrId, expectedTable); 700 } 701 702 /** 703 * Assert that a specific table matches a matrix of supplied regexps. 704 * 705 * @param tableSummaryOrId summary or id attribute value of table 706 * @param expectedCellValues double dimensional array of expected regexps 707 */ 708 public static void assertTableMatch(String tableSummaryOrId, String[][] expectedCellValues) { 709 getTester().assertTableMatch(tableSummaryOrId, expectedCellValues); 710 } 711 712 /** 713 * Assert that a range of rows for a specific table matches a matrix of supplied regexps. 714 * 715 * @param tableSummaryOrId summary or id attribute value of table 716 * @param startRow index of start row for comparison 717 * @param expectedTable represents expected regexps (colspan and rowspan supported). 718 */ 719 public static void assertTableRowsMatch(String tableSummaryOrId, int startRow, Table expectedTable) { 720 getTester().assertTableRowsMatch(tableSummaryOrId, startRow, expectedTable); 721 } 722 723 /** 724 * Assert that a range of rows for a specific table matches a matrix of supplied regexps. 725 * 726 * @param tableSummaryOrId summary or id attribute value of table 727 * @param startRow index of start row for comparison 728 * @param expectedTable represents expected regexps (colspan and rowspan not supported). 729 */ 730 public static void assertTableRowsMatch(String tableSummaryOrId, int startRow, String[][] expectedTable) { 731 getTester().assertTableRowsMatch(tableSummaryOrId, startRow, expectedTable); 732 } 733 734 /** 735 * Assert that a form input element with a given name is present. 736 * 737 * @param formElementName 738 */ 739 public static void assertFormElementPresent(String formElementName) { 740 getTester().assertFormElementPresent(formElementName); 741 } 742 743 /** 744 * Assert that a form input element with a given name is not present. 745 * 746 * @param formElementName 747 */ 748 public static void assertFormElementNotPresent(String formElementName) { 749 getTester().assertFormElementNotPresent(formElementName); 750 } 751 752 /** 753 * Assert that a form checkbox with a given name is present. 754 * 755 * @param checkboxName checkbox name. 756 */ 757 public static void assertCheckboxPresent(String checkboxName) { 758 getTester().assertCheckboxPresent(checkboxName); 759 } 760 761 /** 762 * Assert that a given checkbox is present. 763 * 764 * @param checkboxName checkbox name attribut. 765 * @param checkboxValue checkbox value attribut. 766 */ 767 public static void assertCheckboxPresent(String checkboxName, String checkboxValue) { 768 getTester().assertCheckboxPresent(checkboxName, checkboxValue); 769 } 770 771 /** 772 * Assert that a form checkbox with a given name is not present. 773 * 774 * @param checkboxName checkbox name. 775 */ 776 public static void assertCheckboxNotPresent(String checkboxName) { 777 getTester().assertCheckboxNotPresent(checkboxName); 778 } 779 780 /** 781 * Assert that a given checkbox is not present. 782 * 783 * @param checkboxName checkbox name. 784 * @param checkboxValue checkbox value attribut. 785 */ 786 public static void assertCheckboxNotPresent(String checkboxName, String checkboxValue) { 787 getTester().assertCheckboxNotPresent(checkboxName, checkboxValue); 788 } 789 790 /** 791 * Assert that there is a form present. 792 * 793 */ 794 public static void assertFormPresent() { 795 getTester().assertFormPresent(); 796 } 797 798 /** 799 * Assert that there is a form with the specified name or id present. 800 * 801 * @param nameOrID 802 */ 803 public static void assertFormPresent(String nameOrID) { 804 getTester().assertFormPresent(nameOrID); 805 } 806 807 /** 808 * Assert that there is a form with the specified name or id and the given index present. 809 * 810 * @param nameOrID 811 * @param index The 0-based index, when more than one form with the same name is expected. 812 */ 813 public static void assertFormPresent(String nameOrID, int index) { 814 getTester().assertFormPresent(nameOrID, index); 815 } 816 817 /** 818 * Assert that there is not a form present. 819 * 820 */ 821 public static void assertFormNotPresent() { 822 getTester().assertFormNotPresent(); 823 } 824 825 /** 826 * Assert that there is not a form with the specified name or id present. 827 * 828 * @param nameOrID 829 */ 830 public static void assertFormNotPresent(String nameOrID) { 831 getTester().assertFormNotPresent(nameOrID); 832 } 833 834 /** 835 * Assert that a specific form element has an expected value. Can be used to check hidden input. 836 * 837 * @param formElementName 838 * @param expectedValue 839 * @see #assertTextFieldEquals(String, String) 840 * @deprecated use an explicit testing method, e.g. {@link #assertTextFieldEquals(String, String)} 841 */ 842 public static void assertFormElementEquals(String formElementName, String expectedValue) { 843 getTester().assertFormElementEquals(formElementName, expectedValue); 844 } 845 846 /** 847 * Assert that a specific form element matches an expected regexp. 848 * 849 * @param formElementName 850 * @param regexp 851 */ 852 public static void assertFormElementMatch(String formElementName, String regexp) { 853 getTester().assertFormElementMatch(formElementName, regexp); 854 } 855 856 /** 857 * Assert that a form element had no value / is empty. 858 * 859 * @param formElementName 860 * @see #setTextField(String, String) 861 * @see #setHiddenField(String, String) 862 * @deprecated use an explicit testing method, e.g. {@link #setTextField(String, String)} or {@link #setHiddenField(String, String)} 863 */ 864 public static void assertFormElementEmpty(String formElementName) { 865 getTester().assertFormElementEmpty(formElementName); 866 } 867 868 /** 869 * Assert that an input text element with name <code>formElementName</code> has the <code>expectedValue</code> 870 * value. 871 * 872 * @param formElementName the value of the name attribute of the element 873 * @param expectedValue the expected value of the given input element 874 */ 875 public static void assertTextFieldEquals(String formElementName, String expectedValue) { 876 getTester().assertTextFieldEquals(formElementName, expectedValue); 877 } 878 879 /** 880 * Assert that an input hidden element with name <code>formElementName</code> has the <code>expectedValue</code> 881 * value. 882 * 883 * @param formElementName the value of the name attribute of the element 884 * @param expectedValue the expected value of the given input element 885 */ 886 public static void assertHiddenFieldPresent(String formElementName, String expectedValue) { 887 getTester().assertHiddenFieldPresent(formElementName, expectedValue); 888 } 889 890 /** 891 * Assert that a specific checkbox is selected. 892 * 893 * @param checkBoxName 894 */ 895 public static void assertCheckboxSelected(String checkBoxName) { 896 getTester().assertCheckboxSelected(checkBoxName); 897 } 898 899 /** 900 * Assert that a specific checkbox is selected. 901 * 902 * @param checkBoxName 903 * @param checkBoxValue 904 */ 905 public static void assertCheckboxSelected(String checkBoxName, String checkBoxValue) { 906 getTester().assertCheckboxSelected(checkBoxName, checkBoxValue); 907 } 908 909 /** 910 * Assert that a specific checkbox is not selected. 911 * 912 * @param checkBoxName 913 */ 914 public static void assertCheckboxNotSelected(String checkBoxName) { 915 getTester().assertCheckboxNotSelected(checkBoxName); 916 } 917 918 /** 919 * Assert that a specific checkbox is not selected. 920 * 921 * @param checkBoxName 922 * @param checkBoxValue 923 */ 924 public static void assertCheckboxNotSelected(String checkBoxName, String checkBoxValue) { 925 getTester().assertCheckboxNotSelected(checkBoxName, checkBoxValue); 926 } 927 928 /** 929 * Assert that a specific option is present in a radio group. 930 * 931 * @param name radio group name. 932 * @param radioOption option to test for. 933 */ 934 public static void assertRadioOptionPresent(String name, String radioOption) { 935 getTester().assertRadioOptionPresent(name, radioOption); 936 } 937 938 /** 939 * Assert that a specific option is not present in a radio group. 940 * 941 * @param name radio group name. 942 * @param radioOption option to test for. 943 */ 944 public static void assertRadioOptionNotPresent(String name, String radioOption) { 945 getTester().assertRadioOptionNotPresent(name, radioOption); 946 } 947 948 /** 949 * Assert that a specific option is selected in a radio group. 950 * 951 * @param name radio group name. 952 * @param radioOption option to test for selection. 953 */ 954 public static void assertRadioOptionSelected(String name, String radioOption) { 955 getTester().assertRadioOptionSelected(name, radioOption); 956 } 957 958 /** 959 * Assert that a specific option is not selected in a radio group. 960 * 961 * @param name radio group name. 962 * @param radioOption option to test for selection. 963 */ 964 public static void assertRadioOptionNotSelected(String name, String radioOption) { 965 getTester().assertRadioOptionNotSelected(name, radioOption); 966 } 967 968 /** 969 * Assert that given options are present in a select box (by label). 970 * 971 * @param selectName name of the select element. 972 * @param optionLabels option labels. 973 */ 974 public static void assertSelectOptionsPresent(String selectName, String[] optionLabels) { 975 getTester().assertSelectOptionsPresent(selectName, optionLabels); 976 } 977 978 /** 979 * Assert that a specific option is present in a select box (by label). 980 * 981 * @param selectName name of the select element. 982 * @param optionLabel option label. 983 */ 984 public static void assertSelectOptionPresent(String selectName, String optionLabel) { 985 getTester().assertSelectOptionPresent(selectName, optionLabel); 986 } 987 988 /** 989 * Assert that given options are present in the Nth select box (by label). 990 * 991 * @param selectName name of the select element. 992 * @param index the 0-based index of the select element when multiple 993 * select elements are expected. 994 * @param optionLabels option labels. 995 */ 996 public static void assertSelectOptionsPresent(String selectName, int index, String[] optionLabels) { 997 getTester().assertSelectOptionsPresent(selectName, index, optionLabels); 998 } 999 1000 /** 1001 * Assert that a specific option is present in the Nth select box (by label). 1002 * 1003 * @param selectName name of the select element. 1004 * @param index the 0-based index of the select element when multiple 1005 * select elements are expected. 1006 * @param optionLabel option label. 1007 */ 1008 public static void assertSelectOptionPresent(String selectName, int index, String optionLabel) { 1009 getTester().assertSelectOptionPresent(selectName, index, optionLabel); 1010 } 1011 1012 /** 1013 * Assert that given options are present in a select box (by value). 1014 * 1015 * @param selectName name of the select element. 1016 * @param optionValues option labels. 1017 */ 1018 public static void assertSelectOptionValuesPresent(String selectName, String[] optionValues) { 1019 getTester().assertSelectOptionValuesPresent(selectName, optionValues); 1020 } 1021 1022 /** 1023 * Assert that a specific option is present in a select box (by value). 1024 * 1025 * @param selectName name of the select element. 1026 * @param optionValue option value. 1027 */ 1028 public static void assertSelectOptionValuePresent(String selectName, String optionValue) { 1029 getTester().assertSelectOptionValuePresent(selectName, optionValue); 1030 } 1031 1032 /** 1033 * Assert that given options are present in the Nth select box (by value). 1034 * 1035 * @param selectName name of the select element. 1036 * @param index the 0-based index of the select element when multiple 1037 * select elements are expected. 1038 * @param optionValues option labels. 1039 */ 1040 public static void assertSelectOptionValuesPresent(String selectName, int index, String[] optionValues) { 1041 getTester().assertSelectOptionValuesPresent(selectName, index, optionValues); 1042 } 1043 1044 /** 1045 * Assert that a specific option is present in the Nth select box (by value). 1046 * 1047 * @param selectName name of the select element. 1048 * @param index the 0-based index of the select element when multiple 1049 * select elements are expected. 1050 * @param optionValue option value. 1051 */ 1052 public static void assertSelectOptionValuePresent(String selectName, int index, String optionValue) { 1053 getTester().assertSelectOptionValuePresent(selectName, index, optionValue); 1054 } 1055 1056 /** 1057 * Assert that a specific option value is not present in a select box. 1058 * 1059 * @param selectName name of the select element. 1060 * @param optionValue option value. 1061 */ 1062 public static void assertSelectOptionValueNotPresent(String selectName, String optionValue) { 1063 getTester().assertSelectOptionValueNotPresent(selectName, optionValue); 1064 } 1065 1066 /** 1067 * Assert that a specific option is not present in a select box. 1068 * 1069 * @param selectName name of the select element. 1070 * @param expectedOption option label. 1071 */ 1072 public static void assertSelectOptionNotPresent(String selectName, String optionLabel) { 1073 getTester().assertSelectOptionNotPresent(selectName, optionLabel); 1074 } 1075 1076 /** 1077 * Assert that a specific option value is not present in a select box. 1078 * 1079 * @param selectName name of the select element. 1080 * @param optionValue option value. 1081 */ 1082 public static void assertSelectOptionValueNotPresent(String selectName, int index, String optionValue) { 1083 getTester().assertSelectOptionValueNotPresent(selectName, index, optionValue); 1084 } 1085 1086 /** 1087 * Assert that a specific option is not present in a select box. 1088 * 1089 * @param selectName name of the select element. 1090 * @param expectedOption option label. 1091 */ 1092 public static void assertSelectOptionNotPresent(String selectName, int index, String optionLabel) { 1093 getTester().assertSelectOptionNotPresent(selectName, index, optionLabel); 1094 } 1095 1096 /** 1097 * Assert that the display values of a select element's options match a given array of strings. 1098 * 1099 * @param selectName name of the select element. 1100 * @param expectedOptions expected labels for the select box. 1101 */ 1102 public static void assertSelectOptionsEqual(String selectName, String[] expectedOptions) { 1103 getTester().assertSelectOptionsEqual(selectName, expectedOptions); 1104 } 1105 1106 /** 1107 * Assert that the display values of 1108 * the Nth select element's options match a given array of strings. 1109 * 1110 * @param selectName name of the select element. 1111 * @param index the 0-based index of the select element when multiple 1112 * select elements are expected. 1113 * @param expectedOptions expected labels for the select box. 1114 */ 1115 public static void assertSelectOptionsEqual(String selectName, int index, String[] expectedOptions) { 1116 getTester().assertSelectOptionsEqual(selectName, index, expectedOptions); 1117 } 1118 1119 /** 1120 * Assert that the display values of a select element's options do not match a given array of strings. 1121 * 1122 * @param selectName name of the select element. 1123 * @param expectedOptions expected display values for the select box. 1124 */ 1125 public static void assertSelectOptionsNotEqual(String selectName, String[] expectedOptions) { 1126 getTester().assertSelectOptionsNotEqual(selectName, expectedOptions); 1127 } 1128 1129 /** 1130 * Assert that the display values of the Nth select element's 1131 * options do not match a given array of strings. 1132 * 1133 * @param selectName name of the select element. 1134 * @param index the 0-based index of the select element when multiple 1135 * select elements are expected. 1136 * @param expectedOptions expected display values for the select box. 1137 */ 1138 public static void assertSelectOptionsNotEqual(String selectName, int index, String[] expectedOptions) { 1139 getTester().assertSelectOptionsNotEqual(selectName, index, expectedOptions); 1140 } 1141 1142 /** 1143 * Assert that the values of the Nth select element's options match 1144 * a given array of strings. 1145 * 1146 * @param selectName name of the select element. 1147 * @param index the 0-based index of the select element when multiple 1148 * select elements are expected. 1149 * @param expectedValues expected values for the select box. 1150 */ 1151 public static void assertSelectOptionValuesEqual(String selectName, int index, String[] expectedValues) { 1152 getTester().assertSelectOptionValuesEqual(selectName, index, expectedValues); 1153 } 1154 1155 /** 1156 * Assert that the values of a select element's options match a given array of strings. 1157 * 1158 * @param selectName name of the select element. 1159 * @param expectedValues expected values for the select box. 1160 */ 1161 public static void assertSelectOptionValuesEqual(String selectName, String[] expectedValues) { 1162 getTester().assertSelectOptionValuesEqual(selectName, expectedValues); 1163 } 1164 1165 /** 1166 * Assert that the values of a select element's options do not match a given array of strings. 1167 * 1168 * @param selectName name of the select element. 1169 * @param optionValues expected values for the select box. 1170 */ 1171 public static void assertSelectOptionValuesNotEqual(String selectName, String[] optionValues) { 1172 getTester().assertSelectOptionValuesNotEqual(selectName, optionValues); 1173 } 1174 1175 /** 1176 * Assert that the values of the Nth select element's options do not match a 1177 * given array of strings. 1178 * 1179 * @param selectName name of the select element. 1180 * @param index the 0-based index of the select element when multiple 1181 * select elements are expected. 1182 * @param optionValues expected values for the select box. 1183 */ 1184 public static void assertSelectOptionValuesNotEqual(String selectName, int index, String[] optionValues) { 1185 getTester().assertSelectOptionValuesNotEqual(selectName, index, optionValues); 1186 } 1187 1188 /** 1189 * Assert that the currently selected display label(s) of a select box matches given label(s). 1190 * 1191 * @param selectName name of the select element. 1192 * @param labels expected display label(s) of the selected option. 1193 */ 1194 public static void assertSelectedOptionsEqual(String selectName, String[] labels) { 1195 getTester().assertSelectedOptionsEqual(selectName, labels); 1196 } 1197 1198 /** 1199 * Assert that the currently selected display label(s) of a select box matches given label(s). 1200 * 1201 * @param selectName name of the select element. 1202 * @param index the 0-based index used when more than one select element 1203 * with the same name is expected. 1204 * @param labels expected display label(s) of the selected option. 1205 */ 1206 public static void assertSelectedOptionsEqual(String selectName, int index, String[] labels) { 1207 getTester().assertSelectedOptionsEqual(selectName, index, labels); 1208 } 1209 1210 /** 1211 * Assert that the label of the current selected option matches 1212 * the provided value. 1213 * @param selectName name of the select element 1214 * @param optionLabel expected value of the option label 1215 */ 1216 public static void assertSelectedOptionEquals(String selectName, String optionLabel) { 1217 getTester().assertSelectedOptionEquals(selectName, optionLabel); 1218 } 1219 1220 /** 1221 * Assert that the label of the current selected option matches 1222 * the provided value in the Nth select element with the specified name. 1223 * @param selectName name of the select element 1224 * @param index the 0-based index used when more than one select element 1225 * with the same name is expected. 1226 * @param optionLabel expected value of the option label 1227 */ 1228 public static void assertSelectedOptionEquals(String selectName, int index, String option) { 1229 getTester().assertSelectedOptionEquals(selectName, index, option); 1230 } 1231 1232 /** 1233 * Assert that the currently selected value(s) of a select box matches given value(s). 1234 * 1235 * @param selectName name of the select element. 1236 * @param values expected value(s) of the selected option. 1237 */ 1238 public static void assertSelectedOptionValuesEqual(String selectName, String[] values) { 1239 getTester().assertSelectedOptionValuesEqual(selectName, values); 1240 } 1241 1242 /** 1243 * Assert that the currently selected value(s) of the Nth 1244 * select box with the specified name matches given value(s). 1245 * 1246 * @param selectName name of the select element. 1247 * @param index the 0-based index used when more than one select element 1248 * with the same name is expected. 1249 * @param values expected value(s) of the selected option. 1250 */ 1251 public static void assertSelectedOptionValuesEqual(String selectName, int index, String[] values) { 1252 getTester().assertSelectedOptionValuesEqual(selectName, index, values); 1253 } 1254 1255 /** 1256 * Assert that the currently selected value of a select box matches given value. 1257 * 1258 * @param selectName name of the select element. 1259 * @param value expected value of the selected option. 1260 */ 1261 public static void assertSelectedOptionValueEquals(String selectName, String value) { 1262 getTester().assertSelectedOptionValueEquals(selectName, value); 1263 } 1264 1265 /** 1266 * Assert that the currently selected value of a select box matches given value. 1267 * 1268 * @param selectName name of the select element. 1269 * @param index the 0-based index used when more than one select element 1270 * with the same name is expected. 1271 * @param value expected value of the selected option. 1272 */ 1273 public static void assertSelectedOptionValueEquals(String selectName, int index, String value) { 1274 getTester().assertSelectedOptionValueEquals(selectName, index, value); 1275 } 1276 1277 /** 1278 * Assert that the currently selected display value(s) of a select box matches a given value(s). 1279 * 1280 * @param selectName name of the select element. 1281 * @param regexps expected display value of the selected option. 1282 */ 1283 public static void assertSelectedOptionsMatch(String selectName, String[] regexps) { 1284 getTester().assertSelectedOptionsMatch(selectName, regexps); 1285 } 1286 1287 /** 1288 * Assert that the currently selected display value(s) of a select box matches a given value(s). 1289 * 1290 * @param selectName name of the select element. 1291 * @param index the 0-based index used when more than one select element 1292 * with the same name is expected. 1293 * @param regexps expected display value of the selected option. 1294 */ 1295 public static void assertSelectedOptionsMatch(String selectName, int index, String[] regexps) { 1296 getTester().assertSelectedOptionsMatch(selectName, index, regexps); 1297 } 1298 1299 /** 1300 * Assert that the label of the current selected option matches 1301 * the provided regular expression value. 1302 * @param selectName name of the select element 1303 * @param regexp the regular expression to match 1304 */ 1305 public static void assertSelectedOptionMatches(String selectName, String regexp) { 1306 getTester().assertSelectedOptionMatches(selectName, regexp); 1307 } 1308 1309 /** 1310 * Assert that the label of the current selected option matches 1311 * the provided regular expression in the Nth select element with the specified name. 1312 * @param selectName name of the select element 1313 * @param index the 0-based index used when more than one select element 1314 * with the same name is expected. 1315 * @param regexp the regular expression to match 1316 */ 1317 public static void assertSelectedOptionMatches(String selectName, int index, String regexp) { 1318 getTester().assertSelectedOptionMatches(selectName, index, regexp); 1319 } 1320 1321 /** 1322 * Assert that a submit button is present. <br/> A submit button can be the following HTML elements: 1323 * <ul> 1324 * <li>submit input 1325 * <li>image input 1326 * <li>submit button 1327 * </ul> 1328 * 1329 */ 1330 public static void assertSubmitButtonPresent() { 1331 getTester().assertSubmitButtonPresent(); 1332 } 1333 1334 /** 1335 * Assert that a submit button with a given name is present. <br/> A submit button can be the following HTML 1336 * elements: 1337 * <ul> 1338 * <li>submit input 1339 * <li>image input 1340 * <li>submit button 1341 * </ul> 1342 * 1343 * @param buttonName 1344 */ 1345 public static void assertSubmitButtonPresent(String buttonName) { 1346 getTester().assertSubmitButtonPresent(buttonName); 1347 } 1348 1349 /** 1350 * Assert that no submit button is present in the current form. <br/> A submit button can be the following HTML 1351 * elements: 1352 * <ul> 1353 * <li>submit input 1354 * <li>image input 1355 * <li>submit button 1356 * </ul> 1357 * 1358 * @param buttonName 1359 */ 1360 public static void assertSubmitButtonNotPresent() { 1361 getTester().assertSubmitButtonNotPresent(); 1362 } 1363 1364 /** 1365 * Assert that a submit button with a given name is not present. <br/> A submit button can be the following HTML 1366 * elements: 1367 * <ul> 1368 * <li>submit input 1369 * <li>image input 1370 * <li>submit button 1371 * </ul> 1372 * 1373 * @param buttonName 1374 */ 1375 public static void assertSubmitButtonNotPresent(String buttonName) { 1376 getTester().assertSubmitButtonNotPresent(buttonName); 1377 } 1378 1379 /** 1380 * Assert that a submit button with a given name and value is present. <br/> A submit button can be the following 1381 * HTML elements: 1382 * <ul> 1383 * <li>submit input 1384 * <li>image input 1385 * <li>submit button 1386 * </ul> 1387 * 1388 * @param buttonName 1389 * @param buttonValue 1390 */ 1391 public static void assertSubmitButtonPresent(String buttonName, String buttonValue) { 1392 getTester().assertSubmitButtonPresent(buttonName, buttonValue); 1393 } 1394 1395 /** 1396 * Assert that a reset button is present. <br/> A reset button can be the following HTML elements: 1397 * <ul> 1398 * <li>reset input 1399 * <li>reset button 1400 * </ul> 1401 * 1402 */ 1403 public static void assertResetButtonPresent() { 1404 getTester().assertResetButtonPresent(); 1405 } 1406 1407 /** 1408 * Assert that a reset button with a given name is present.<br/> A reset button can be the following HTML elements: 1409 * <ul> 1410 * <li>reset input 1411 * <li>reset button 1412 * </ul> 1413 * 1414 * @param buttonName 1415 */ 1416 public static void assertResetButtonPresent(String buttonName) { 1417 getTester().assertResetButtonPresent(buttonName); 1418 } 1419 1420 /** 1421 * Assert that no reset button is present in the current form.<br/> A reset button can be the following HTML 1422 * elements: 1423 * <ul> 1424 * <li>reset input 1425 * <li>reset button 1426 * </ul> 1427 * 1428 * @param buttonName 1429 */ 1430 public static void assertResetButtonNotPresent() { 1431 getTester().assertResetButtonNotPresent(); 1432 } 1433 1434 /** 1435 * Assert that a reset button with a given name is not present.<br/> A reset button can be the following HTML 1436 * elements: 1437 * <ul> 1438 * <li>reset input 1439 * <li>reset button 1440 * </ul> 1441 * 1442 * @param buttonName 1443 */ 1444 public static void assertResetButtonNotPresent(String buttonName) { 1445 getTester().assertResetButtonNotPresent(buttonName); 1446 } 1447 1448 /** 1449 * Assert that a button with a given id is present in the current window.<br/> A button can be the following HTML 1450 * elements: 1451 * <ul> 1452 * <li>button input 1453 * <li>button button 1454 * </ul> 1455 * 1456 * @param buttonId 1457 */ 1458 public static void assertButtonPresent(String buttonId) { 1459 getTester().assertButtonPresent(buttonId); 1460 } 1461 1462 /** 1463 * Assert that a button with a given text is present in the current window. 1464 * 1465 * @param text Text representation of button content. 1466 */ 1467 public static void assertButtonPresentWithText(String text) { 1468 getTester().assertButtonPresentWithText(text); 1469 } 1470 1471 /** 1472 * Assert that a button with a given text is not present in the current window. 1473 * 1474 * @param text Text representation of button content. 1475 */ 1476 public static void assertButtonNotPresentWithText(String text) { 1477 getTester().assertButtonNotPresentWithText(text); 1478 } 1479 1480 /** 1481 * Assert that a button with a given id is not present in the current window. 1482 * 1483 * @param buttonId 1484 */ 1485 public static void assertButtonNotPresent(String buttonId) { 1486 getTester().assertButtonNotPresent(buttonId); 1487 } 1488 1489 /** 1490 * Assert that a link with a given id is present in the response. 1491 * 1492 * @param linkId 1493 */ 1494 public static void assertLinkPresent(String linkId) { 1495 getTester().assertLinkPresent(linkId); 1496 } 1497 1498 /** 1499 * Assert that no link with the given id is present in the response. 1500 * 1501 * @param linkId 1502 */ 1503 public static void assertLinkNotPresent(String linkId) { 1504 getTester().assertLinkNotPresent(linkId); 1505 } 1506 1507 /** 1508 * Assert that a link containing the supplied text is present. 1509 * 1510 * @param linkText 1511 */ 1512 public static void assertLinkPresentWithText(String linkText) { 1513 getTester().assertLinkPresentWithText(linkText); 1514 } 1515 1516 /** 1517 * Assert that no link containing the supplied text is present. 1518 * 1519 * @param linkText 1520 */ 1521 public static void assertLinkNotPresentWithText(String linkText) { 1522 getTester().assertLinkNotPresentWithText(linkText); 1523 } 1524 1525 /** 1526 * Assert that a link containing the supplied text is present. 1527 * 1528 * @param linkText 1529 * @param index The 0-based index, when more than one link with the same text is expected. 1530 */ 1531 public static void assertLinkPresentWithText(String linkText, int index) { 1532 getTester().assertLinkPresentWithText(linkText, index); 1533 } 1534 1535 /** 1536 * Assert that no link containing the supplied text is present. 1537 * 1538 * @param linkText 1539 * @param index The 0-based index, when more than one link with the same text is expected. 1540 */ 1541 public static void assertLinkNotPresentWithText(String linkText, int index) { 1542 getTester().assertLinkNotPresentWithText(linkText, index); 1543 } 1544 1545 /** 1546 * Assert that a link containing the Exact text is present. 1547 * 1548 * @param linkText 1549 */ 1550 public static void assertLinkPresentWithExactText(String linkText) { 1551 getTester().assertLinkPresentWithExactText(linkText); 1552 } 1553 1554 /** 1555 * Assert that no link containing the Exact text is present. 1556 * 1557 * @param linkText 1558 */ 1559 public static void assertLinkNotPresentWithExactText(String linkText) { 1560 getTester().assertLinkNotPresentWithExactText(linkText); 1561 } 1562 1563 /** 1564 * Assert that a link containing the Exact text is present. 1565 * 1566 * @param linkText 1567 * @param index The 0-based index, when more than one link with the same text is expected. 1568 */ 1569 public static void assertLinkPresentWithExactText(String linkText, int index) { 1570 getTester().assertLinkPresentWithExactText(linkText, index); 1571 } 1572 1573 /** 1574 * Assert that no link containing the Exact text is present. 1575 * 1576 * @param linkText 1577 * @param index The 0-based index, when more than one link with the same text is expected. 1578 */ 1579 public static void assertLinkNotPresentWithExactText(String linkText, int index) { 1580 getTester().assertLinkNotPresentWithExactText(linkText, index); 1581 } 1582 1583 /** 1584 * Assert that a link containing a specified image is present. 1585 * 1586 * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, 1587 * you could just pass in <tt>"my_icon.png"</tt>. 1588 */ 1589 public static void assertLinkPresentWithImage(String imageFileName) { 1590 getTester().assertLinkPresentWithImage(imageFileName); 1591 } 1592 1593 /** 1594 * Assert that a link containing a specified image is present. 1595 * 1596 * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, 1597 * you could just pass in <tt>"my_icon.png"</tt>. 1598 * @param index The 0-based index, when more than one link with the same image is expected. 1599 */ 1600 public static void assertLinkPresentWithImage(String imageFileName, int index) { 1601 getTester().assertLinkPresentWithImage(imageFileName, index); 1602 } 1603 1604 /** 1605 * Assert that a link containing a specified image is not present. 1606 * 1607 * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, 1608 * you could just pass in <tt>"my_icon.png"</tt>. 1609 */ 1610 public static void assertLinkNotPresentWithImage(String imageFileName) { 1611 getTester().assertLinkNotPresentWithImage(imageFileName); 1612 } 1613 1614 /** 1615 * Assert that a link containing a specified image is not present. 1616 * 1617 * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, 1618 * you could just pass in <tt>"my_icon.png"</tt>. 1619 * @param index The 0-based index, when more than one link with the same image is expected. 1620 */ 1621 public static void assertLinkNotPresentWithImage(String imageFileName, int index) { 1622 getTester().assertLinkNotPresentWithImage(imageFileName, index); 1623 } 1624 1625 /** 1626 * Assert that an element with a given id is present. 1627 * 1628 * @param anID element id to test for. 1629 */ 1630 public static void assertElementPresent(String anID) { 1631 getTester().assertElementPresent(anID); 1632 } 1633 1634 /** 1635 * Assert that an element with a given id is not present. 1636 * 1637 * @param anID element id to test for. 1638 */ 1639 public static void assertElementNotPresent(String anID) { 1640 getTester().assertElementNotPresent(anID); 1641 } 1642 1643 /** 1644 * Assert that an element with a given xpath is present. 1645 * 1646 * @param xpath element xpath to test for. 1647 */ 1648 public static void assertElementPresentByXPath(String xpath) { 1649 getTester().assertElementPresentByXPath(xpath); 1650 } 1651 1652 /** 1653 * Assert that an element with a given xpath is not present. 1654 * 1655 * @param xpath element xpath to test for. 1656 */ 1657 public static void assertElementNotPresentByXPath(String xpath) { 1658 getTester().assertElementNotPresentByXPath(xpath); 1659 } 1660 1661 /** 1662 * Get all the comments in a document, as a list of strings. 1663 */ 1664 public static List<String> getComments() { 1665 return getTester().getComments(); 1666 } 1667 1668 /** 1669 * Assert that a comment is present. 1670 * 1671 * @param comment 1672 */ 1673 public static void assertCommentPresent(String comment) { 1674 getTester().assertCommentPresent(comment); 1675 } 1676 1677 /** 1678 * Assert that a comment is not present. 1679 * 1680 * @param comment 1681 */ 1682 public static void assertCommentNotPresent(String comment) { 1683 getTester().assertCommentNotPresent(comment); 1684 } 1685 1686 /** 1687 * Assert that a given element contains specific text. 1688 * 1689 * @param elementID id of element to be inspected. 1690 * @param text to check for. 1691 */ 1692 public static void assertTextInElement(String elementID, String text) { 1693 getTester().assertTextInElement(elementID, text); 1694 } 1695 1696 1697 public static void assertTextNotInElement(String elementID, String text) { 1698 getTester().assertTextNotInElement(elementID, text); 1699 } 1700 1701 /** 1702 * Assert that a given element matches a specific regexp. 1703 * 1704 * @param elementID id of element to be inspected. 1705 * @param regexp to match. 1706 */ 1707 public static void assertMatchInElement(String elementID, String regexp) { 1708 getTester().assertMatchInElement(elementID, regexp); 1709 } 1710 1711 /** 1712 * Assert that a given element does not match a specific regexp. 1713 * 1714 * @param elementID id of element to be inspected. 1715 * @param regexp to match. 1716 */ 1717 public static void assertNoMatchInElement(String elementID, String regexp) { 1718 getTester().assertNoMatchInElement(elementID, regexp); 1719 } 1720 1721 /** 1722 * Assert that a window with the given name is open. 1723 * 1724 * @param windowName 1725 */ 1726 public static void assertWindowPresent(String windowName) { 1727 getTester().assertWindowPresent(windowName); 1728 } 1729 1730 /** 1731 * Assert that a window with the given ID is open. 1732 * 1733 * @param windowID Javascript window ID. 1734 */ 1735 public static void assertWindowPresent(int windowID) { 1736 getTester().assertWindowPresent(windowID); 1737 } 1738 1739 /** 1740 * Assert that at least one window with the given title is open. 1741 * 1742 * @param title 1743 */ 1744 public static void assertWindowPresentWithTitle(String title) { 1745 getTester().assertWindowPresentWithTitle(title); 1746 } 1747 1748 /** 1749 * Assert that the number of opened windows equals given value. 1750 * 1751 * @param windowCount Window count 1752 */ 1753 public static void assertWindowCountEquals(int windowCount) { 1754 getTester().assertWindowCountEquals(windowCount); 1755 } 1756 1757 /** 1758 * Assert that a frame with the given name or ID is present. 1759 * 1760 * @param frameNameOrId Name or ID of the frame. ID is checked first. 1761 */ 1762 public static void assertFramePresent(String frameNameOrId) { 1763 getTester().assertFramePresent(frameNameOrId); 1764 } 1765 1766 /** 1767 * Checks to see if a cookie is present in the response. 1768 * 1769 * @param cookieName The cookie name 1770 */ 1771 public static void assertCookiePresent(String cookieName) { 1772 getTester().assertCookiePresent(cookieName); 1773 } 1774 1775 /** 1776 * Check to see if a cookie has the given value. 1777 * 1778 * @param cookieName The cookie name 1779 * @param expectedValue The cookie value 1780 */ 1781 public static void assertCookieValueEquals(String cookieName, String expectedValue) { 1782 getTester().assertCookieValueEquals(cookieName, expectedValue); 1783 } 1784 1785 /** 1786 * Check to see if a cookie value match the given regexp. 1787 * 1788 * @param cookieName The cookie name 1789 * @param regexp The regexp 1790 */ 1791 public static void assertCookieValueMatch(String cookieName, String regexp) { 1792 getTester().assertCookieValueMatch(cookieName, regexp); 1793 } 1794 1795 /** 1796 * @deprecated Use {@link WebTester#getElementAttributeByXPath(String, String)} 1797 */ 1798 public static String getFormElementValue(String formElementName) { 1799 return getTester().getFormElementValue(formElementName); 1800 } 1801 1802 /** 1803 * Begin interaction with a specified form. If form interaction methods are called without explicitly calling this 1804 * method first, JWebUnit will attempt to determine itself which form is being manipulated. 1805 * 1806 * It is not necessary to call this method if their is only one form on the current page. 1807 * 1808 * @param index 0-based index of the form to work with. 1809 */ 1810 public static void setWorkingForm(int index) { 1811 getTester().setWorkingForm(index); 1812 } 1813 1814 /** 1815 * Begin interaction with a specified form. If form interaction methods are called without explicitly calling this 1816 * method first, JWebUnit will attempt to determine itself which form is being manipulated. 1817 * 1818 * It is not necessary to call this method if their is only one form on the current page. 1819 * 1820 * @param nameOrId name or id of the form to work with. 1821 */ 1822 public static void setWorkingForm(String nameOrId) { 1823 getTester().setWorkingForm(nameOrId); 1824 } 1825 1826 /** 1827 * Begin interaction with a specified form. If form interaction methods are called without explicitly calling this 1828 * method first, JWebUnit will attempt to determine itself which form is being manipulated. 1829 * 1830 * It is not necessary to call this method if their is only one form on the current page. 1831 * 1832 * @param nameOrId name or id of the form to work with. 1833 * @param index The 0-based index, when more than one form with the same name is expected. 1834 */ 1835 public static void setWorkingForm(String nameOrId, int index) { 1836 getTester().setWorkingForm(nameOrId, index); 1837 } 1838 1839 /** 1840 * Set the value of a text or password input field. 1841 * 1842 * @param inputName name of form element. 1843 * @param value value to set. 1844 */ 1845 public static void setTextField(String inputName, String value) { 1846 getTester().setTextField(inputName, value); 1847 } 1848 1849 /** 1850 * Set the value of an hidden input field. 1851 * 1852 * @param inputName name of form element. 1853 * @param value value to set. 1854 */ 1855 public static void setHiddenField(String inputName, String value) { 1856 getTester().setHiddenField(inputName, value); 1857 } 1858 1859 /** 1860 * Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked. 1861 * 1862 * @param checkBoxName name of checkbox to be selected. 1863 */ 1864 public static void checkCheckbox(String checkBoxName) { 1865 getTester().checkCheckbox(checkBoxName); 1866 } 1867 1868 /** 1869 * Select a specified checkbox. If the checkbox is already checked then the checkbox will stay checked. 1870 * 1871 * @param checkBoxName name of checkbox to be selected. 1872 * @param value value of checkbox to be selected. 1873 */ 1874 public static void checkCheckbox(String checkBoxName, String value) { 1875 getTester().checkCheckbox(checkBoxName, value); 1876 } 1877 1878 /** 1879 * Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked. 1880 * 1881 * @param checkBoxName name of checkbox to be deselected. 1882 */ 1883 public static void uncheckCheckbox(String checkBoxName) { 1884 getTester().uncheckCheckbox(checkBoxName); 1885 } 1886 1887 /** 1888 * Deselect a specified checkbox. If the checkbox is already unchecked then the checkbox will stay unchecked. 1889 * 1890 * @param checkBoxName name of checkbox to be deselected. 1891 * @param value value of checkbox to be deselected. 1892 */ 1893 public static void uncheckCheckbox(String checkBoxName, String value) { 1894 getTester().uncheckCheckbox(checkBoxName, value); 1895 } 1896 1897 /** 1898 * Select options with given display labels in a select element. 1899 * 1900 * @param selectName name of select element. 1901 * @param labels labels of options to be selected. 1902 */ 1903 public static void selectOptions(String selectName, String[] labels) { 1904 getTester().selectOptions(selectName, labels); 1905 } 1906 1907 /** 1908 * Select an option with a given display label in a select element. 1909 * 1910 * @param selectName name of select element. 1911 * @param label label of option to be selected. 1912 */ 1913 public static void selectOption(String selectName, String label) { 1914 getTester().selectOption(selectName, label); 1915 } 1916 1917 /** 1918 * Select an option with a given display label in Nth select element. 1919 * 1920 * @param selectName name of select element. 1921 * @param index the 0-based index of the select element when multiple 1922 * select elements are expected. 1923 * @param label label of option to be selected. 1924 */ 1925 public static void selectOption(String selectName, int index, String label) { 1926 getTester().selectOption(selectName, index, label); 1927 } 1928 1929 /** 1930 * Select options with given display labels in the Nth select element. 1931 * 1932 * @param selectName name of select element. 1933 * @param index the 0-based index of the select element when multiple 1934 * select elements are expected. 1935 * @param labels labels of options to be selected. 1936 */ 1937 public static void selectOptions(String selectName, int index, String[] labels) { 1938 getTester().selectOptions(selectName, index, labels); 1939 } 1940 1941 /** 1942 * Select options with given values in a select element. 1943 * 1944 * @param selectName name of select element. 1945 * @param values values of options to be selected. 1946 */ 1947 public static void selectOptionsByValues(String selectName, String[] values) { 1948 getTester().selectOptionsByValues(selectName, values); 1949 } 1950 1951 /** 1952 * Select an option with a given value in the Nth select element. 1953 * 1954 * @param selectName name of select element. 1955 * @param index the 0-based index of the select element when multiple 1956 * select elements are expected. 1957 * @param values values of options to be selected. 1958 */ 1959 public static void selectOptionByValue(String selectName, String value) { 1960 getTester().selectOptionByValue(selectName, value); 1961 } 1962 1963 /** 1964 * Select options with given values in the Nth select element. 1965 * 1966 * @param selectName name of select element. 1967 * @param index the 0-based index of the select element when multiple 1968 * select elements are expected. 1969 * @param values values of options to be selected. 1970 */ 1971 public static void selectOptionsByValues(String selectName, int index, String[] values) { 1972 getTester().selectOptionsByValues(selectName, index, values); 1973 } 1974 1975 /** 1976 * Select an option with a given value in a select element. 1977 * 1978 * @param selectName name of select element. 1979 * @param values values of options to be selected. 1980 */ 1981 public static void selectOptionByValue(String selectName, int index, String value) { 1982 getTester().selectOptionByValue(selectName, index, value); 1983 } 1984 1985 /** 1986 * Submit form - default submit button will be used (unnamed submit button, or named button if there is only one on 1987 * the form. 1988 */ 1989 public static void submit() { 1990 getTester().submit(); 1991 } 1992 1993 /** 1994 * Submit form by pressing named button. 1995 * 1996 * @param buttonName Submit button name attribut value. 1997 */ 1998 public static void submit(String buttonName) { 1999 getTester().submit(buttonName); 2000 } 2001 2002 /** 2003 * Submit the form by pressing the named button with the given value (label). Useful if you have more than one 2004 * submit button with same name. 2005 * 2006 * @param buttonName Submit button name attribut value. 2007 * @param buttonValue Submit button value attribut value. 2008 */ 2009 public static void submit(String buttonName, String buttonValue) { 2010 getTester().submit(buttonName, buttonValue); 2011 } 2012 2013 /** 2014 * Reset the current form using the default reset button. See {@link #getForm}for an explanation of how the current 2015 * form is established. 2016 */ 2017 public static void reset() { 2018 getTester().reset(); 2019 } 2020 2021 /** 2022 * Navigate by selection of a link containing given text. 2023 * 2024 * @param linkText Text in the link. 2025 */ 2026 public static void clickLinkWithText(String linkText) { 2027 getTester().clickLinkWithText(linkText); 2028 } 2029 2030 /** 2031 * Navigate by selecting Nth link containing given text. 2032 * 2033 * @param linkText Text in the link. 2034 * @param index The 0-based index, when more than one link with the same text is expected. 2035 */ 2036 public static void clickLinkWithText(String linkText, int index) { 2037 getTester().clickLinkWithText(linkText, index); 2038 } 2039 2040 /** 2041 * Navigate by selection of a link with the exact given text. 2042 * 2043 * @param linkText Text of the link. 2044 */ 2045 public static void clickLinkWithExactText(String linkText) { 2046 getTester().clickLinkWithExactText(linkText); 2047 } 2048 2049 /** 2050 * Navigate by selecting Nth link with the exact given text. 2051 * 2052 * @param linkText Text of the link. 2053 * @param index The 0-based index, when more than one link with the same text is expected. 2054 */ 2055 public static void clickLinkWithExactText(String linkText, int index) { 2056 getTester().clickLinkWithExactText(linkText, index); 2057 } 2058 2059 /** 2060 * Click the button with the given id. 2061 * 2062 * @param buttonId Button ID attribut value. 2063 */ 2064 public static void clickButton(String buttonId) { 2065 getTester().clickButton(buttonId); 2066 } 2067 2068 /** 2069 * Clicks a button with <code>text</code> of the value attribute. 2070 * 2071 * @param buttonValueText The text of the button (contents of the value attribute). 2072 */ 2073 public static void clickButtonWithText(String buttonValueText) { 2074 getTester().clickButtonWithText(buttonValueText); 2075 } 2076 2077 /** 2078 * Navigate by selection of a link with a given image. 2079 * 2080 * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, 2081 * you could just pass in <tt>"my_icon.png"</tt>. 2082 */ 2083 public static void clickLinkWithImage(String imageFileName) { 2084 getTester().clickLinkWithImage(imageFileName); 2085 } 2086 2087 /** 2088 * Navigate by selection of a link with a given image. 2089 * 2090 * @param imageFileName A suffix of the image's filename; for example, to match <tt>"images/my_icon.png"</tt>, 2091 * you could just pass in <tt>"my_icon.png"</tt>. 2092 * @param index The 0-based index, when more than one link with the same image is expected. 2093 */ 2094 public static void clickLinkWithImage(String imageFileName, int index) { 2095 getTester().clickLinkWithImage(imageFileName, index); 2096 } 2097 2098 /** 2099 * Navigate by selection of a link with given id. 2100 * 2101 * @param linkId id of link 2102 */ 2103 public static void clickLink(String linkId) { 2104 getTester().clickLink(linkId); 2105 } 2106 2107 /** 2108 * Clicks a radio option. Asserts that the radio option exists first. * 2109 * 2110 * @param radioGroup name of the radio group. 2111 * @param radioOption value of the option to check for. 2112 */ 2113 public static void clickRadioOption(String radioGroup, String radioOption) { 2114 getTester().clickRadioOption(radioGroup, radioOption); 2115 } 2116 2117 /** 2118 * Click element with given xpath. 2119 * 2120 * @param xpath xpath of the element. 2121 */ 2122 public static void clickElementByXPath(String xpath) { 2123 getTester().clickElementByXPath(xpath); 2124 } 2125 2126 /** 2127 * Get the attribute value of the given element. 2128 * For example, if you have an element <code><img src="test.gif" alt="picture"></code> 2129 * getElementAttributeByXPath("//img[@src='test.gif']", "alt") returns "picture". 2130 * 2131 * @param xpath XPath of the element 2132 * @param attribute Name of the attribute 2133 * @return The value of the attribute 2134 */ 2135 public static String getElementAttributeByXPath(String xpath, String attribute) { 2136 return getTester().getElementAttributeByXPath(xpath, attribute); 2137 } 2138 2139 /** 2140 * @deprecated Use {@link #getElementAttributeByXPath(String, String)} 2141 */ 2142 public static String getElementAttributByXPath(String xpath, String attribute) { 2143 return getTester().getElementAttributByXPath(xpath, attribute); 2144 } 2145 2146 /** 2147 * Get text of the given element. 2148 * 2149 * @param xpath xpath of the element. 2150 */ 2151 public static String getElementTextByXPath(String xpath) { 2152 return getTester().getElementTextByXPath(xpath); 2153 } 2154 2155 /** 2156 * Get an element for a particular xpath. 2157 * 2158 * @param xpath XPath to search 2159 * @return the requested element 2160 * @throws AssertionError if the element xpath is not found 2161 */ 2162 public static IElement getElementByXPath(String xpath) { 2163 return getTester().getElementByXPath(xpath); 2164 } 2165 2166 /** 2167 * Return {@code true} if the given element by XPath exists. 2168 * 2169 * @param xpath XPath to search 2170 * @return {@code true} if the the requested element 2171 * @throws AssertionError if the element xpath is not found 2172 */ 2173 public static boolean hasElementByXPath(String xpath) { 2174 return getTester().hasElementByXPath(xpath); 2175 } 2176 2177 /** 2178 * Get an element for a particular ID. 2179 * 2180 * @param id element ID to find 2181 * @return the requested element 2182 * @throws AssertionError if the element is not found 2183 */ 2184 public static IElement getElementById(String id) { 2185 return getTester().getElementById(id); 2186 } 2187 2188 /** 2189 * Returns {@code true} if an element with the given ID exists. 2190 * 2191 * @param id element ID to find 2192 * @return {@code true} if the element ID exists, {@code false} otherwise 2193 */ 2194 public static boolean hasElementById(String id) { 2195 return getTester().hasElementById(id); 2196 } 2197 2198 /** 2199 * Get elements for a particular xpath. 2200 * 2201 * @param xpath XPath to search 2202 * @return the requested elements found 2203 */ 2204 public static List<IElement> getElementsByXPath(String xpath) { 2205 return getTester().getElementsByXPath(xpath); 2206 } 2207 2208 /** 2209 * Return {@code true} if the given elements by XPath exists. 2210 * 2211 * @param xpath XPath to search 2212 * @return {@code true} if the given elements by XPath exist 2213 */ 2214 public static boolean hasElementsByXPath(String xpath) { 2215 return getTester().hasElementsByXPath(xpath); 2216 } 2217 2218 /** 2219 * Assert a label for a given ID exists. 2220 */ 2221 public static void assertLabelPresent(String id) { 2222 getTester().assertLabelPresent(id); 2223 } 2224 2225 /** 2226 * Assert a label exists. 2227 */ 2228 public static void assertLabelMatches(String regexp) { 2229 getTester().assertLabelMatches(regexp); 2230 } 2231 2232 /** 2233 * Get all the fields of type <code>input</code>, <code>textarea</code> or <code>select</code> 2234 * that are referenced or contained in a particular label. 2235 * 2236 * @param label The label to consider 2237 * @return A list of all fields contained or referenced in this label 2238 */ 2239 public static List<IElement> getFieldsForLabel(IElement label) { 2240 return getTester().getFieldsForLabel(label); 2241 } 2242 2243 /** 2244 * Get the current value of a given labelled field. 2245 * 2246 * @param identifier the HTML ID for the given labelled field 2247 * @param label the label found for the given HTML ID 2248 * @return the value found in a field for the given label/ID, or 2249 * <code>null</code> if none was found 2250 */ 2251 public static String getLabeledFieldValue(String identifier, IElement label) { 2252 return getTester().getLabeledFieldValue(identifier, label); 2253 } 2254 2255 /** 2256 * Assert that a labeled field exists (for the given ID) and the 2257 * field that it labels equals the given text 2258 * 2259 * @param id the HTML ID for the given labelled field 2260 * @param fieldText the text that the field's value should equal 2261 * @see #getLabeledFieldValue(String, IElement, String) 2262 * @see #getLabel(String) 2263 */ 2264 public static void assertLabeledFieldEquals(String id, String fieldText) { 2265 getTester().assertLabeledFieldEquals(id, fieldText); 2266 } 2267 2268 2269 public static void setLabeledFormElementField(String id, String value) { 2270 getTester().setLabeledFormElementField(id, value); 2271 } 2272 2273 /** 2274 * Make a given window active. 2275 * 2276 * @param windowName Name of the window. 2277 */ 2278 public static void gotoWindow(String windowName) { 2279 getTester().gotoWindow(windowName); 2280 } 2281 2282 /** 2283 * Make a given window active. 2284 * 2285 * @param windowID Javascript ID of the window 2286 * @deprecated Javascript ID does'nt not exists. Currently this is an index 2287 * in the list of available windows, but this is not portable (and probably not stable). 2288 * Use {@link #gotoWindow(String)} or {@link #gotoWindowByTitle(String)} instead. 2289 */ 2290 @Deprecated 2291 public static void gotoWindow(int windowID) { 2292 getTester().gotoWindow(windowID); 2293 } 2294 2295 /** 2296 * Make the root window active. Used to reset the effect of {@link ITestingEngine#gotoFrame(String)}. 2297 */ 2298 public static void gotoRootWindow() { 2299 getTester().gotoRootWindow(); 2300 } 2301 2302 /** 2303 * Make first window with the given title active. 2304 * 2305 * @param title Title of the window. 2306 */ 2307 public static void gotoWindowByTitle(String title) { 2308 getTester().gotoWindowByTitle(title); 2309 } 2310 2311 /** 2312 * Make the given frame active. 2313 * 2314 * @param frameNameOrId Name or ID of the frame. ID is checked first. 2315 */ 2316 public static void gotoFrame(String frameNameOrId) { 2317 getTester().gotoFrame(frameNameOrId); 2318 } 2319 2320 /** 2321 * Go to the given page like if user has typed the URL manually in the browser. Use 2322 * {@link TestContext#setBaseUrl(String) getTestContext().setBaseUrl(String)} to define base URL. Absolute URL 2323 * should start with "http://", "https://" or "www.". 2324 * 2325 * @param url absolute or relative URL (relative to base URL). 2326 * @throws TestingEngineResponseException If something bad happend (404) 2327 */ 2328 public static void gotoPage(String url)throws TestingEngineResponseException { 2329 getTester().gotoPage(url); 2330 } 2331 2332 /** 2333 * Print all the cookies to stdout. 2334 * 2335 */ 2336 public static void dumpCookies() { 2337 getTester().dumpCookies(); 2338 } 2339 2340 /** 2341 * Get the source of the HTML page (like in a real browser), or HTTP body for a non HTML content. 2342 * 2343 * @return The HTML content. 2344 */ 2345 public static String getPageSource() { 2346 return getTester().getPageSource(); 2347 } 2348 2349 /** 2350 * Get the last data sent by the server. 2351 * 2352 * @return HTTP server response. 2353 */ 2354 public static String getServerResponse() { 2355 return getTester().getServerResponse(); 2356 } 2357 2358 /** 2359 * @deprecated use {@link #getServerResponse()} 2360 * @return 2361 */ 2362 public static String getServeurResponse() { 2363 return getTester().getServeurResponse(); 2364 } 2365 2366 /** 2367 * Save the last downloaded page (or file) to the disk. 2368 * 2369 * @param f The file name. 2370 */ 2371 public static void saveAs(File f) { 2372 getTester().saveAs(f); 2373 } 2374 2375 /** 2376 * Download the current page (or file) and compare it with the given file. 2377 * 2378 * @param expected Expected file URL. 2379 */ 2380 public static void assertDownloadedFileEquals(URL expected) { 2381 getTester().assertDownloadedFileEquals(expected); 2382 } 2383 2384 /** 2385 * Dump html of current response to System.out - for debugging purposes. 2386 * 2387 * @param stream 2388 * @deprecated Use {@link WebTester#getPageSource()} 2389 */ 2390 public static void dumpHtml() { 2391 getTester().dumpHtml(); 2392 } 2393 2394 /** 2395 * Dump html of current response to a specified stream - for debugging purposes. 2396 * 2397 * @param stream 2398 * @deprecated Use {@link WebTester#getPageSource()} 2399 */ 2400 public static void dumpHtml(PrintStream stream) { 2401 getTester().dumpHtml(stream); 2402 } 2403 2404 /** 2405 * Dump the table as the 2D array that is used for assertions - for debugging purposes. 2406 * 2407 * @param tableNameOrId 2408 * @param stream 2409 */ 2410 public static void dumpTable(String tableNameOrId) { 2411 getTester().dumpTable(tableNameOrId); 2412 } 2413 2414 /** 2415 * Dump the table as the 2D array that is used for assertions - for debugging purposes. 2416 * 2417 * @param tableNameOrId 2418 * @param table 2419 * @param stream 2420 */ 2421 public static void dumpTable(String tableNameOrId, PrintStream stream) { 2422 getTester().dumpTable(tableNameOrId, stream); 2423 } 2424 2425 /** 2426 * Enable or disable Javascript support 2427 */ 2428 public static void setScriptingEnabled(boolean value) { 2429 getTester().setScriptingEnabled(value); 2430 } 2431 2432 /** 2433 * Set the Testing Engine that you want to use for the tests based on the Testing Engine Key. 2434 * 2435 * @see TestingEngineRegistry 2436 * @param testingEngineKey The testingEngineKey to set. 2437 */ 2438 public static void setTestingEngineKey(String testingEngineKey) { 2439 getTester().setTestingEngineKey(testingEngineKey); 2440 } 2441 2442 /** 2443 * Gets the Testing Engine Key that is used to find the proper testing engine class (HtmlUnitDialog / 2444 * SeleniumDialog) for the tests. 2445 * 2446 * @return Returns the testingEngineKey. 2447 */ 2448 public static String getTestingEngineKey() { 2449 return getTester().getTestingEngineKey(); 2450 } 2451 2452 /** 2453 * Set the value of a form input element. 2454 * 2455 * @param formElementName name of form element. 2456 * @param value 2457 * @see #setTextField(String, String) 2458 * @deprecated use {@link #setTextField(String, String)} or other methods 2459 */ 2460 public static void setFormElement(String formElementName, String value) { 2461 getTester().setFormElement(formElementName, value); 2462 } 2463 2464 /** 2465 * Tell that the given alert box is expected. 2466 * 2467 * @param message Message in the alert. 2468 */ 2469 public static void setExpectedJavaScriptAlert(String message) { 2470 getTester().setExpectedJavaScriptAlert(message); 2471 } 2472 2473 /** 2474 * Tell that the given alert boxes are expected in the given order. 2475 * 2476 * @param messages Messages in the alerts. 2477 */ 2478 public static void setExpectedJavaScriptAlert(String[] messages) { 2479 getTester().setExpectedJavaScriptAlert(messages); 2480 } 2481 2482 /** 2483 * Tell that the given confirm boxe is expected. 2484 * 2485 * @param message Message in the confirm. 2486 * @param action Whether we should click on "OK" (true) or "Cancel" (false) 2487 */ 2488 public static void setExpectedJavaScriptConfirm(String message, boolean action) { 2489 getTester().setExpectedJavaScriptConfirm(message, action); 2490 } 2491 2492 /** 2493 * Tell that the given confirm boxes are expected in the given order. 2494 * 2495 * @param messages Messages in the confirms. 2496 * @param actions Whether we should click on "OK" (true) or "Cancel" (false) 2497 */ 2498 public static void setExpectedJavaScriptConfirm(String[] messages, boolean[] actions) { 2499 getTester().setExpectedJavaScriptConfirm(messages, actions); 2500 } 2501 2502 /** 2503 * Tell that the given prompt boxe is expected. 2504 * 2505 * @param message Message in the prompt. 2506 * @param input What we should put in the prompt (null if user press Cancel) 2507 */ 2508 public static void setExpectedJavaScriptPrompt(String message, String input) { 2509 getTester().setExpectedJavaScriptPrompt(message, input); 2510 } 2511 2512 /** 2513 * Tell that the given prompt boxes are expected in the given order. 2514 * 2515 * @param messages Messages in the prompts. 2516 * @param inputs What we should put in the prompt (null if user press Cancel) 2517 */ 2518 public static void setExpectedJavaScriptPrompt(String[] messages, String[] inputs) { 2519 getTester().setExpectedJavaScriptPrompt(messages, inputs); 2520 } 2521 2522 /** 2523 * Assert there is at least one image in the page with given src and (optional) alt attributes. 2524 * @param imageSrc Value of image src attribute. 2525 * @param imageAlt Value of image alt attribute. Ignored when null. 2526 */ 2527 public static void assertImagePresent(String imageSrc, String imageAlt) { 2528 getTester().assertImagePresent(imageSrc, imageAlt); 2529 } 2530 2531 /** 2532 * Assert there is at least one image in the page with given partial src and (optional) partial alt attributes. 2533 * @param partialImageSrc 2534 * @param partialImageAlt 2535 */ 2536 public static void assertImagePresentPartial(String partialImageSrc, String partialImageAlt) { 2537 getTester().assertImagePresentPartial(partialImageSrc, partialImageAlt); 2538 } 2539 2540 /** 2541 * @see #assertImageValidAndStore(String, String, java.io.File) 2542 */ 2543 public static void assertImageValid(String imageSrc, String imageAlt) { 2544 getTester().assertImageValid(imageSrc, imageAlt); 2545 } 2546 2547 /** 2548 * Asserts that the image with the given src and alt attribute values exist in the page and is an actual reachable 2549 * image, then saves it as png with the given file name. 2550 * 2551 * @param imageSrc as it appears in the html page, i.e. relative to the current page. 2552 */ 2553 public static void assertImageValidAndStore(String imageSrc, String imageAlt, File out) { 2554 getTester().assertImageValidAndStore(imageSrc, imageAlt, out); 2555 } 2556 2557 /** 2558 * @see #assertImageValidAndStore(String, String, java.io.File) 2559 */ 2560 public static Image getImage(String imageSrc, String imageAlt) { 2561 return getTester().getImage(imageSrc, imageAlt); 2562 } 2563 2564 /** 2565 * Set the timeout for the request. A timeout of 0 means 2566 * an infinite timeout. 2567 * 2568 * @param milli the milliseconds in which to timeout, or 0 for infinite 2569 * wait (the default). 2570 */ 2571 public static void setTimeout(int milli) { 2572 getTester().setTimeout(milli); 2573 } 2574 2575 }