Add Tests for getElementsInfo() and getElementsAttribute()
Showing
3 changed files
with
27 additions
and
1 deletions
... | @@ -2,5 +2,6 @@ | ... | @@ -2,5 +2,6 @@ |
2 | <html> | 2 | <html> |
3 | <body> | 3 | <body> |
4 | <div class="tester testo testme" data-stuff="beautiful string"></div> | 4 | <div class="tester testo testme" data-stuff="beautiful string"></div> |
5 | <div class="tester testo testme" data-stuff="not as beautiful string"></div> | ||
5 | </body> | 6 | </body> |
6 | </html> | 7 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,12 +2,17 @@ | ... | @@ -2,12 +2,17 @@ |
2 | /*jshint strict:false*/ | 2 | /*jshint strict:false*/ |
3 | var x = require('casper').selectXPath; | 3 | var x = require('casper').selectXPath; |
4 | 4 | ||
5 | casper.test.begin('getElementAttribute() tests', 2, function(test) { | 5 | casper.test.begin('getElementAttribute() tests', 4, function(test) { |
6 | casper.start('tests/site/elementattribute.html', function() { | 6 | casper.start('tests/site/elementattribute.html', function() { |
7 | test.assertEquals(this.getElementAttribute('.testo', 'data-stuff'), | 7 | test.assertEquals(this.getElementAttribute('.testo', 'data-stuff'), |
8 | 'beautiful string', 'Casper.getElementAttribute() works with a CSS selector'); | 8 | 'beautiful string', 'Casper.getElementAttribute() works with a CSS selector'); |
9 | test.assertEquals(this.getElementAttribute(x('//div[@class]'), 'data-stuff'), | 9 | test.assertEquals(this.getElementAttribute(x('//div[@class]'), 'data-stuff'), |
10 | 'beautiful string', 'Casper.getElementAttribute() works with a XPath selector'); | 10 | 'beautiful string', 'Casper.getElementAttribute() works with a XPath selector'); |
11 | }).then(function() { | ||
12 | test.assertEquals(this.getElementsAttribute('.testo', 'data-stuff'), | ||
13 | ['beautiful string', 'not as beautiful string'], 'Casper.getElementsAttribute() works with a CSS selector'); | ||
14 | test.assertEquals(this.getElementsAttribute(x('//div[@class]'), 'data-stuff'), | ||
15 | ['beautiful string', 'not as beautiful string'], 'Casper.getElementsAttribute() works with a XPath selector'); | ||
11 | }).run(function() { | 16 | }).run(function() { |
12 | test.done(); | 17 | test.done(); |
13 | }); | 18 | }); | ... | ... |
... | @@ -161,3 +161,23 @@ casper.test.begin('ClientUtils.getElementInfo() tests', 10, function(test) { | ... | @@ -161,3 +161,23 @@ casper.test.begin('ClientUtils.getElementInfo() tests', 10, function(test) { |
161 | 'ClientUtils.getElementInfo() retrieves element whole tag contents'); | 161 | 'ClientUtils.getElementInfo() retrieves element whole tag contents'); |
162 | test.done(); | 162 | test.done(); |
163 | }); | 163 | }); |
164 | |||
165 | casper.test.begin('ClientUtils.getElementsInfo() tests', 10, function(test) { | ||
166 | casper.page.content = '<a href="plop" class="plip plup"><i>paf</i></a><a href="plap" class="plip plup"><i>puf</i></a>'; | ||
167 | var info = casper.getElementsInfo('a.plip')[1]; | ||
168 | test.assertEquals(info.nodeName, 'a', 'ClientUtils.getElementsInfo() retrieves element name'); | ||
169 | test.assertEquals(info.attributes, { | ||
170 | 'href': 'plap', | ||
171 | 'class': 'plip plup' | ||
172 | }, 'ClientUtils.getElementsInfo() retrieves element attributes'); | ||
173 | test.assertEquals(info.html, '<i>puf</i>', 'ClientUtils.getElementsInfo() retrieves element html content'); | ||
174 | test.assertEquals(info.text, 'puf', 'ClientUtils.getElementsInfo() retrieves element text'); | ||
175 | test.assert(info.x > 0, 'ClientUtils.getElementsInfo() retrieves element x pos'); | ||
176 | test.assert(info.y > 0, 'ClientUtils.getElementsInfo() retrieves element y pos'); | ||
177 | test.assert(info.width > 0, 'ClientUtils.getElementsInfo() retrieves element width'); | ||
178 | test.assert(info.height > 0, 'ClientUtils.getElementsInfo() retrieves element height'); | ||
179 | test.assert(info.visible, 'ClientUtils.getElementsInfo() retrieves element visibility'); | ||
180 | test.assertEquals(info.tag, '<a href="plap" class="plip plup"><i>puf</i></a>', | ||
181 | 'ClientUtils.getElementsInfo() retrieves element whole tag contents'); | ||
182 | test.done(); | ||
183 | }); | ... | ... |
-
Please register or sign in to post a comment