Commit a2282c1c a2282c1c2f9f32efce592ee5c3d73c7dfd6caf93 by Nicolas Perriault

fixed edge case for CasperUtils.visible(), added tests

1 parent 4a42fe7f
...@@ -947,7 +947,7 @@ ...@@ -947,7 +947,7 @@
947 waitWhileSelector: function(selector, then, onTimeout, timeout) { 947 waitWhileSelector: function(selector, then, onTimeout, timeout) {
948 timeout = timeout ? timeout : this.defaultWaitTimeout; 948 timeout = timeout ? timeout : this.defaultWaitTimeout;
949 return this.waitFor(function(self) { 949 return this.waitFor(function(self) {
950 return ! self.exists(selector); 950 return !self.exists(selector);
951 }, then, onTimeout, timeout); 951 }, then, onTimeout, timeout);
952 }, 952 },
953 953
...@@ -981,7 +981,7 @@ ...@@ -981,7 +981,7 @@
981 waitWhileVisible: function(selector, then, onTimeout, timeout) { 981 waitWhileVisible: function(selector, then, onTimeout, timeout) {
982 timeout = timeout ? timeout : this.defaultWaitTimeout; 982 timeout = timeout ? timeout : this.defaultWaitTimeout;
983 return this.waitFor(function(self) { 983 return this.waitFor(function(self) {
984 return ! self.visible(selector); 984 return !self.visible(selector);
985 }, then, onTimeout, timeout); 985 }, then, onTimeout, timeout);
986 } 986 }
987 }; 987 };
...@@ -1085,7 +1085,7 @@ ...@@ -1085,7 +1085,7 @@
1085 this.visible = function(selector) { 1085 this.visible = function(selector) {
1086 try { 1086 try {
1087 var el = document.querySelector(selector); 1087 var el = document.querySelector(selector);
1088 return el && el.offsetHeight > 0 && el.offsetWidth > 0; 1088 return el && el.style.visibility !== 'hidden' && el.offsetHeight > 0 && el.offsetWidth > 0;
1089 } catch (e) { 1089 } catch (e) {
1090 return false; 1090 return false;
1091 } 1091 }
......
...@@ -247,7 +247,20 @@ casper.then(function(self) { ...@@ -247,7 +247,20 @@ casper.then(function(self) {
247 self.thenOpen('tests/site/page1.html'); 247 self.thenOpen('tests/site/page1.html');
248 }); 248 });
249 249
250 250 // Casper.visible()
251 casper.thenOpen('tests/site/visible.html', function(self) {
252 self.test.comment('Casper.visible()');
253 self.test.assert(self.visible('#img1'), 'Casper.visible() can detect if an element is visible');
254 self.test.assert(!self.visible('#img2'), 'Casper.visible() can detect if an element is invisible');
255 self.test.assert(!self.visible('#img3'), 'Casper.visible() can detect if an element is invisible');
256 self.waitWhileVisible('#img1', function(self) {
257 self.test.comment('Casper.waitWhileVisible()');
258 self.test.pass('Casper.waitWhileVisible() can wait while an element is visible');
259 }, function(self) {
260 self.test.comment('Casper.waitWhileVisible()');
261 self.test.fail('Casper.waitWhileVisible() can wait while an element is visible');
262 }, 2000);
263 });
251 264
252 // History 265 // History
253 casper 266 casper
......
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test index</title>
6 <script>
7 setTimeout(function() {
8 document.querySelector('#img1').style.display = 'none';
9 }, 1000);
10 </script>
11 </head>
12 <body>
13 <img src="images/phantom.png" id="img1">
14 <img src="images/phantom.png" id="img2" style="display:none">
15 <img src="images/phantom.png" id="img3" style="visibility:hidden">
16 </body>
17 </html>
...\ No newline at end of file ...\ No newline at end of file