Commit aaae5f34 aaae5f34a37033896dade42400ed45a273e50e74 by Nicolas Perriault

Merge pull request #9 from jean-philippe/master

Added Casper.getGlobal() for retrieving a global variable value.
2 parents 0cddb57a 02dbc67c
...@@ -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')
......
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script type="text/javascript">
5 var myGlobal = 'awesome string';
6 </script>
7 </body>
8 </html>
...\ No newline at end of file ...\ No newline at end of file