Commit a2282c1c a2282c1c2f9f32efce592ee5c3d73c7dfd6caf93 by Nicolas Perriault

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

1 parent 4a42fe7f
......@@ -947,7 +947,7 @@
waitWhileSelector: function(selector, then, onTimeout, timeout) {
timeout = timeout ? timeout : this.defaultWaitTimeout;
return this.waitFor(function(self) {
return ! self.exists(selector);
return !self.exists(selector);
}, then, onTimeout, timeout);
},
......@@ -981,7 +981,7 @@
waitWhileVisible: function(selector, then, onTimeout, timeout) {
timeout = timeout ? timeout : this.defaultWaitTimeout;
return this.waitFor(function(self) {
return ! self.visible(selector);
return !self.visible(selector);
}, then, onTimeout, timeout);
}
};
......@@ -1085,7 +1085,7 @@
this.visible = function(selector) {
try {
var el = document.querySelector(selector);
return el && el.offsetHeight > 0 && el.offsetWidth > 0;
return el && el.style.visibility !== 'hidden' && el.offsetHeight > 0 && el.offsetWidth > 0;
} catch (e) {
return false;
}
......
......@@ -247,7 +247,20 @@ casper.then(function(self) {
self.thenOpen('tests/site/page1.html');
});
// Casper.visible()
casper.thenOpen('tests/site/visible.html', function(self) {
self.test.comment('Casper.visible()');
self.test.assert(self.visible('#img1'), 'Casper.visible() can detect if an element is visible');
self.test.assert(!self.visible('#img2'), 'Casper.visible() can detect if an element is invisible');
self.test.assert(!self.visible('#img3'), 'Casper.visible() can detect if an element is invisible');
self.waitWhileVisible('#img1', function(self) {
self.test.comment('Casper.waitWhileVisible()');
self.test.pass('Casper.waitWhileVisible() can wait while an element is visible');
}, function(self) {
self.test.comment('Casper.waitWhileVisible()');
self.test.fail('Casper.waitWhileVisible() can wait while an element is visible');
}, 2000);
});
// History
casper
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test index</title>
<script>
setTimeout(function() {
document.querySelector('#img1').style.display = 'none';
}, 1000);
</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="img3" style="visibility:hidden">
</body>
</html>
\ No newline at end of file