Commit df1009e1 df1009e1b0202566614269040784e3a528d95651 by Nicolas Perriault

Merge branch 'master' into tester-refactor

2 parents 236aba1c 3aa64e34
......@@ -6,6 +6,8 @@ XXXX-XX-XX, v0.6.9
- fixed [#114](https://github.com/n1k0/casperjs/issues/114) - ensured client-side utils are injected before any `evaluate()` call
- fixed [#117](https://github.com/n1k0/casperjs/issues/117) - `fill()` coulnd't `submit()` a form with a submit input named *submit*
- merged [#122](https://github.com/n1k0/casperjs/pull/122) - allow downloads to be triggered by more than just `GET` requests
- fixed loaded resources array is now reset adequately [reference discussion](https://groups.google.com/forum/?hl=fr?fromgroups#!topic/casperjs/TCkNzrj1IoA)
2012-05-20, v0.6.8
------------------
......
Subproject commit c5b5de3e85582ebfe2d2051cd8dbfc5cf67c885a
Subproject commit b9192a22522dcd8aac843ba769caf384ac00277e
......
......@@ -350,10 +350,10 @@ Casper.prototype.die = function die(message, status) {
* @param String targetPath The destination file path
* @return Casper
*/
Casper.prototype.download = function download(url, targetPath) {
Casper.prototype.download = function download(url, targetPath, method, data) {
var cu = require('clientutils').create();
try {
fs.write(targetPath, cu.decode(this.base64encode(url)), 'w');
fs.write(targetPath, cu.decode(this.base64encode(url, method, data)), 'w');
this.emit('downloaded.file', targetPath);
this.log(f("Downloaded and saved resource in %s", targetPath));
} catch (e) {
......@@ -746,6 +746,7 @@ Casper.prototype.open = function open(location, settings) {
operation: settings.method,
data: settings.data
}, this.page.settings);
this.resources = [];
return this;
};
......@@ -775,17 +776,18 @@ Casper.prototype.resourceExists = function resourceExists(test) {
var testFn;
switch (utils.betterTypeOf(test)) {
case "string":
testFn = function _test(res) {
testFn = function _testResourceExists_String(res) {
return res.url.search(test) !== -1;
};
break;
case "regexp":
testFn = function _test(res) {
testFn = function _testResourceExists_Regexp(res) {
return test.test(res.url);
};
break;
case "function":
testFn = test;
testFn.name = "_testResourceExists_Function";
break;
default:
throw new CasperError("Invalid type");
......@@ -1299,7 +1301,6 @@ function createPage(casper) {
};
page.onLoadStarted = function onLoadStarted() {
casper.loadInProgress = true;
casper.resources = [];
casper.emit('load.started');
};
page.onLoadFinished = function onLoadFinished(status) {
......
......@@ -546,8 +546,14 @@
*/
this.visible = function visible(selector) {
try {
var el = this.findOne(selector);
return el && el.style.visibility !== 'hidden' && el.offsetHeight > 0 && el.offsetWidth > 0;
var comp,
el = this.findOne(selector);
if (el) {
comp = window.getComputedStyle(el, null);
return comp.visibility !== 'hidden' && comp.display !== 'none' && el.offsetHeight > 0 && el.offsetWidth > 0;
}
return false;
} catch (e) {
return false;
}
......
......@@ -15,7 +15,7 @@ casper = require('casper').create verbose: true
casper.fetchScore = ->
@evaluate ->
result = document.querySelector('#resultStats').innerText
~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''))
parseInt /Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')
terms = casper.cli.args # terms are passed through command-line arguments
......@@ -38,7 +38,7 @@ casper.each terms, (self, term) ->
self.echo "#{term}: #{score}"
casper.run ->
scores.sort -> (a, b) -> b.score - a.score;
winner = scores[0]
winner = x for x in scores when x.score > winner.score
@echo "Winner is #{winner.term} with #{winner.score} results"
@exit()
......
......@@ -16,7 +16,7 @@ var casper = new require('casper').create({
casper.fetchScore = function() {
return this.evaluate(function() {
var result = document.querySelector('#resultStats').innerText;
return ~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''));
return parseInt(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''));
});
};
......@@ -45,10 +45,10 @@ casper.each(terms, function(self, term, i) {
});
casper.run(function(self) {
scores.sort(function(a, b) {
return b.score - a.score;
});
var winner = scores[0];
for (var i = 0, len = scores.length; i < len; i++)
if (scores[i].score > winner.score)
winner = scores[i];
self.echo('winner is "' + winner.term + '" with ' + winner.score + ' results');
self.exit();
});
......