Commit 9e8cad06 9e8cad06cc575216ed4125cc0d6f18dab9488d0c by Nicolas Perriault

fixed Casper#captureSelector() which was broken since the beginning (\!)

1 parent e8b1583f
Showing 1 changed file with 16 additions and 7 deletions
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
33 * @return Casper 33 * @return Casper
34 */ 34 */
35 phantom.Casper = function(options) { 35 phantom.Casper = function(options) {
36 const DEFAULT_DIE_MESSAGE = "Suite explicitely interrupted without any message given."; 36 var DEFAULT_DIE_MESSAGE = "Suite explicitely interrupted without any message given.";
37 const DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"; 37 var DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1";
38 // init & checks 38 // init & checks
39 if (!(this instanceof arguments.callee)) { 39 if (!(this instanceof arguments.callee)) {
40 return new Casper(options); 40 return new Casper(options);
...@@ -132,10 +132,18 @@ ...@@ -132,10 +132,18 @@
132 captureSelector: function(targetFile, selector) { 132 captureSelector: function(targetFile, selector) {
133 return this.capture(targetFile, this.evaluate(function() { 133 return this.capture(targetFile, this.evaluate(function() {
134 try { 134 try {
135 return document.querySelector(selector).getBoundingClientRect(); 135 var clipRect = document.querySelector('%selector%').getBoundingClientRect();
136 return {
137 top: clipRect.top,
138 left: clipRect.left,
139 width: clipRect.width,
140 height: clipRect.height
141 };
136 } catch (e) { 142 } catch (e) {
137 console.log('unable to fetch bounds for element ' + selector); 143 __utils__.log('unable to fetch bounds for element ' + selector, 'warning');
138 } 144 }
145 }, {
146 selector: selector.replace("'", "\'")
139 })); 147 }));
140 }, 148 },
141 149
...@@ -399,8 +407,9 @@ ...@@ -399,8 +407,9 @@
399 if (submit) { 407 if (submit) {
400 this.evaluate(function() { 408 this.evaluate(function() {
401 var form = document.querySelector('%selector%'); 409 var form = document.querySelector('%selector%');
402 console.log('submitting form to ' + (form.getAttribute('action') || "unknown") 410 var method = form.getAttribute('method').toUpperCase() || "GET";
403 + ', HTTP ' + (form.getAttribute('method').toUpperCase() || "GET")); 411 var action = form.getAttribute('action') || "unknown";
412 __utils__.log('submitting form to ' + action + ', HTTP ' + method, 'info');
404 form.submit(); 413 form.submit();
405 }, { 414 }, {
406 selector: selector.replace("'", "\'") 415 selector: selector.replace("'", "\'")
...@@ -738,7 +747,7 @@ ...@@ -738,7 +747,7 @@
738 files: [] 747 files: []
739 }; 748 };
740 if (!(form instanceof HTMLElement) || typeof form === "string") { 749 if (!(form instanceof HTMLElement) || typeof form === "string") {
741 console.log("attempting to fetch form element from selector: '" + form + "'"); 750 __utils__.log("attempting to fetch form element from selector: '" + form + "'", "info");
742 try { 751 try {
743 form = document.querySelector(form); 752 form = document.querySelector(form);
744 } catch (e) { 753 } catch (e) {
......