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
0d445eba
...
0d445eba12dd6161844b15fcba291586aa45dafd
authored
2011-10-18 14:12:20 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper#fetchText
1 parent
35ac229d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
casper.js
tests/run.js
tests/site/index.html
casper.js
View file @
0d445eb
...
...
@@ -332,6 +332,21 @@
},
/**
* Fetches innerText within the element(s) matching a given CSS3
* selector.
*
* @param String selector A CSS3 selector
* @return String
*/
fetchText
:
function
(
selector
)
{
return
this
.
evaluate
(
function
()
{
return
__utils__
.
fetchText
(
'%selector%'
);
},
{
selector
:
selector
.
replace
(
"'"
,
"\'"
)
});
},
/**
* Fills a form with provided field values.
*
* @param String selector A CSS3 selector to the target form to fill
...
...
@@ -686,6 +701,23 @@
};
/**
* Fetches innerText within the element(s) matching a given CSS3
* selector.
*
* @param String selector A CSS3 selector
* @return String
*/
this
.
fetchText
=
function
(
selector
)
{
var
text
=
''
,
elements
=
this
.
findAll
(
selector
);
if
(
elements
&&
elements
.
length
)
{
Array
.
prototype
.
forEach
.
call
(
elements
,
function
(
element
)
{
text
+=
element
.
innerText
;
});
}
return
text
;
};
/**
* Fills a form with provided field values, and optionnaly submits it.
*
* @param HTMLElement|String form A form element, or a CSS3 selector to a form element
...
...
tests/run.js
View file @
0d445eb
...
...
@@ -38,6 +38,8 @@ casper.start('tests/site/index.html', function(self) {
self
.
test
.
assertEval
(
function
()
{
return
typeof
(
__utils__
)
===
"object"
;
},
'start() injects ClientUtils instance within remote DOM'
);
self
.
test
.
comment
(
'fetching'
)
self
.
test
.
assertEquals
(
self
.
fetchText
(
'ul li'
),
'onetwothree'
,
'fetchText() can retrieves text contents'
);
self
.
test
.
comment
(
'encoding'
);
var
image
=
self
.
base64encode
(
'file://'
+
phantom
.
libraryPath
+
'/site/images/phantom.png'
);
self
.
test
.
assertEquals
(
image
.
length
,
6160
,
'base64encode() can retrieve base64 contents'
);
...
...
tests/site/index.html
View file @
0d445eb
...
...
@@ -8,5 +8,10 @@
<img
src=
"images/phantom.png"
/>
<a
href=
"test.html"
>
test
</a>
<a
href=
"form.html"
>
form
</a>
<ul>
<li>
one
</li>
<li>
two
</li>
<li>
three
</li>
</ul>
</body>
</html>
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment