Tester.assertUrlMatch() now allows to search for a string
Showing
1 changed file
with
17 additions
and
7 deletions
... | @@ -544,17 +544,27 @@ Tester.prototype.assertType = function assertType(subject, type, message) { | ... | @@ -544,17 +544,27 @@ Tester.prototype.assertType = function assertType(subject, type, message) { |
544 | }; | 544 | }; |
545 | 545 | ||
546 | /** | 546 | /** |
547 | * Asserts that a the current page url matches the provided RegExp | 547 | * Asserts that a the current page url matches a given pattern. A pattern may be |
548 | * pattern. | 548 | * either a RegExp object or a String. The method will test if the URL matches |
549 | * the pattern or contains the String. | ||
549 | * | 550 | * |
550 | * @param RegExp pattern A RegExp object instance | 551 | * @param RegExp|String pattern The test pattern |
551 | * @param String message Test description | 552 | * @param String message Test description |
552 | * @return Object An assertion result object | 553 | * @return Object An assertion result object |
553 | */ | 554 | */ |
554 | Tester.prototype.assertUrlMatch = Tester.prototype.assertUrlMatches = function assertUrlMatch(pattern, message) { | 555 | Tester.prototype.assertUrlMatch = Tester.prototype.assertUrlMatches = function assertUrlMatch(pattern, message) { |
555 | "use strict"; | 556 | "use strict"; |
556 | var currentUrl = this.casper.getCurrentUrl(); | 557 | var currentUrl = this.casper.getCurrentUrl(), |
557 | return this.assert(pattern.test(currentUrl), message, { | 558 | patternType = utils.betterTypeOf(pattern), |
559 | result; | ||
560 | if (patternType === "regexp") { | ||
561 | result = pattern.test(currentUrl); | ||
562 | } else if (patternType === "string") { | ||
563 | result = currentUrl.indexOf(pattern) !== -1; | ||
564 | } else { | ||
565 | throw new CasperError("assertUrlMatch() only accepts strings or regexps"); | ||
566 | } | ||
567 | return this.assert(result, message, { | ||
558 | type: "assertUrlMatch", | 568 | type: "assertUrlMatch", |
559 | standard: "Current url matches the provided pattern", | 569 | standard: "Current url matches the provided pattern", |
560 | values: { | 570 | values: { | ... | ... |
-
Please register or sign in to post a comment