Merge pull request #432 from rigoleto/fix-for-visible-with-multiple-elements
fix for visible/waitUntilVisible when selector matches multiple elements
Showing
5 changed files
with
23 additions
and
14 deletions
... | @@ -777,14 +777,14 @@ | ... | @@ -777,14 +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 elems = this.findAll(selector); |
781 | el = this.findOne(selector); | 781 | return Array.prototype.some.call(elems, function(el) { |
782 | 782 | var comp = window.getComputedStyle(el, null); | |
783 | if (el) { | 783 | return comp.visibility !== 'hidden' && |
784 | comp = window.getComputedStyle(el, null); | 784 | comp.display !== 'none' && |
785 | return comp.visibility !== 'hidden' && comp.display !== 'none' && el.offsetHeight > 0 && el.offsetWidth > 0; | 785 | el.offsetHeight > 0 && |
786 | } | 786 | el.offsetWidth > 0; |
787 | return false; | 787 | }); |
788 | } catch (e) { | 788 | } catch (e) { |
789 | return false; | 789 | return false; |
790 | } | 790 | } | ... | ... |
... | @@ -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à</div> | 17 | <div id="encoded">Voilà</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 | }); | ... | ... |
-
Please register or sign in to post a comment