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 ...@@ -6,6 +6,8 @@ XXXX-XX-XX, v0.6.9
6 6
7 - fixed [#114](https://github.com/n1k0/casperjs/issues/114) - ensured client-side utils are injected before any `evaluate()` call 7 - fixed [#114](https://github.com/n1k0/casperjs/issues/114) - ensured client-side utils are injected before any `evaluate()` call
8 - fixed [#117](https://github.com/n1k0/casperjs/issues/117) - `fill()` coulnd't `submit()` a form with a submit input named *submit* 8 - fixed [#117](https://github.com/n1k0/casperjs/issues/117) - `fill()` coulnd't `submit()` a form with a submit input named *submit*
9 - merged [#122](https://github.com/n1k0/casperjs/pull/122) - allow downloads to be triggered by more than just `GET` requests
10 - fixed loaded resources array is now reset adequately [reference discussion](https://groups.google.com/forum/?hl=fr?fromgroups#!topic/casperjs/TCkNzrj1IoA)
9 11
10 2012-05-20, v0.6.8 12 2012-05-20, v0.6.8
11 ------------------ 13 ------------------
......
1 Subproject commit c5b5de3e85582ebfe2d2051cd8dbfc5cf67c885a 1 Subproject commit b9192a22522dcd8aac843ba769caf384ac00277e
......
...@@ -350,10 +350,10 @@ Casper.prototype.die = function die(message, status) { ...@@ -350,10 +350,10 @@ Casper.prototype.die = function die(message, status) {
350 * @param String targetPath The destination file path 350 * @param String targetPath The destination file path
351 * @return Casper 351 * @return Casper
352 */ 352 */
353 Casper.prototype.download = function download(url, targetPath) { 353 Casper.prototype.download = function download(url, targetPath, method, data) {
354 var cu = require('clientutils').create(); 354 var cu = require('clientutils').create();
355 try { 355 try {
356 fs.write(targetPath, cu.decode(this.base64encode(url)), 'w'); 356 fs.write(targetPath, cu.decode(this.base64encode(url, method, data)), 'w');
357 this.emit('downloaded.file', targetPath); 357 this.emit('downloaded.file', targetPath);
358 this.log(f("Downloaded and saved resource in %s", targetPath)); 358 this.log(f("Downloaded and saved resource in %s", targetPath));
359 } catch (e) { 359 } catch (e) {
...@@ -746,6 +746,7 @@ Casper.prototype.open = function open(location, settings) { ...@@ -746,6 +746,7 @@ Casper.prototype.open = function open(location, settings) {
746 operation: settings.method, 746 operation: settings.method,
747 data: settings.data 747 data: settings.data
748 }, this.page.settings); 748 }, this.page.settings);
749 this.resources = [];
749 return this; 750 return this;
750 }; 751 };
751 752
...@@ -775,17 +776,18 @@ Casper.prototype.resourceExists = function resourceExists(test) { ...@@ -775,17 +776,18 @@ Casper.prototype.resourceExists = function resourceExists(test) {
775 var testFn; 776 var testFn;
776 switch (utils.betterTypeOf(test)) { 777 switch (utils.betterTypeOf(test)) {
777 case "string": 778 case "string":
778 testFn = function _test(res) { 779 testFn = function _testResourceExists_String(res) {
779 return res.url.search(test) !== -1; 780 return res.url.search(test) !== -1;
780 }; 781 };
781 break; 782 break;
782 case "regexp": 783 case "regexp":
783 testFn = function _test(res) { 784 testFn = function _testResourceExists_Regexp(res) {
784 return test.test(res.url); 785 return test.test(res.url);
785 }; 786 };
786 break; 787 break;
787 case "function": 788 case "function":
788 testFn = test; 789 testFn = test;
790 testFn.name = "_testResourceExists_Function";
789 break; 791 break;
790 default: 792 default:
791 throw new CasperError("Invalid type"); 793 throw new CasperError("Invalid type");
...@@ -1299,7 +1301,6 @@ function createPage(casper) { ...@@ -1299,7 +1301,6 @@ function createPage(casper) {
1299 }; 1301 };
1300 page.onLoadStarted = function onLoadStarted() { 1302 page.onLoadStarted = function onLoadStarted() {
1301 casper.loadInProgress = true; 1303 casper.loadInProgress = true;
1302 casper.resources = [];
1303 casper.emit('load.started'); 1304 casper.emit('load.started');
1304 }; 1305 };
1305 page.onLoadFinished = function onLoadFinished(status) { 1306 page.onLoadFinished = function onLoadFinished(status) {
......
...@@ -546,8 +546,14 @@ ...@@ -546,8 +546,14 @@
546 */ 546 */
547 this.visible = function visible(selector) { 547 this.visible = function visible(selector) {
548 try { 548 try {
549 var el = this.findOne(selector); 549 var comp,
550 return el && el.style.visibility !== 'hidden' && el.offsetHeight > 0 && el.offsetWidth > 0; 550 el = this.findOne(selector);
551
552 if (el) {
553 comp = window.getComputedStyle(el, null);
554 return comp.visibility !== 'hidden' && comp.display !== 'none' && el.offsetHeight > 0 && el.offsetWidth > 0;
555 }
556 return false;
551 } catch (e) { 557 } catch (e) {
552 return false; 558 return false;
553 } 559 }
......
...@@ -15,7 +15,7 @@ casper = require('casper').create verbose: true ...@@ -15,7 +15,7 @@ casper = require('casper').create verbose: true
15 casper.fetchScore = -> 15 casper.fetchScore = ->
16 @evaluate -> 16 @evaluate ->
17 result = document.querySelector('#resultStats').innerText 17 result = document.querySelector('#resultStats').innerText
18 ~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')) 18 parseInt /Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')
19 19
20 terms = casper.cli.args # terms are passed through command-line arguments 20 terms = casper.cli.args # terms are passed through command-line arguments
21 21
...@@ -38,7 +38,7 @@ casper.each terms, (self, term) -> ...@@ -38,7 +38,7 @@ casper.each terms, (self, term) ->
38 self.echo "#{term}: #{score}" 38 self.echo "#{term}: #{score}"
39 39
40 casper.run -> 40 casper.run ->
41 scores.sort -> (a, b) -> b.score - a.score;
42 winner = scores[0] 41 winner = scores[0]
42 winner = x for x in scores when x.score > winner.score
43 @echo "Winner is #{winner.term} with #{winner.score} results" 43 @echo "Winner is #{winner.term} with #{winner.score} results"
44 @exit() 44 @exit()
......
...@@ -16,7 +16,7 @@ var casper = new require('casper').create({ ...@@ -16,7 +16,7 @@ var casper = new require('casper').create({
16 casper.fetchScore = function() { 16 casper.fetchScore = function() {
17 return this.evaluate(function() { 17 return this.evaluate(function() {
18 var result = document.querySelector('#resultStats').innerText; 18 var result = document.querySelector('#resultStats').innerText;
19 return ~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')); 19 return parseInt(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''));
20 }); 20 });
21 }; 21 };
22 22
...@@ -45,10 +45,10 @@ casper.each(terms, function(self, term, i) { ...@@ -45,10 +45,10 @@ casper.each(terms, function(self, term, i) {
45 }); 45 });
46 46
47 casper.run(function(self) { 47 casper.run(function(self) {
48 scores.sort(function(a, b) {
49 return b.score - a.score;
50 });
51 var winner = scores[0]; 48 var winner = scores[0];
49 for (var i = 0, len = scores.length; i < len; i++)
50 if (scores[i].score > winner.score)
51 winner = scores[i];
52 self.echo('winner is "' + winner.term + '" with ' + winner.score + ' results'); 52 self.echo('winner is "' + winner.term + '" with ' + winner.score + ' results');
53 self.exit(); 53 self.exit();
54 }); 54 });
......