added Casper.thenClick() to add a new step for clicking a link (@marchugon)
Showing
3 changed files
with
26 additions
and
16 deletions
... | @@ -225,21 +225,6 @@ | ... | @@ -225,21 +225,6 @@ |
225 | }, | 225 | }, |
226 | 226 | ||
227 | /** | 227 | /** |
228 | * Adds a new navigation step for clicking on a provided link. | ||
229 | * | ||
230 | * @param String selector A DOM CSS3 compatible selector | ||
231 | * @param function then Next step function to execute on page loaded (optional) | ||
232 | * @return Casper | ||
233 | * @see Casper#open | ||
234 | */ | ||
235 | thenClick: function(selector, fallbackToHref, then) { | ||
236 | this.then(function(self) { | ||
237 | self.click(selector, fallbackToHref); | ||
238 | }); | ||
239 | return typeof then === "function" ? this.then(then) : this; | ||
240 | }, | ||
241 | |||
242 | /** | ||
243 | * Logs the HTML code of the current page. | 228 | * Logs the HTML code of the current page. |
244 | * | 229 | * |
245 | * @return Casper | 230 | * @return Casper |
... | @@ -649,6 +634,24 @@ | ... | @@ -649,6 +634,24 @@ |
649 | }, | 634 | }, |
650 | 635 | ||
651 | /** | 636 | /** |
637 | * Adds a new navigation step for clicking on a provided link selector | ||
638 | * and execute an optional next step. | ||
639 | * | ||
640 | * @param String selector A DOM CSS3 compatible selector | ||
641 | * @param Function then Next step function to execute on page loaded (optional) | ||
642 | * @param Boolean fallbackToHref Whether to try to relocate to the value of any href attribute (default: true) | ||
643 | * @return Casper | ||
644 | * @see Casper#click | ||
645 | * @see Casper#then | ||
646 | */ | ||
647 | thenClick: function(selector, then, fallbackToHref) { | ||
648 | this.then(function(self) { | ||
649 | self.click(selector, fallbackToHref); | ||
650 | }); | ||
651 | return typeof then === "function" ? this.then(then) : this; | ||
652 | }, | ||
653 | |||
654 | /** | ||
652 | * Adds a new navigation step to perform code evaluation within the | 655 | * Adds a new navigation step to perform code evaluation within the |
653 | * current retrieved page DOM. | 656 | * current retrieved page DOM. |
654 | * | 657 | * | ... | ... |
... | @@ -145,6 +145,12 @@ casper.then(function(self) { | ... | @@ -145,6 +145,12 @@ casper.then(function(self) { |
145 | self.test.assertUrlMatch(/topic=bar/, 'fill() select field was submitted'); | 145 | self.test.assertUrlMatch(/topic=bar/, 'fill() select field was submitted'); |
146 | }); | 146 | }); |
147 | 147 | ||
148 | // Casper#thenClick() | ||
149 | casper.thenClick('body a', function(self) { | ||
150 | self.test.comment('Casper.thenClick()'); | ||
151 | self.test.assertTitle('CasperJS test index', 'thenClick() casper can add a step for clicking a link'); | ||
152 | }); | ||
153 | |||
148 | // Casper#each() | 154 | // Casper#each() |
149 | casper.test.comment('each'); | 155 | casper.test.comment('each'); |
150 | casper.each([1, 2, 3], function(self, item, i) { | 156 | casper.each([1, 2, 3], function(self, item, i) { | ... | ... |
... | @@ -5,6 +5,7 @@ | ... | @@ -5,6 +5,7 @@ |
5 | <title>CasperJS test form result</title> | 5 | <title>CasperJS test form result</title> |
6 | </head> | 6 | </head> |
7 | <body> | 7 | <body> |
8 | this is the result page | 8 | <p>this is the result page</p> |
9 | <p><a href="index.html">Return back home</a></p> | ||
9 | </body> | 10 | </body> |
10 | </html> | 11 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment