Commit 977f74e0 977f74e006ec78c70d8a137395d3a2bd33b5338d by Reid Lynch

fix for visible/waitUntilVisible when selector matches multiple elements

1 parent b87c8630
...@@ -777,12 +777,14 @@ ...@@ -777,12 +777,14 @@
777 */ 777 */
778 this.visible = function visible(selector) { 778 this.visible = function visible(selector) {
779 try { 779 try {
780 var comp, 780 var el, comp,
781 el = this.findOne(selector); 781 elems = this.findAll(selector);
782 782
783 if (el) { 783 for(var i = 0; i < elems.length; i++)
784 {
785 el = elems[i];
784 comp = window.getComputedStyle(el, null); 786 comp = window.getComputedStyle(el, null);
785 return comp.visibility !== 'hidden' && comp.display !== 'none' && el.offsetHeight > 0 && el.offsetWidth > 0; 787 if (comp.visibility !== 'hidden' && comp.display !== 'none' && el.offsetHeight > 0 && el.offsetWidth > 0) return true;
786 } 788 }
787 return false; 789 return false;
788 } catch (e) { 790 } catch (e) {
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
10 </script> 10 </script>
11 </head> 11 </head>
12 <body> 12 <body>
13 <img src="images/phantom.png" id="img1"> 13 <img src="images/phantom.png" id="img1" style="display:none">
14 <img src="images/phantom.png" id="img2" style="display:none"> 14 <img src="images/phantom.png" id="img2">
15 <img src="images/phantom.png" id="img3" style="visibility:hidden"> 15 <img src="images/phantom.png" id="img3" style="visibility:hidden">
16 </body> 16 </body>
17 </html> 17 </html>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 Loading... 15 Loading...
16 </div> 16 </div>
17 <div id="encoded">Voil&agrave;</div> 17 <div id="encoded">Voil&agrave;</div>
18 <p style="display:none;">I'm hidden.</p>
19 <p>I'm visible.</p>
18 <script> 20 <script>
19 setTimeout(function() { 21 setTimeout(function() {
20 var li = document.createElement('li') 22 var li = document.createElement('li')
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 casper.test.begin('visibility tests', 4, function(test) { 3 casper.test.begin('visibility tests', 5, function(test) {
4 casper.start('tests/site/visible.html', function() { 4 casper.start('tests/site/visible.html', function() {
5 test.assert(this.visible('#img1'), 'Casper.visible() can detect if an element is visible'); 5 test.assert(!this.visible('#img1'), 'Casper.visible() can detect if an element is invisible');
6 test.assert(!this.visible('#img2'), 'Casper.visible() can detect if an element is invisible'); 6 test.assert(this.visible('#img2'), 'Casper.visible() can detect if an element is visible');
7 test.assert(!this.visible('#img3'), 'Casper.visible() can detect if an element is invisible'); 7 test.assert(!this.visible('#img3'), 'Casper.visible() can detect if an element is invisible');
8 test.assert(this.visible('img'), 'Casper.visible() can detect if an element is visible');
8 this.waitWhileVisible('#img1', function() { 9 this.waitWhileVisible('#img1', function() {
9 test.pass('Casper.waitWhileVisible() can wait while an element is visible'); 10 test.pass('Casper.waitWhileVisible() can wait while an element is visible');
10 }, function() { 11 }, function() {
......
...@@ -117,7 +117,7 @@ casper.test.begin('waitForSelectorTextChange() tests', 1, function(test) { ...@@ -117,7 +117,7 @@ casper.test.begin('waitForSelectorTextChange() tests', 1, function(test) {
117 }); 117 });
118 }); 118 });
119 119
120 casper.test.begin('waitUntilVisible() tests', 1, function(test) { 120 casper.test.begin('waitUntilVisible() tests', 2, function(test) {
121 casper.start('tests/site/waitFor.html'); 121 casper.start('tests/site/waitFor.html');
122 122
123 casper.waitUntilVisible('li:nth-child(4)', function() { 123 casper.waitUntilVisible('li:nth-child(4)', function() {
...@@ -126,6 +126,12 @@ casper.test.begin('waitUntilVisible() tests', 1, function(test) { ...@@ -126,6 +126,12 @@ casper.test.begin('waitUntilVisible() tests', 1, function(test) {
126 test.fail('Casper.waitUntilVisible() waits for a selector being visible'); 126 test.fail('Casper.waitUntilVisible() waits for a selector being visible');
127 }); 127 });
128 128
129 casper.waitUntilVisible('p', function() {
130 test.pass('Casper.waitUntilVisible() waits for a selector being visible');
131 }, function() {
132 test.fail('Casper.waitUntilVisible() waits for a selector being visible');
133 });
134
129 casper.run(function() { 135 casper.run(function() {
130 test.done(); 136 test.done();
131 }); 137 });
......