Commit a41a81c8 a41a81c81bf1863e7306b72421a03ab777f0798e by hexid

Add Tests for getElementsInfo() and getElementsAttribute()

1 parent c4582f66
......@@ -2,5 +2,6 @@
<html>
<body>
<div class="tester testo testme" data-stuff="beautiful string"></div>
<div class="tester testo testme" data-stuff="not as beautiful string"></div>
</body>
</html>
\ No newline at end of file
......
......@@ -2,12 +2,17 @@
/*jshint strict:false*/
var x = require('casper').selectXPath;
casper.test.begin('getElementAttribute() tests', 2, function(test) {
casper.test.begin('getElementAttribute() tests', 4, function(test) {
casper.start('tests/site/elementattribute.html', function() {
test.assertEquals(this.getElementAttribute('.testo', 'data-stuff'),
'beautiful string', 'Casper.getElementAttribute() works with a CSS selector');
test.assertEquals(this.getElementAttribute(x('//div[@class]'), 'data-stuff'),
'beautiful string', 'Casper.getElementAttribute() works with a XPath selector');
}).then(function() {
test.assertEquals(this.getElementsAttribute('.testo', 'data-stuff'),
['beautiful string', 'not as beautiful string'], 'Casper.getElementsAttribute() works with a CSS selector');
test.assertEquals(this.getElementsAttribute(x('//div[@class]'), 'data-stuff'),
['beautiful string', 'not as beautiful string'], 'Casper.getElementsAttribute() works with a XPath selector');
}).run(function() {
test.done();
});
......
......@@ -161,3 +161,23 @@ casper.test.begin('ClientUtils.getElementInfo() tests', 10, function(test) {
'ClientUtils.getElementInfo() retrieves element whole tag contents');
test.done();
});
casper.test.begin('ClientUtils.getElementsInfo() tests', 10, function(test) {
casper.page.content = '<a href="plop" class="plip plup"><i>paf</i></a><a href="plap" class="plip plup"><i>puf</i></a>';
var info = casper.getElementsInfo('a.plip')[1];
test.assertEquals(info.nodeName, 'a', 'ClientUtils.getElementsInfo() retrieves element name');
test.assertEquals(info.attributes, {
'href': 'plap',
'class': 'plip plup'
}, 'ClientUtils.getElementsInfo() retrieves element attributes');
test.assertEquals(info.html, '<i>puf</i>', 'ClientUtils.getElementsInfo() retrieves element html content');
test.assertEquals(info.text, 'puf', 'ClientUtils.getElementsInfo() retrieves element text');
test.assert(info.x > 0, 'ClientUtils.getElementsInfo() retrieves element x pos');
test.assert(info.y > 0, 'ClientUtils.getElementsInfo() retrieves element y pos');
test.assert(info.width > 0, 'ClientUtils.getElementsInfo() retrieves element width');
test.assert(info.height > 0, 'ClientUtils.getElementsInfo() retrieves element height');
test.assert(info.visible, 'ClientUtils.getElementsInfo() retrieves element visibility');
test.assertEquals(info.tag, '<a href="plap" class="plip plup"><i>puf</i></a>',
'ClientUtils.getElementsInfo() retrieves element whole tag contents');
test.done();
});
......