Merge pull request #9 from jean-philippe/master
Added Casper.getGlobal() for retrieving a global variable value.
Showing
3 changed files
with
27 additions
and
1 deletions
... | @@ -491,7 +491,7 @@ | ... | @@ -491,7 +491,7 @@ |
491 | }, | 491 | }, |
492 | 492 | ||
493 | /** | 493 | /** |
494 | * Retrieve current document url. | 494 | * Retrieves current document url. |
495 | * | 495 | * |
496 | * @return String | 496 | * @return String |
497 | */ | 497 | */ |
... | @@ -502,6 +502,18 @@ | ... | @@ -502,6 +502,18 @@ |
502 | }, | 502 | }, |
503 | 503 | ||
504 | /** | 504 | /** |
505 | * Retrieves global variable. | ||
506 | * | ||
507 | * @param String name The name of the global variable to retrieve | ||
508 | * @return mixed | ||
509 | */ | ||
510 | getGlobal: function(name) { | ||
511 | return this.evaluate(function() { | ||
512 | return window[window.__casper_params__.name]; | ||
513 | }, {'name': name}); | ||
514 | }, | ||
515 | |||
516 | /** | ||
505 | * Retrieves current page title, if any. | 517 | * Retrieves current page title, if any. |
506 | * | 518 | * |
507 | * @return String | 519 | * @return String | ... | ... |
... | @@ -207,6 +207,12 @@ casper.then(function() { | ... | @@ -207,6 +207,12 @@ casper.then(function() { |
207 | }); | 207 | }); |
208 | }); | 208 | }); |
209 | 209 | ||
210 | // Casper.getGlobal() | ||
211 | casper.thenOpen('tests/site/global.html', function(self) { | ||
212 | self.test.comment('Casper.getGlobal()'); | ||
213 | self.test.assertEquals(self.getGlobal('myGlobal'), 'awesome string', 'global retrieved') | ||
214 | }); | ||
215 | |||
210 | // History | 216 | // History |
211 | casper | 217 | casper |
212 | .thenOpen('tests/site/page1.html') | 218 | .thenOpen('tests/site/page1.html') | ... | ... |
-
Please register or sign in to post a comment