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 @@
},
/**
* 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