Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
a41a81c8
...
a41a81c81bf1863e7306b72421a03ab777f0798e
authored
2013-05-04 12:01:03 -0600
by
hexid
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add Tests for getElementsInfo() and getElementsAttribute()
1 parent
c4582f66
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletions
tests/site/elementattribute.html
tests/suites/casper/elementattribute.js
tests/suites/clientutils.js
tests/site/elementattribute.html
View file @
a41a81c
...
...
@@ -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
...
...
tests/suites/casper/elementattribute.js
View file @
a41a81c
...
...
@@ -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
();
});
...
...
tests/suites/clientutils.js
View file @
a41a81c
...
...
@@ -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
();
});
...
...
Please
register
or
sign in
to post a comment