Commit 02dbc67c 02dbc67cd0538e062986225df82fe029d446a16b by jean-philippe serafin

added Casper.getGlobal()

1 parent 0cddb57a
......@@ -491,7 +491,7 @@
},
/**
* Retrieve current document url.
* Retrieves current document url.
*
* @return String
*/
......@@ -502,6 +502,18 @@
},
/**
* Retrieves global variable.
*
* @param String name The name of the global variable to retrieve
* @return mixed
*/
getGlobal: function(name) {
return this.evaluate(function() {
return window[window.__casper_params__.name];
}, {'name': name});
},
/**
* Retrieves current page title, if any.
*
* @return String
......
......@@ -207,6 +207,12 @@ casper.then(function() {
});
});
// Casper.getGlobal()
casper.thenOpen('tests/site/global.html', function(self) {
self.test.comment('Casper.getGlobal()');
self.test.assertEquals(self.getGlobal('myGlobal'), 'awesome string', 'global retrieved')
});
// History
casper
.thenOpen('tests/site/page1.html')
......
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var myGlobal = 'awesome string';
</script>
</body>
</html>
\ No newline at end of file