AC: Add assertSelectorHasText and assertSelectorDoesntHaveText functions.
Showing
3 changed files
with
47 additions
and
0 deletions
... | @@ -398,6 +398,46 @@ var Tester = function Tester(casper, options) { | ... | @@ -398,6 +398,46 @@ var Tester = function Tester(casper, options) { |
398 | }; | 398 | }; |
399 | 399 | ||
400 | /** | 400 | /** |
401 | * Asserts that given text exists in the provided selector. | ||
402 | * | ||
403 | * @param String selector Selector expression | ||
404 | * @param String text Text to be found | ||
405 | * @param String message Test description | ||
406 | * @return Object An assertion result object | ||
407 | */ | ||
408 | this.assertSelectorHasText = function assertSelectorHasText(selector, text, message) { | ||
409 | var textFound = casper.fetchText(selector).indexOf(text) !== -1; | ||
410 | return this.assert(textFound, message, { | ||
411 | type: "assertTextInSelector", | ||
412 | standard: f('Found %s within the selector %s', this.colorize(text, 'COMMENT'), this.colorize(selector, 'COMMENT')), | ||
413 | values: { | ||
414 | selector: selector, | ||
415 | text: text | ||
416 | } | ||
417 | }); | ||
418 | }; | ||
419 | |||
420 | /** | ||
421 | * Asserts that given text does not exist in the provided selector. | ||
422 | * | ||
423 | * @param String selector Selector expression | ||
424 | * @param String text Text not to be found | ||
425 | * @param String message Test description | ||
426 | * @return Object An assertion result object | ||
427 | */ | ||
428 | this.assertSelectorDoesntHaveText = function assertSelectorDoesntHaveText(selector, text, message) { | ||
429 | var textFound = casper.fetchText(selector).indexOf(text) === -1; | ||
430 | return this.assert(textFound, message, { | ||
431 | type: "assertNoTextInSelector", | ||
432 | standard: f('Did not find %s within the selector %s', this.colorize(text, 'COMMENT'), this.colorize(selector, 'COMMENT')), | ||
433 | values: { | ||
434 | selector: selector, | ||
435 | text: text | ||
436 | } | ||
437 | }); | ||
438 | }; | ||
439 | |||
440 | /** | ||
401 | * Asserts that title of the remote page equals to the expected one. | 441 | * Asserts that title of the remote page equals to the expected one. |
402 | * | 442 | * |
403 | * @param String expected The expected title string | 443 | * @param String expected The expected title string | ... | ... |
... | @@ -50,6 +50,12 @@ casper.thenOpen('tests/site/index.html', function() { | ... | @@ -50,6 +50,12 @@ casper.thenOpen('tests/site/index.html', function() { |
50 | 50 | ||
51 | t.comment('Tester.assertTextExists()'); | 51 | t.comment('Tester.assertTextExists()'); |
52 | t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); | 52 | t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); |
53 | |||
54 | t.comment('Tester.assertSelectorHasText()'); | ||
55 | t.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected'); | ||
56 | |||
57 | t.comment('Tester.assertSelectorDoesntHaveText()'); | ||
58 | t.assertSelectorDoesntHaveText('h1', 'Subtitle', 'Tester.assertSelectorDoesntHaveText() works as expected'); | ||
53 | }); | 59 | }); |
54 | 60 | ||
55 | casper.then(function() { | 61 | casper.then(function() { | ... | ... |
-
Please register or sign in to post a comment