Commit d546a12e d546a12e6bb0b9220aa10087f3950de64f182faa by Nicolas Perriault

Merge pull request #432 from rigoleto/fix-for-visible-with-multiple-elements

fix for visible/waitUntilVisible when selector matches multiple elements
2 parents 87aa8ab1 7fc49456
......@@ -777,14 +777,14 @@
*/
this.visible = function visible(selector) {
try {
var comp,
el = this.findOne(selector);
if (el) {
comp = window.getComputedStyle(el, null);
return comp.visibility !== 'hidden' && comp.display !== 'none' && el.offsetHeight > 0 && el.offsetWidth > 0;
}
return false;
var elems = this.findAll(selector);
return Array.prototype.some.call(elems, function(el) {
var comp = window.getComputedStyle(el, null);
return comp.visibility !== 'hidden' &&
comp.display !== 'none' &&
el.offsetHeight > 0 &&
el.offsetWidth > 0;
});
} catch (e) {
return false;
}
......
......@@ -10,8 +10,8 @@
</script>
</head>
<body>
<img src="images/phantom.png" id="img1">
<img src="images/phantom.png" id="img2" style="display:none">
<img src="images/phantom.png" id="img1" style="display:none">
<img src="images/phantom.png" id="img2">
<img src="images/phantom.png" id="img3" style="visibility:hidden">
</body>
</html>
\ No newline at end of file
......
......@@ -15,6 +15,8 @@
Loading...
</div>
<div id="encoded">Voil&agrave;</div>
<p style="display:none;">I'm hidden.</p>
<p>I'm visible.</p>
<script>
setTimeout(function() {
var li = document.createElement('li')
......
/*global casper*/
/*jshint strict:false*/
casper.test.begin('visibility tests', 4, function(test) {
casper.test.begin('visibility tests', 5, function(test) {
casper.start('tests/site/visible.html', function() {
test.assert(this.visible('#img1'), 'Casper.visible() can detect if an element is visible');
test.assert(!this.visible('#img2'), 'Casper.visible() can detect if an element is invisible');
test.assert(!this.visible('#img1'), 'Casper.visible() can detect if an element is invisible');
test.assert(this.visible('#img2'), 'Casper.visible() can detect if an element is visible');
test.assert(!this.visible('#img3'), 'Casper.visible() can detect if an element is invisible');
test.assert(this.visible('img'), 'Casper.visible() can detect if an element is visible');
this.waitWhileVisible('#img1', function() {
test.pass('Casper.waitWhileVisible() can wait while an element is visible');
}, function() {
......
......@@ -117,7 +117,7 @@ casper.test.begin('waitForSelectorTextChange() tests', 1, function(test) {
});
});
casper.test.begin('waitUntilVisible() tests', 1, function(test) {
casper.test.begin('waitUntilVisible() tests', 2, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitUntilVisible('li:nth-child(4)', function() {
......@@ -126,6 +126,12 @@ casper.test.begin('waitUntilVisible() tests', 1, function(test) {
test.fail('Casper.waitUntilVisible() waits for a selector being visible');
});
casper.waitUntilVisible('p', function() {
test.pass('Casper.waitUntilVisible() waits for a selector being visible');
}, function() {
test.fail('Casper.waitUntilVisible() waits for a selector being visible');
});
casper.run(function() {
test.done();
});
......