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
5a0a49ff
...
5a0a49fff6e5b73ba26d4733ce52bb6b363de8c4
authored
2011-10-15 19:20:16 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added jsdoc for phantom.Casper.XUnitExporter
1 parent
6eb73e0b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
37 deletions
casper.js
samples/googlelinks.js
casper.js
View file @
5a0a49f
...
...
@@ -1111,6 +1111,10 @@
};
};
/**
* JUnit XML (xUnit) exporter for test results.
*
*/
phantom
.
Casper
.
XUnitExporter
=
function
()
{
var
node
=
function
(
name
,
attributes
)
{
var
node
=
document
.
createElement
(
name
);
...
...
@@ -1128,6 +1132,9 @@
return
this
.
outerHTML
;
// ouch
};
/**
* Adds a successful test result
*/
this
.
addSuccess
=
function
(
classname
,
name
)
{
xml
.
appendChild
(
node
(
'testcase'
,
{
classname
:
classname
,
...
...
@@ -1135,6 +1142,9 @@
}));
};
/**
* Adds a failed test result
*/
this
.
addFailure
=
function
(
classname
,
name
,
message
,
type
)
{
var
fnode
=
node
(
'testcase'
,
{
classname
:
classname
,
...
...
@@ -1148,6 +1158,9 @@
xml
.
appendChild
(
fnode
);
};
/**
* Retrieves generated XML object.
*/
this
.
getXML
=
function
()
{
return
xml
;
}
...
...
@@ -1238,9 +1251,9 @@
/**
* Object recursive merging utility.
*
* @param
o
bject obj1 the destination object
* @param
o
bject obj2 the source object
* @return
o
bject
* @param
O
bject obj1 the destination object
* @param
O
bject obj2 the source object
* @return
O
bject
*/
function
mergeObjects
(
obj1
,
obj2
)
{
for
(
var
p
in
obj2
)
{
...
...
@@ -1261,9 +1274,9 @@
* Replaces a function string contents with placeholders provided by an
* Object.
*
* @param
f
unction fn The function
* @param
o
bject replacements Object containing placeholder replacements
* @return
s
tring A function string representation
* @param
F
unction fn The function
* @param
O
bject replacements Object containing placeholder replacements
* @return
S
tring A function string representation
*/
function
replaceFunctionPlaceholders
(
fn
,
replacements
)
{
if
(
replacements
&&
typeof
replacements
===
"object"
)
{
...
...
samples/googlelinks.js
View file @
5a0a49f
phantom
.
injectJs
(
'casper.js'
);
var
links
=
[];
var
casper
=
new
phantom
.
Casper
();
function
getLinks
()
{
var
links
=
document
.
querySelectorAll
(
'h3.r a'
);
return
Array
.
prototype
.
map
.
call
(
links
,
function
(
e
)
{
return
{
title
:
e
.
innerText
,
href
:
e
.
getAttribute
(
'href'
)
};
return
e
.
getAttribute
(
'href'
)
});
}
var
links
=
[];
var
casper
=
new
phantom
.
Casper
({
faultTolerant
:
false
,
logLevel
:
"debug"
,
// we only want "info" or higher level log messages
loadImages
:
false
,
// do not download images to save bandwidth
loadPlugins
:
false
,
// do not load plugins to save kitten
verbose
:
true
// write log messages to the console
})
.
start
(
'http://google.fr/'
)
.
then
(
function
(
self
)
{
casper
.
start
(
'http://google.fr/'
,
function
(
self
)
{
// search for 'casperjs' from google form
self
.
fill
(
'form[name=f]'
,
{
q
:
'casperjs'
},
true
);
})
.
then
(
function
(
self
)
{
self
.
fill
(
'form[name=f]'
,
{
q
:
'casperjs'
},
true
);
});
casper
.
then
(
function
(
self
)
{
// aggregate results for the 'casperjs' search
links
=
self
.
evaluate
(
getLinks
);
// now search for 'phantomjs' by fillin the form again
self
.
fill
(
'form[name=f]'
,
{
q
:
'phantomjs'
},
true
);
})
.
then
(
function
(
self
)
{
self
.
fill
(
'form[name=f]'
,
{
q
:
'phantomjs'
},
true
);
});
casper
.
then
(
function
(
self
)
{
// aggregate results for the 'phantomjs' search
links
=
links
.
concat
(
self
.
evaluate
(
getLinks
));
})
.
run
(
function
(
self
)
{
});
casper
.
run
(
function
(
self
)
{
// echo results in some pretty fashion
self
.
echo
(
links
.
map
(
function
(
i
)
{
return
i
.
title
+
' ('
+
i
.
href
+
')'
;
}).
join
(
'\n'
)).
exit
();
})
;
self
.
echo
(
links
.
length
+
' links found:'
);
self
.
echo
(
' - '
+
links
.
join
(
'\n - '
)).
exit
();
});
...
...
Please
register
or
sign in
to post a comment