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
90f33738
...
90f33738f968769d6abc4c1f37779d1c2db91086
authored
2012-01-11 19:05:03 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
removed obsolete isolation tricks from test suite
1 parent
9dd655b4
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
725 additions
and
769 deletions
.gitignore
tests/suites/casper/capture.js
tests/suites/casper/click.js
tests/suites/casper/clientutils.js
tests/suites/casper/encode.js
tests/suites/casper/evaluate.js
tests/suites/casper/exists.js
tests/suites/casper/fetchtext.js
tests/suites/casper/flow.coffee
tests/suites/casper/formfill.js
tests/suites/casper/global.js
tests/suites/casper/history.js
tests/suites/casper/hooks.js
tests/suites/casper/logging.js
tests/suites/casper/open.js
tests/suites/casper/resources.coffee
tests/suites/casper/start.js
tests/suites/casper/steps.js
tests/suites/casper/viewport.js
tests/suites/casper/visible.js
tests/suites/casper/wait.js
tests/suites/cli.js
tests/suites/coffee.coffee
tests/suites/error.js
tests/suites/injector.js
tests/suites/tester.js
tests/suites/utils.js
tests/suites/xunit.js
.gitignore
View file @
90f3373
.DS_Store
*.xml
*.png
/tmp
...
...
tests/suites/casper/capture.js
View file @
90f3373
(
function
(
t
)
{
var
fs
=
require
(
'fs'
),
testFile
=
'/tmp/__casper_test_capture.png'
;
var
fs
=
require
(
'fs'
),
testFile
=
'/tmp/__casper_test_capture.png'
;
if
(
fs
.
exists
(
testFile
)
&&
fs
.
isFile
(
testFile
))
{
fs
.
remove
(
testFile
);
}
if
(
fs
.
exists
(
testFile
)
&&
fs
.
isFile
(
testFile
))
{
fs
.
remove
(
testFile
);
}
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
self
.
viewport
(
300
,
200
);
t
.
comment
(
'Casper.capture()'
);
self
.
capture
(
testFile
);
t
.
assert
(
fs
.
isFile
(
testFile
),
'Casper.capture() captured a screenshot'
);
});
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
self
.
viewport
(
300
,
200
);
this
.
tes
t
.
comment
(
'Casper.capture()'
);
self
.
capture
(
testFile
);
this
.
tes
t
.
assert
(
fs
.
isFile
(
testFile
),
'Casper.capture() captured a screenshot'
);
});
try
{
fs
.
remove
(
testFile
);
}
catch
(
e
)
{}
try
{
fs
.
remove
(
testFile
);
}
catch
(
e
)
{}
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
(
self
)
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/click.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/index.html'
,
function
()
{
this
.
click
(
'a[href="test.html"]'
);
});
casper
.
start
(
'tests/site/index.html'
,
function
()
{
this
.
click
(
'a[href="test.html"]'
);
});
casper
.
then
(
function
()
{
t
.
comment
(
'Casper.click()'
);
t
.
assertTitle
(
'CasperJS test target'
,
'Casper.click() can click on a link'
);
}).
thenClick
(
'a'
,
function
()
{
t
.
comment
(
'Casper.thenClick()'
);
t
.
assertTitle
(
'CasperJS test form'
,
'Casper.thenClick() can click on a link'
);
});
casper
.
then
(
function
()
{
this
.
tes
t
.
comment
(
'Casper.click()'
);
this
.
tes
t
.
assertTitle
(
'CasperJS test target'
,
'Casper.click() can click on a link'
);
}).
thenClick
(
'a'
,
function
()
{
this
.
tes
t
.
comment
(
'Casper.thenClick()'
);
this
.
tes
t
.
assertTitle
(
'CasperJS test form'
,
'Casper.thenClick() can click on a link'
);
});
// onclick variants tests
casper
.
thenOpen
(
'tests/site/click.html'
,
function
()
{
t
.
comment
(
'CasperUtils.click()'
);
this
.
test
.
assert
(
this
.
click
(
'#test1'
),
'CasperUtils.click() can click an `href="javascript:` link'
);
this
.
test
.
assert
(
this
.
click
(
'#test2'
),
'CasperUtils.click() can click an `href="#"` link'
);
this
.
test
.
assert
(
this
.
click
(
'#test3'
),
'CasperUtils.click() can click an `onclick=".*; return false"` link'
);
this
.
test
.
assert
(
this
.
click
(
'#test4'
),
'CasperUtils.click() can click an unobstrusive js handled link'
);
var
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assert
(
results
.
test1
,
'CasperUtils.click() has clicked an `href="javascript:` link'
);
this
.
test
.
assert
(
results
.
test2
,
'CasperUtils.click() has clicked an `href="#"` link'
);
this
.
test
.
assert
(
results
.
test3
,
'CasperUtils.click() has clicked an `onclick=".*; return false"` link'
);
this
.
test
.
assert
(
results
.
test4
,
'CasperUtils.click() has clicked an unobstrusive js handled link'
);
});
// onclick variants tests
casper
.
thenOpen
(
'tests/site/click.html'
,
function
()
{
this
.
tes
t
.
comment
(
'CasperUtils.click()'
);
this
.
test
.
assert
(
this
.
click
(
'#test1'
),
'CasperUtils.click() can click an `href="javascript:` link'
);
this
.
test
.
assert
(
this
.
click
(
'#test2'
),
'CasperUtils.click() can click an `href="#"` link'
);
this
.
test
.
assert
(
this
.
click
(
'#test3'
),
'CasperUtils.click() can click an `onclick=".*; return false"` link'
);
this
.
test
.
assert
(
this
.
click
(
'#test4'
),
'CasperUtils.click() can click an unobstrusive js handled link'
);
var
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assert
(
results
.
test1
,
'CasperUtils.click() has clicked an `href="javascript:` link'
);
this
.
test
.
assert
(
results
.
test2
,
'CasperUtils.click() has clicked an `href="#"` link'
);
this
.
test
.
assert
(
results
.
test3
,
'CasperUtils.click() has clicked an `onclick=".*; return false"` link'
);
this
.
test
.
assert
(
results
.
test4
,
'CasperUtils.click() has clicked an unobstrusive js handled link'
);
});
// casper.mouse
casper
.
then
(
function
()
{
t
.
comment
(
'Mouse.down()'
);
this
.
mouse
.
down
(
200
,
100
);
var
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
testdown
,
[
200
,
100
],
'Mouse.down() has pressed button to the specified position'
);
// casper.mouse
casper
.
then
(
function
()
{
this
.
tes
t
.
comment
(
'Mouse.down()'
);
this
.
mouse
.
down
(
200
,
100
);
var
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
testdown
,
[
200
,
100
],
'Mouse.down() has pressed button to the specified position'
);
t
.
comment
(
'Mouse.up()'
);
this
.
mouse
.
up
(
200
,
100
);
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
testup
,
[
200
,
100
],
'Mouse.up() has released button to the specified position'
);
this
.
tes
t
.
comment
(
'Mouse.up()'
);
this
.
mouse
.
up
(
200
,
100
);
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
testup
,
[
200
,
100
],
'Mouse.up() has released button to the specified position'
);
t
.
comment
(
'Mouse.move()'
);
this
.
mouse
.
move
(
200
,
100
);
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
testmove
,
[
200
,
100
],
'Mouse.move() has moved to the specified position'
);
});
this
.
tes
t
.
comment
(
'Mouse.move()'
);
this
.
mouse
.
move
(
200
,
100
);
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
testmove
,
[
200
,
100
],
'Mouse.move() has moved to the specified position'
);
});
casper
.
run
(
function
()
{
t
.
done
();
});
})(
casper
.
test
);
\ No newline at end of file
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/clientutils.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'ClientUtils.encode()'
);
var
fs
=
require
(
'fs'
);
var
clientutils
=
require
(
'clientutils'
).
create
();
var
testCases
=
{
'an empty string'
:
''
,
'a word'
:
'plop'
,
'a null char'
:
'a\u0000'
,
'an utf8 string'
:
'ÀÁÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ'
,
'song lyrics'
:
(
"Voilà l'été, j'aperçois le soleil\n"
+
"Les nuages filent et le ciel s'éclaircit\n"
+
"Et dans ma tête qui bourdonnent?\n"
+
"Les abeilles!"
),
'a file contents'
:
fs
.
read
(
phantom
.
casperPath
+
'/tests/site/alert.html'
)
};
var
fs
=
require
(
'fs'
);
var
clientutils
=
require
(
'clientutils'
).
create
();
var
testCases
=
{
'an empty string'
:
''
,
'a word'
:
'plop'
,
'a null char'
:
'a\u0000'
,
'an utf8 string'
:
'ÀÁÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ'
,
'song lyrics'
:
(
"Voilà l'été, j'aperçois le soleil\n"
+
"Les nuages filent et le ciel s'éclaircit\n"
+
"Et dans ma tête qui bourdonnent?\n"
+
"Les abeilles!"
),
'a file contents'
:
fs
.
read
(
phantom
.
casperPath
+
'/tests/site/alert.html'
)
};
casper
.
test
.
comment
(
'ClientUtils.encode()'
);
for
(
var
what
in
testCases
)
{
var
source
=
testCases
[
what
];
var
encoded
=
clientutils
.
encode
(
source
);
t
.
assertEquals
(
clientutils
.
decode
(
encoded
),
source
,
'ClientUtils can encode and decode '
+
what
);
}
for
(
var
what
in
testCases
)
{
var
source
=
testCases
[
what
];
var
encoded
=
clientutils
.
encode
(
source
);
casper
.
tes
t
.
assertEquals
(
clientutils
.
decode
(
encoded
),
source
,
'ClientUtils can encode and decode '
+
what
);
}
t
.
done
();
})(
casper
.
test
);
casper
.
test
.
done
();
...
...
tests/suites/casper/encode.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
var
imageUrl
=
'file://'
+
phantom
.
casperPath
+
'/tests/site/images/phantom.png'
;
var
image
=
self
.
base64encode
(
imageUrl
);
var
fs
=
require
(
'fs'
);
var
fs
=
require
(
'fs'
);
t
.
comment
(
'Casper.base64encode()'
);
t
.
assertEquals
(
image
.
length
,
6160
,
'Casper.base64encode() can retrieve base64 contents'
);
casper
.
start
(
'tests/site/index.html'
,
function
()
{
var
imageUrl
=
'file://'
+
phantom
.
casperPath
+
'/tests/site/images/phantom.png'
;
var
image
=
this
.
base64encode
(
imageUrl
);
t
.
comment
(
'Casper.download()'
);
self
.
download
(
imageUrl
,
'logo.png'
);
t
.
assert
(
fs
.
exists
(
'logo.png'
),
'Casper.download() downloads a file'
);
if
(
fs
.
exists
(
'logo.png'
))
{
fs
.
remove
(
'logo.png'
);
}
});
this
.
test
.
comment
(
'Casper.base64encode()'
);
this
.
test
.
assertEquals
(
image
.
length
,
6160
,
'Casper.base64encode() can retrieve base64 contents'
);
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
this
.
test
.
comment
(
'Casper.download()'
);
this
.
download
(
imageUrl
,
'logo.png'
);
this
.
test
.
assert
(
fs
.
exists
(
'logo.png'
),
'Casper.download() downloads a file'
);
if
(
fs
.
exists
(
'logo.png'
))
{
fs
.
remove
(
'logo.png'
);
}
});
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/evaluate.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Casper.evaluate()'
);
casper
.
test
.
comment
(
'Casper.evaluate()'
);
casper
.
start
();
casper
.
start
();
var
params
=
{
"boolean true"
:
true
,
"boolean false"
:
false
,
"int number"
:
42
,
"float number"
:
1337.42
,
"string"
:
"plop! \"Ÿ£$\" 'no'"
,
"array"
:
[
1
,
2
,
3
],
"object"
:
{
a
:
1
,
b
:
2
}
};
var
params
=
{
"boolean true"
:
true
,
"boolean false"
:
false
,
"int number"
:
42
,
"float number"
:
1337.42
,
"string"
:
"plop! \"Ÿ£$\" 'no'"
,
"array"
:
[
1
,
2
,
3
],
"object"
:
{
a
:
1
,
b
:
2
}
};
var
casperParams
=
casper
.
evaluate
(
function
()
{
return
__casper_params__
;
},
params
);
var
casperParams
=
casper
.
evaluate
(
function
()
{
return
__casper_params__
;
},
params
);
casper
.
test
.
assertType
(
casperParams
,
"object"
,
'Casper.evaluate() exposes parameters in a dedicated object'
);
casper
.
test
.
assertEquals
(
Object
.
keys
(
casperParams
).
length
,
7
,
'Casper.evaluate() object containing parameters has the correct length'
);
casper
.
test
.
assertType
(
casperParams
,
"object"
,
'Casper.evaluate() exposes parameters in a dedicated object'
);
casper
.
test
.
assertEquals
(
Object
.
keys
(
casperParams
).
length
,
7
,
'Casper.evaluate() object containing parameters has the correct length'
);
for
(
var
param
in
casperParams
)
{
casper
.
test
.
assertEquals
(
JSON
.
stringify
(
casperParams
[
param
]),
JSON
.
stringify
(
params
[
param
]),
'Casper.evaluate() can pass a '
+
param
);
casper
.
test
.
assertEquals
(
typeof
casperParams
[
param
],
typeof
params
[
param
],
'Casper.evaluate() preserves the '
+
param
+
' type'
);
}
for
(
var
param
in
casperParams
)
{
casper
.
test
.
assertEquals
(
JSON
.
stringify
(
casperParams
[
param
]),
JSON
.
stringify
(
params
[
param
]),
'Casper.evaluate() can pass a '
+
param
);
casper
.
test
.
assertEquals
(
typeof
casperParams
[
param
],
typeof
params
[
param
],
'Casper.evaluate() preserves the '
+
param
+
' type'
);
}
t
.
done
();
})(
casper
.
test
);
casper
.
test
.
done
();
...
...
tests/suites/casper/exists.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Casper.exists()'
);
casper
.
test
.
comment
(
'Casper.exists()'
);
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
t
.
assert
(
self
.
exists
(
'a'
)
&&
!
self
.
exists
(
'chucknorriz'
),
'Casper.exists() can check if an element exists'
);
});
casper
.
start
(
'tests/site/index.html'
,
function
(
)
{
this
.
test
.
assert
(
this
.
exists
(
'a'
)
&&
!
this
.
exists
(
'chucknorriz'
),
'Casper.exists() can check if an element exists'
);
});
casper
.
run
(
function
(
step
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/fetchtext.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Casper.fetchText()'
);
casper
.
test
.
comment
(
'Casper.fetchText()'
);
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
t
.
assertEquals
(
self
.
fetchText
(
'ul li'
),
'onetwothree'
,
'Casper.fetchText() can retrieve text contents'
);
});
casper
.
start
(
'tests/site/index.html'
,
function
(
)
{
this
.
test
.
assertEquals
(
this
.
fetchText
(
'ul li'
),
'onetwothree'
,
'Casper.fetchText() can retrieve text contents'
);
});
casper
.
run
(
function
()
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/flow.coffee
View file @
90f3373
do
(
casper
)
->
step
=
0
step
=
0
# testing resources
casper
.
start
"tests/site/resources.html"
,
->
@
test
.
assertEquals
++
step
,
1
,
"step 1"
@
wait
400
,
->
@
test
.
assertEquals
++
step
,
2
,
"step 1.1"
# testing resources
casper
.
start
"tests/site/resources.html"
,
->
@
test
.
assertEquals
++
step
,
1
,
"step 1"
@
wait
400
,
->
@
test
.
assertEquals
++
step
,
2
,
"step 1.1"
@
wait
200
,
->
@
test
.
assertEquals
++
step
,
3
,
"step 1.1.1"
@
wait
200
,
->
@
test
.
assertEquals
++
step
,
3
,
"step 1.1.1"
@
wait
200
,
->
@
test
.
assertEquals
++
step
,
4
,
"step 1.1.1.1"
@
then
->
@
test
.
assertEquals
++
step
,
5
,
"step 1.1.2.1"
@
wait
400
,
->
@
test
.
assertEquals
++
step
,
6
,
"step 1.2"
@
test
.
assertEquals
++
step
,
4
,
"step 1.1.1.1"
@
then
->
@
test
.
assertEquals
++
step
,
5
,
"step 1.1.2.1"
@
wait
400
,
->
@
test
.
assertEquals
++
step
,
6
,
"step 1.2"
casper
.
wait
200
,
->
@
test
.
assertEquals
++
step
,
7
,
"step 2"
casper
.
wait
200
,
->
@
test
.
assertEquals
++
step
,
7
,
"step 2"
casper
.
waitForSelector
(
'#noneExistingSelector'
->
@
test
.
fail
"should run into timeout"
->
@
test
.
assertEquals
++
step
,
8
,
"step 3 sucessfully timed out"
1000
)
casper
.
then
->
@
test
.
assertEquals
++
step
,
9
,
"step 4"
casper
.
waitForSelector
(
'#noneExistingSelector'
->
@
test
.
fail
"should run into timeout"
->
@
test
.
assertEquals
++
step
,
8
,
"step 3 sucessfully timed out"
1000
)
casper
.
then
->
@
test
.
assertEquals
++
step
,
9
,
"step 4"
@
wait
300
,
->
@
test
.
assertEquals
++
step
,
10
,
"step 4.1"
@
wait
300
,
->
@
test
.
assertEquals
++
step
,
10
,
"step 4.1"
@
wait
300
,
->
@
test
.
assertEquals
++
step
,
11
,
"step 4.1.1"
@
wait
100
,
->
@
test
.
assertEquals
++
step
,
12
,
"step 5.2"
@
test
.
assertEquals
++
step
,
11
,
"step 4.1.1"
@
wait
100
,
->
@
test
.
assertEquals
++
step
,
12
,
"step 5.2"
casper
.
then
->
@
test
.
assertEquals
++
step
,
13
,
"last step"
casper
.
then
->
@
test
.
assertEquals
++
step
,
13
,
"last step"
casper
.
run
(
->
@
test
.
done
())
\ No newline at end of file
casper
.
run
(
->
@
test
.
done
())
\ No newline at end of file
...
...
tests/suites/casper/formfill.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/form.html'
,
function
(
self
)
{
t
.
comment
(
'Casper.fill()'
);
self
.
fill
(
'form[action="result.html"]'
,
{
email
:
'chuck@norris.com'
,
content
:
'Am watching thou'
,
check
:
true
,
choice
:
'no'
,
topic
:
'bar'
,
file
:
phantom
.
libraryPath
+
'/README.md'
,
'checklist[]'
:
[
'1'
,
'3'
]
});
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="email"]'
).
value
;
},
'chuck@norris.com'
,
'Casper.fill() can fill an input[type=text] form field'
);
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'textarea[name="content"]'
).
value
;
},
'Am watching thou'
,
'Casper.fill() can fill a textarea form field'
);
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'select[name="topic"]'
).
value
;
},
'bar'
,
'Casper.fill() can pick a value from a select form field'
);
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="check"]'
).
checked
;
},
true
,
'Casper.fill() can check a form checkbox'
);
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="choice"][value="no"]'
).
checked
;
},
true
,
'Casper.fill() can check a form radio button 1/2'
);
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="choice"][value="yes"]'
).
checked
;
},
false
,
'Casper.fill() can check a form radio button 2/2'
);
t
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="file"]'
).
files
.
length
===
1
;
},
true
,
'Casper.fill() can select a file to upload'
);
t
.
assertEvalEquals
(
function
()
{
return
(
document
.
querySelector
(
'input[name="checklist[]"][value="1"]'
).
checked
&&
!
document
.
querySelector
(
'input[name="checklist[]"][value="2"]'
).
checked
&&
document
.
querySelector
(
'input[name="checklist[]"][value="3"]'
).
checked
);
},
true
,
'Casper.fill() can fill a list of checkboxes'
);
self
.
click
(
'input[type="submit"]'
);
casper
.
start
(
'tests/site/form.html'
,
function
()
{
this
.
test
.
comment
(
'Casper.fill()'
);
this
.
fill
(
'form[action="result.html"]'
,
{
email
:
'chuck@norris.com'
,
content
:
'Am watching thou'
,
check
:
true
,
choice
:
'no'
,
topic
:
'bar'
,
file
:
phantom
.
libraryPath
+
'/README.md'
,
'checklist[]'
:
[
'1'
,
'3'
]
});
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="email"]'
).
value
;
},
'chuck@norris.com'
,
'Casper.fill() can fill an input[type=text] form field'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'textarea[name="content"]'
).
value
;
},
'Am watching thou'
,
'Casper.fill() can fill a textarea form field'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'select[name="topic"]'
).
value
;
},
'bar'
,
'Casper.fill() can pick a value from a select form field'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="check"]'
).
checked
;
},
true
,
'Casper.fill() can check a form checkbox'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="choice"][value="no"]'
).
checked
;
},
true
,
'Casper.fill() can check a form radio button 1/2'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="choice"][value="yes"]'
).
checked
;
},
false
,
'Casper.fill() can check a form radio button 2/2'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="file"]'
).
files
.
length
===
1
;
},
true
,
'Casper.fill() can select a file to upload'
);
this
.
test
.
assertEvalEquals
(
function
()
{
return
(
document
.
querySelector
(
'input[name="checklist[]"][value="1"]'
).
checked
&&
!
document
.
querySelector
(
'input[name="checklist[]"][value="2"]'
).
checked
&&
document
.
querySelector
(
'input[name="checklist[]"][value="3"]'
).
checked
);
},
true
,
'Casper.fill() can fill a list of checkboxes'
);
this
.
click
(
'input[type="submit"]'
);
});
casper
.
then
(
function
(
self
)
{
t
.
comment
(
'Form submitted'
);
t
.
assertUrlMatch
(
/email=chuck@norris.com/
,
'Casper.fill() input[type=email] field was submitted'
);
t
.
assertUrlMatch
(
/content=Am
\+
watching
\+
thou/
,
'Casper.fill() textarea field was submitted'
);
t
.
assertUrlMatch
(
/check=on/
,
'Casper.fill() input[type=checkbox] field was submitted'
);
t
.
assertUrlMatch
(
/choice=no/
,
'Casper.fill() input[type=radio] field was submitted'
);
t
.
assertUrlMatch
(
/topic=bar/
,
'Casper.fill() select field was submitted'
);
});
casper
.
then
(
function
(
)
{
this
.
tes
t
.
comment
(
'Form submitted'
);
this
.
tes
t
.
assertUrlMatch
(
/email=chuck@norris.com/
,
'Casper.fill() input[type=email] field was submitted'
);
this
.
tes
t
.
assertUrlMatch
(
/content=Am
\+
watching
\+
thou/
,
'Casper.fill() textarea field was submitted'
);
this
.
tes
t
.
assertUrlMatch
(
/check=on/
,
'Casper.fill() input[type=checkbox] field was submitted'
);
this
.
tes
t
.
assertUrlMatch
(
/choice=no/
,
'Casper.fill() input[type=radio] field was submitted'
);
this
.
tes
t
.
assertUrlMatch
(
/topic=bar/
,
'Casper.fill() select field was submitted'
);
});
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/global.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/global.html'
,
function
(
self
)
{
t
.
comment
(
'Casper.getGlobal()'
);
t
.
assertEquals
(
self
.
getGlobal
(
'myGlobal'
),
'awesome string'
,
'Casper.getGlobal() can retrieve a remote global variable'
);
t
.
assertRaises
(
self
.
getGlobal
,
[
'myUnencodableGlobal'
],
'Casper.getGlobal() does not fail trying to encode an unencodable global'
);
});
casper
.
start
(
'tests/site/global.html'
,
function
()
{
this
.
test
.
comment
(
'Casper.getGlobal()'
);
this
.
test
.
assertEquals
(
this
.
getGlobal
(
'myGlobal'
),
'awesome string'
,
'Casper.getGlobal() can retrieve a remote global variable'
);
this
.
test
.
assertRaises
(
this
.
getGlobal
,
[
'myUnencodableGlobal'
],
'Casper.getGlobal() does not fail trying to encode an unencodable global'
);
});
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/history.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/page1.html'
);
casper
.
thenOpen
(
'tests/site/page2.html'
);
casper
.
thenOpen
(
'tests/site/page3.html'
);
casper
.
start
(
'tests/site/page1.html'
);
casper
.
thenOpen
(
'tests/site/page2.html'
);
casper
.
thenOpen
(
'tests/site/page3.html'
);
casper
.
back
();
casper
.
then
(
function
(
self
)
{
t
.
comment
(
'navigating history backward'
);
t
.
assertMatch
(
self
.
getCurrentUrl
(),
/tests
\/
site
\/
page2
\.
html$/
,
'Casper.back() can go back an history step'
);
});
casper
.
back
();
casper
.
then
(
function
(
)
{
this
.
tes
t
.
comment
(
'navigating history backward'
);
this
.
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/tests
\/
site
\/
page2
\.
html$/
,
'Casper.back() can go back an history step'
);
});
casper
.
forward
();
casper
.
then
(
function
(
self
)
{
t
.
comment
(
'navigating history forward'
);
t
.
assertMatch
(
self
.
getCurrentUrl
(),
/tests
\/
site
\/
page3
\.
html$/
,
'Casper.forward() can go forward an history step'
);
});
casper
.
forward
();
casper
.
then
(
function
(
)
{
this
.
tes
t
.
comment
(
'navigating history forward'
);
this
.
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/tests
\/
site
\/
page3
\.
html$/
,
'Casper.forward() can go forward an history step'
);
});
casper
.
run
(
function
(
self
)
{
t
.
assert
(
self
.
history
.
length
>
0
,
'Casper.history contains urls'
);
t
.
assertMatch
(
self
.
history
[
0
],
/tests
\/
site
\/
page1
\.
html$/
,
'Casper.history has the correct first url'
);
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
assert
(
this
.
history
.
length
>
0
,
'Casper.history contains urls'
);
this
.
test
.
assertMatch
(
this
.
history
[
0
],
/tests
\/
site
\/
page1
\.
html$/
,
'Casper.history has the correct first url'
);
this
.
test
.
done
();
});
...
...
tests/suites/casper/hooks.js
View file @
90f3373
(
function
(
t
)
{
// Casper.options.onStepComplete
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
self
.
options
.
onStepComplete
=
function
(
self
,
stepResult
)
{
t
.
comment
(
'Casper.options.onStepComplete()'
);
t
.
assertEquals
(
stepResult
,
'ok'
,
'Casper.options.onStepComplete() is called on step complete'
);
self
.
options
.
onStepComplete
=
null
;
};
return
'ok'
;
});
// Dear curious test reader,
// The on* family of methods is considered deprecated since 0.6.0; please use events instead
// Casper.options.onResourceRequested & Casper.options.onResourceReceived
casper
.
then
(
function
(
self
)
{
self
.
options
.
onResourceReceived
=
function
(
self
,
resource
)
{
t
.
comment
(
'Casper.options.onResourceReceived()'
);
t
.
assertType
(
resource
,
'object'
,
'Casper.options.onResourceReceived() retrieve a resource object'
);
t
.
assert
(
'status'
in
resource
,
'Casper.options.onResourceReceived() retrieve a valid resource object'
);
self
.
options
.
onResourceReceived
=
null
;
};
self
.
options
.
onResourceRequested
=
function
(
self
,
request
)
{
t
.
comment
(
'Casper.options.onResourceRequested()'
);
t
.
assertType
(
request
,
'object'
,
'Casper.options.onResourceRequested() retrieve a request object'
);
t
.
assert
(
'method'
in
request
,
'Casper.options.onResourceRequested() retrieve a valid request object'
);
self
.
options
.
onResourceRequested
=
null
;
};
self
.
thenOpen
(
'tests/site/page1.html'
);
});
// Casper.options.onStepComplete
casper
.
start
(
'tests/site/index.html'
,
function
()
{
this
.
options
.
onStepComplete
=
function
(
self
,
stepResult
)
{
this
.
test
.
comment
(
'Casper.options.onStepComplete()'
);
this
.
test
.
assertEquals
(
stepResult
,
'ok'
,
'Casper.options.onStepComplete() is called on step complete'
);
self
.
options
.
onStepComplete
=
null
;
};
return
'ok'
;
});
// Casper.options.onAlert()
casper
.
then
(
function
(
self
)
{
self
.
options
.
onAlert
=
function
(
self
,
message
)
{
t
.
assertEquals
(
message
,
'plop'
,
'Casper.options.onAlert() can intercept an alert message'
);
};
}).
thenOpen
(
'tests/site/alert.html'
).
thenClick
(
'button'
,
function
(
self
)
{
self
.
options
.
onAlert
=
null
;
});
// Casper.options.onResourceRequested & Casper.options.onResourceReceived
casper
.
then
(
function
()
{
this
.
options
.
onResourceReceived
=
function
(
self
,
resource
)
{
this
.
test
.
comment
(
'Casper.options.onResourceReceived()'
);
this
.
test
.
assertType
(
resource
,
'object'
,
'Casper.options.onResourceReceived() retrieve a resource object'
);
this
.
test
.
assert
(
'status'
in
resource
,
'Casper.options.onResourceReceived() retrieve a valid resource object'
);
self
.
options
.
onResourceReceived
=
null
;
};
this
.
options
.
onResourceRequested
=
function
(
self
,
request
)
{
this
.
test
.
comment
(
'Casper.options.onResourceRequested()'
);
this
.
test
.
assertType
(
request
,
'object'
,
'Casper.options.onResourceRequested() retrieve a request object'
);
this
.
test
.
assert
(
'method'
in
request
,
'Casper.options.onResourceRequested() retrieve a valid request object'
);
self
.
options
.
onResourceRequested
=
null
;
};
this
.
thenOpen
(
'tests/site/page1.html'
);
});
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
// Casper.options.onAlert()
casper
.
then
(
function
()
{
this
.
options
.
onAlert
=
function
(
self
,
message
)
{
self
.
test
.
assertEquals
(
message
,
'plop'
,
'Casper.options.onAlert() can intercept an alert message'
);
};
}).
thenOpen
(
'tests/site/alert.html'
).
thenClick
(
'button'
,
function
()
{
this
.
options
.
onAlert
=
null
;
});
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/logging.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/index.html'
);
casper
.
start
(
'tests/site/index.html'
);
var
oldLevel
=
casper
.
options
.
logLevel
;
var
oldLevel
=
casper
.
options
.
logLevel
;
casper
.
options
.
logLevel
=
'info'
;
casper
.
options
.
verbose
=
false
;
casper
.
options
.
logLevel
=
'info'
;
casper
.
options
.
verbose
=
false
;
t
.
comment
(
'Casper.log()'
);
casper
.
log
(
'foo'
,
'info'
);
t
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'foo'
&&
e
.
level
===
'info'
;
}),
'Casper.log() adds a log entry'
);
casper
.
tes
t
.
comment
(
'Casper.log()'
);
casper
.
log
(
'foo'
,
'info'
);
casper
.
tes
t
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'foo'
&&
e
.
level
===
'info'
;
}),
'Casper.log() adds a log entry'
);
casper
.
options
.
logLevel
=
oldLevel
;
casper
.
options
.
verbose
=
true
;
casper
.
options
.
logLevel
=
oldLevel
;
casper
.
options
.
verbose
=
true
;
casper
.
then
(
function
(
self
)
{
var
oldLevel
=
casper
.
options
.
logLevel
;
casper
.
options
.
logLevel
=
'debug'
;
casper
.
options
.
verbose
=
false
;
casper
.
evaluate
(
function
()
{
__utils__
.
log
(
'debug message'
);
__utils__
.
log
(
'info message'
,
'info'
);
});
t
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'debug message'
&&
e
.
level
===
'debug'
&&
e
.
space
===
'remote'
;
}),
'ClientUtils.log() adds a log entry'
);
t
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'info message'
&&
e
.
level
===
'info'
&&
e
.
space
===
'remote'
;
}),
'ClientUtils.log() adds a log entry at a given level'
);
casper
.
options
.
logLevel
=
oldLevel
;
casper
.
options
.
verbose
=
true
;
casper
.
then
(
function
()
{
var
oldLevel
=
casper
.
options
.
logLevel
;
casper
.
options
.
logLevel
=
'debug'
;
casper
.
options
.
verbose
=
false
;
casper
.
evaluate
(
function
()
{
__utils__
.
log
(
'debug message'
);
__utils__
.
log
(
'info message'
,
'info'
);
});
this
.
test
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'debug message'
&&
e
.
level
===
'debug'
&&
e
.
space
===
'remote'
;
}),
'ClientUtils.log() adds a log entry'
);
this
.
test
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'info message'
&&
e
.
level
===
'info'
&&
e
.
space
===
'remote'
;
}),
'ClientUtils.log() adds a log entry at a given level'
);
casper
.
options
.
logLevel
=
oldLevel
;
casper
.
options
.
verbose
=
true
;
});
casper
.
run
(
function
(
self
)
{
t
.
assertEquals
(
self
.
result
.
log
.
length
,
3
,
'Casper.log() logged messages'
);
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
assertEquals
(
this
.
result
.
log
.
length
,
3
,
'Casper.log() logged messages'
);
this
.
test
.
done
();
});
...
...
tests/suites/casper/open.js
View file @
90f3373
(
function
(
t
)
{
var
current
=
0
,
tests
=
[
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"get"
},
"Casper.open() used the expected GET settings"
);
},
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"post"
,
data
:
"plop=42&chuck=norris"
},
"Casper.open() used the expected POST settings"
);
},
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"put"
,
data
:
"plop=42&chuck=norris"
},
"Casper.open() used the expected PUT settings"
);
},
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"get"
,
username
:
'bob'
,
password
:
'sinclar'
},
"Casper.open() used the expected HTTP auth settings"
);
}
];
var
t
=
casper
.
test
,
current
=
0
,
tests
=
[
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"get"
},
"Casper.open() used the expected GET settings"
);
},
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"post"
,
data
:
"plop=42&chuck=norris"
},
"Casper.open() used the expected POST settings"
);
},
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"put"
,
data
:
"plop=42&chuck=norris"
},
"Casper.open() used the expected PUT settings"
);
},
function
(
settings
)
{
t
.
assertEquals
(
settings
,
{
method
:
"get"
,
username
:
'bob'
,
password
:
'sinclar'
},
"Casper.open() used the expected HTTP auth settings"
);
}
];
casper
.
start
();
casper
.
start
();
casper
.
on
(
'open'
,
function
(
url
,
settings
)
{
tests
[
current
++
](
settings
);
});
casper
.
on
(
'open'
,
function
(
url
,
settings
)
{
tests
[
current
++
](
settings
);
});
// GET
casper
.
open
(
'tests/site/index.html'
).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using GET"
);
});
// GET
casper
.
open
(
'tests/site/index.html'
).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using GET"
);
});
// POST
casper
.
open
(
'tests/site/index.html'
,
{
method
:
'post'
,
data
:
{
plop
:
42
,
chuck
:
'norris'
}
}).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using POST"
);
});
// POST
casper
.
open
(
'tests/site/index.html'
,
{
method
:
'post'
,
data
:
{
plop
:
42
,
chuck
:
'norris'
}
}).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using POST"
);
});
// PUT
casper
.
open
(
'tests/site/index.html'
,
{
method
:
'put'
,
data
:
{
plop
:
42
,
chuck
:
'norris'
}
}).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using PUT"
);
});
// PUT
casper
.
open
(
'tests/site/index.html'
,
{
method
:
'put'
,
data
:
{
plop
:
42
,
chuck
:
'norris'
}
}).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using PUT"
);
});
// HTTP Auth
casper
.
open
(
'tests/site/index.html'
,
{
method
:
'get'
,
username
:
'bob'
,
password
:
'sinclar'
}).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using HTTP auth"
);
});
// HTTP Auth
casper
.
open
(
'tests/site/index.html'
,
{
method
:
'get'
,
username
:
'bob'
,
password
:
'sinclar'
}).
then
(
function
()
{
t
.
pass
(
"Casper.open() can open and load a location using HTTP auth"
);
});
casper
.
run
(
function
()
{
this
.
removeAllListeners
(
'open'
);
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
removeAllListeners
(
'open'
);
t
.
done
();
});
...
...
tests/suites/casper/resources.coffee
View file @
90f3373
do
(
casper
)
->
casper
.
start
"tests/site/resources.html"
,
->
@
test
.
assertEquals
@
resources
.
length
,
1
,
"only one resource found"
onTime
=
->
@
test
.
assertEquals
(
@
resources
.
length
2
"two resources found"
)
@
test
.
assertResourceExists
(
/phantom\.png/i
"phantom image found via test RegExp"
)
@
test
.
assertResourceExists
(
(
res
)
->
res
.
url
.
match
"phantom.png"
"phantom image found via test Function"
)
@
test
.
assertResourceExists
(
"phantom.png"
"phantom image found via test String"
)
onTimeout
=
->
@
test
.
fail
"waitForResource timeout occured"
@
waitForResource
"phantom.png"
,
onTime
,
onTimeout
casper
.
start
"tests/site/resources.html"
,
->
@
test
.
assertEquals
@
resources
.
length
,
1
,
"only one resource found"
onTime
=
->
@
test
.
assertEquals
(
@
resources
.
length
2
"two resources found"
)
@
test
.
assertResourceExists
(
/phantom\.png/i
"phantom image found via test RegExp"
)
@
test
.
assertResourceExists
(
(
res
)
->
res
.
url
.
match
"phantom.png"
"phantom image found via test Function"
)
@
test
.
assertResourceExists
(
"phantom.png"
"phantom image found via test String"
)
onTimeout
=
->
@
test
.
fail
"waitForResource timeout occured"
@
waitForResource
"phantom.png"
,
onTime
,
onTimeout
casper
.
run
(
->
@
test
.
done
())
casper
.
run
(
->
@
test
.
done
())
...
...
tests/suites/casper/start.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Casper.start()'
);
casper
.
test
.
comment
(
'Casper.start()'
);
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
t
.
pass
(
'Casper.start() can chain a next step'
);
t
.
assertTitle
(
'CasperJS test index'
,
'Casper.start() opened the passed url'
);
t
.
assertEval
(
function
()
{
return
typeof
(
__utils__
)
===
"object"
;
},
'Casper.start() injects ClientUtils instance within remote DOM'
);
});
casper
.
start
(
'tests/site/index.html'
,
function
(
)
{
this
.
tes
t
.
pass
(
'Casper.start() can chain a next step'
);
this
.
tes
t
.
assertTitle
(
'CasperJS test index'
,
'Casper.start() opened the passed url'
);
this
.
tes
t
.
assertEval
(
function
()
{
return
typeof
(
__utils__
)
===
"object"
;
},
'Casper.start() injects ClientUtils instance within remote DOM'
);
});
t
.
assert
(
casper
.
started
,
'Casper.start() started'
);
casper
.
tes
t
.
assert
(
casper
.
started
,
'Casper.start() started'
);
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/steps.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Casper.then()'
);
casper
.
test
.
comment
(
'Casper.then()'
);
casper
.
start
(
'tests/site/index.html'
);
casper
.
start
(
'tests/site/index.html'
);
var
nsteps
=
casper
.
steps
.
length
;
var
nsteps
=
casper
.
steps
.
length
;
casper
.
then
(
function
(
self
)
{
t
.
assertTitle
(
'CasperJS test index'
,
'Casper.then() added a new step'
);
});
casper
.
then
(
function
(
self
)
{
this
.
tes
t
.
assertTitle
(
'CasperJS test index'
,
'Casper.then() added a new step'
);
});
t
.
assertEquals
(
casper
.
steps
.
length
,
nsteps
+
1
,
'Casper.then() can add a new step'
);
casper
.
tes
t
.
assertEquals
(
casper
.
steps
.
length
,
nsteps
+
1
,
'Casper.then() can add a new step'
);
t
.
comment
(
'Casper.thenOpen()'
);
casper
.
tes
t
.
comment
(
'Casper.thenOpen()'
);
casper
.
thenOpen
(
'tests/site/test.html'
);
casper
.
thenOpen
(
'tests/site/test.html'
);
t
.
assertEquals
(
casper
.
steps
.
length
,
nsteps
+
2
,
'Casper.thenOpen() can add a new step'
);
casper
.
tes
t
.
assertEquals
(
casper
.
steps
.
length
,
nsteps
+
2
,
'Casper.thenOpen() can add a new step'
);
casper
.
thenOpen
(
'tests/site/test.html'
,
function
(
self
)
{
t
.
assertTitle
(
'CasperJS test target'
,
'Casper.thenOpen() opened a location and executed a step'
);
});
casper
.
thenOpen
(
'tests/site/test.html'
,
function
(
)
{
this
.
tes
t
.
assertTitle
(
'CasperJS test target'
,
'Casper.thenOpen() opened a location and executed a step'
);
});
t
.
assertEquals
(
casper
.
steps
.
length
,
nsteps
+
4
,
'Casper.thenOpen() can add a new step for opening, plus another step'
);
casper
.
tes
t
.
assertEquals
(
casper
.
steps
.
length
,
nsteps
+
4
,
'Casper.thenOpen() can add a new step for opening, plus another step'
);
t
.
comment
(
'Casper.each()'
);
casper
.
each
([
1
,
2
,
3
],
function
(
self
,
item
,
i
)
{
self
.
test
.
assertEquals
(
i
,
item
-
1
,
'Casper.each() passes a contextualized index'
);
});
casper
.
tes
t
.
comment
(
'Casper.each()'
);
casper
.
each
([
1
,
2
,
3
],
function
(
self
,
item
,
i
)
{
self
.
test
.
assertEquals
(
i
,
item
-
1
,
'Casper.each() passes a contextualized index'
);
});
casper
.
run
(
function
()
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/viewport.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Casper.viewport()'
);
casper
.
test
.
comment
(
'Casper.viewport()'
);
casper
.
start
();
casper
.
start
();
casper
.
viewport
(
1337
,
999
);
casper
.
viewport
(
1337
,
999
);
t
.
assertEquals
(
casper
.
page
.
viewportSize
.
width
,
1337
,
'Casper.viewport() can change the width of page viewport'
);
t
.
assertEquals
(
casper
.
page
.
viewportSize
.
height
,
999
,
'Casper.viewport() can change the height of page viewport'
);
t
.
assertRaises
(
casper
.
viewport
,
[
'a'
,
'b'
],
'Casper.viewport() validates viewport size data'
);
casper
.
tes
t
.
assertEquals
(
casper
.
page
.
viewportSize
.
width
,
1337
,
'Casper.viewport() can change the width of page viewport'
);
casper
.
tes
t
.
assertEquals
(
casper
.
page
.
viewportSize
.
height
,
999
,
'Casper.viewport() can change the height of page viewport'
);
casper
.
tes
t
.
assertRaises
(
casper
.
viewport
,
[
'a'
,
'b'
],
'Casper.viewport() validates viewport size data'
);
t
.
done
();
})(
casper
.
test
);
casper
.
test
.
done
();
...
...
tests/suites/casper/visible.js
View file @
90f3373
(
function
(
t
)
{
casper
.
start
(
'tests/site/visible.html'
,
function
(
self
)
{
self
.
test
.
comment
(
'Casper.visible()'
);
self
.
test
.
assert
(
self
.
visible
(
'#img1'
),
'Casper.visible() can detect if an element is visible'
);
self
.
test
.
assert
(
!
self
.
visible
(
'#img2'
),
'Casper.visible() can detect if an element is invisible'
);
self
.
test
.
assert
(
!
self
.
visible
(
'#img3'
),
'Casper.visible() can detect if an element is invisible'
);
self
.
waitWhileVisible
(
'#img1'
,
function
(
self
)
{
self
.
test
.
comment
(
'Casper.waitWhileVisible()'
);
self
.
test
.
pass
(
'Casper.waitWhileVisible() can wait while an element is visible'
);
},
function
(
self
)
{
self
.
test
.
comment
(
'Casper.waitWhileVisible()'
);
self
.
test
.
fail
(
'Casper.waitWhileVisible() can wait while an element is visible'
);
},
2000
);
});
casper
.
start
(
'tests/site/visible.html'
,
function
()
{
this
.
test
.
comment
(
'Casper.visible()'
);
this
.
test
.
assert
(
this
.
visible
(
'#img1'
),
'Casper.visible() can detect if an element is visible'
);
this
.
test
.
assert
(
!
this
.
visible
(
'#img2'
),
'Casper.visible() can detect if an element is invisible'
);
this
.
test
.
assert
(
!
this
.
visible
(
'#img3'
),
'Casper.visible() can detect if an element is invisible'
);
this
.
waitWhileVisible
(
'#img1'
,
function
()
{
this
.
test
.
comment
(
'Casper.waitWhileVisible()'
);
this
.
test
.
pass
(
'Casper.waitWhileVisible() can wait while an element is visible'
);
},
function
()
{
this
.
test
.
comment
(
'Casper.waitWhileVisible()'
);
this
.
test
.
fail
(
'Casper.waitWhileVisible() can wait while an element is visible'
);
},
2000
);
});
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/casper/wait.js
View file @
90f3373
(
function
(
t
)
{
var
waitStart
;
var
waitStart
;
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
waitStart
=
new
Date
().
getTime
();
});
casper
.
start
(
'tests/site/index.html'
,
function
(
)
{
waitStart
=
new
Date
().
getTime
();
});
casper
.
wait
(
1000
,
function
(
self
)
{
self
.
test
.
comment
(
'Casper.wait()'
);
self
.
test
.
assert
(
new
Date
().
getTime
()
-
waitStart
>
1000
,
'Casper.wait() can wait for a given amount of time'
);
// Casper.waitFor()
casper
.
thenOpen
(
'tests/site/waitFor.html'
,
function
(
self
)
{
casper
.
test
.
comment
(
'Casper.waitFor()'
);
self
.
waitFor
(
function
(
self
)
{
return
self
.
evaluate
(
function
()
{
return
document
.
querySelectorAll
(
'li'
).
length
===
4
;
});
},
function
(
self
)
{
self
.
test
.
pass
(
'Casper.waitFor() can wait for something to happen'
);
},
function
(
self
)
{
self
.
test
.
fail
(
'Casper.waitFor() can wait for something to happen'
);
casper
.
wait
(
1000
,
function
()
{
this
.
test
.
comment
(
'Casper.wait()'
);
this
.
test
.
assert
(
new
Date
().
getTime
()
-
waitStart
>
1000
,
'Casper.wait() can wait for a given amount of time'
);
// Casper.waitFor()
casper
.
thenOpen
(
'tests/site/waitFor.html'
,
function
()
{
this
.
test
.
comment
(
'Casper.waitFor()'
);
this
.
waitFor
(
function
()
{
return
this
.
evaluate
(
function
()
{
return
document
.
querySelectorAll
(
'li'
).
length
===
4
;
});
},
function
()
{
this
.
test
.
pass
(
'Casper.waitFor() can wait for something to happen'
);
},
function
()
{
this
.
test
.
fail
(
'Casper.waitFor() can wait for something to happen'
);
});
});
});
casper
.
run
(
function
(
self
)
{
t
.
done
();
});
})(
casper
.
test
);
casper
.
run
(
function
()
{
this
.
test
.
done
();
});
...
...
tests/suites/cli.js
View file @
90f3373
(
function
(
t
)
{
var
cli
=
require
(
'cli'
);
var
cli
=
require
(
'cli'
),
t
=
casper
.
test
;
t
.
comment
(
'parse(), get(), has()'
);
t
.
comment
(
'parse(), get(), has()'
);
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
0
),
undefined
,
'parse() does not return inexistant positional arg'
);
t
.
assertEquals
(
parsed
.
get
(
'blah'
),
undefined
,
'parse() does not return inexistant option'
);
t
.
assert
(
!
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
!
parsed
.
has
(
'blah'
),
'has() checks if an option is set'
);
})(
cli
.
parse
([]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
0
),
undefined
,
'parse() does not return inexistant positional arg'
);
t
.
assertEquals
(
parsed
.
get
(
'blah'
),
undefined
,
'parse() does not return inexistant option'
);
t
.
assert
(
!
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
!
parsed
.
has
(
'blah'
),
'has() checks if an option is set'
);
})(
cli
.
parse
([]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[
'foo'
,
'bar'
],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
0
),
'foo'
,
'parse() retrieve first positional arg'
);
t
.
assertEquals
(
parsed
.
get
(
1
),
'bar'
,
'parse() retrieve second positional arg'
);
t
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
.
assert
(
!
parsed
.
has
(
2
),
'has() checks if an arg is not set'
);
})(
cli
.
parse
([
'foo'
,
'bar'
]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[
'foo'
,
'bar'
],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
0
),
'foo'
,
'parse() retrieve first positional arg'
);
t
.
assertEquals
(
parsed
.
get
(
1
),
'bar'
,
'parse() retrieve second positional arg'
);
t
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
.
assert
(
!
parsed
.
has
(
2
),
'has() checks if an arg is not set'
);
})(
cli
.
parse
([
'foo'
,
'bar'
]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
foo
:
'bar'
,
baz
:
true
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'foo'
),
'bar'
,
'parse() retrieve an option value'
);
t
.
assert
(
parsed
.
get
(
'baz'
),
'parse() retrieve boolean option flag'
);
t
.
assert
(
parsed
.
has
(
"foo"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"baz"
),
'has() checks if an option is set'
);
})(
cli
.
parse
([
'--foo=bar'
,
'--baz'
]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
foo
:
'bar'
,
baz
:
true
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'foo'
),
'bar'
,
'parse() retrieve an option value'
);
t
.
assert
(
parsed
.
get
(
'baz'
),
'parse() retrieve boolean option flag'
);
t
.
assert
(
parsed
.
has
(
"foo"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"baz"
),
'has() checks if an option is set'
);
})(
cli
.
parse
([
'--foo=bar'
,
'--baz'
]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
'&é"à'
:
42
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'&é"à'
),
42
,
'parse() handles options with exotic names'
);
t
.
assert
(
parsed
.
has
(
'&é"à'
),
'has() checks if an option is set'
);
})(
cli
.
parse
([
'--&é"à=42'
]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
'&é"à'
:
42
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'&é"à'
),
42
,
'parse() handles options with exotic names'
);
t
.
assert
(
parsed
.
has
(
'&é"à'
),
'has() checks if an option is set'
);
})(
cli
.
parse
([
'--&é"à=42'
]));
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[
'foo & bar'
,
'baz & boz'
],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
universe
:
42
,
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'universe'
),
42
,
'parse() can cast a numeric option value'
);
t
.
assertEquals
(
parsed
.
get
(
'lap'
),
13.37
,
'parse() can cast a float option value'
);
t
.
assertType
(
parsed
.
get
(
'lap'
),
"number"
,
'parse() can cast a boolean value'
);
t
.
assert
(
parsed
.
get
(
'chucknorris'
),
'parse() can get a flag value by its option name'
);
t
.
assertType
(
parsed
.
get
(
'oops'
),
"boolean"
,
'parse() can cast a boolean value'
);
t
.
assertEquals
(
parsed
.
get
(
'oops'
),
false
,
'parse() can cast a boolean value'
);
t
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
"universe"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"lap"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"chucknorris"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"oops"
),
'has() checks if an option is set'
);
(
function
(
parsed
)
{
t
.
assertEquals
(
parsed
.
args
,
[
'foo & bar'
,
'baz & boz'
],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
universe
:
42
,
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'universe'
),
42
,
'parse() can cast a numeric option value'
);
t
.
assertEquals
(
parsed
.
get
(
'lap'
),
13.37
,
'parse() can cast a float option value'
);
t
.
assertType
(
parsed
.
get
(
'lap'
),
"number"
,
'parse() can cast a boolean value'
);
t
.
assert
(
parsed
.
get
(
'chucknorris'
),
'parse() can get a flag value by its option name'
);
t
.
assertType
(
parsed
.
get
(
'oops'
),
"boolean"
,
'parse() can cast a boolean value'
);
t
.
assertEquals
(
parsed
.
get
(
'oops'
),
false
,
'parse() can cast a boolean value'
);
t
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
"universe"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"lap"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"chucknorris"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"oops"
),
'has() checks if an option is set'
);
t
.
comment
(
'drop()'
);
t
.
comment
(
'drop()'
);
parsed
.
drop
(
0
);
t
.
assertEquals
(
parsed
.
get
(
0
),
'baz & boz'
,
'drop() dropped arg'
);
parsed
.
drop
(
"universe"
);
t
.
assert
(
!
parsed
.
has
(
"universe"
),
'drop() dropped option'
);
t
.
assertEquals
(
parsed
.
args
,
[
"baz & boz"
],
'drop() did not affect other args'
);
t
.
assertEquals
(
parsed
.
options
,
{
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'drop() did not affect other options'
);
})(
cli
.
parse
([
'foo & bar'
,
'baz & boz'
,
'--universe=42'
,
'--lap=13.37'
,
'--chucknorris'
,
'--oops=false'
]));
parsed
.
drop
(
0
);
t
.
assertEquals
(
parsed
.
get
(
0
),
'baz & boz'
,
'drop() dropped arg'
);
parsed
.
drop
(
"universe"
);
t
.
assert
(
!
parsed
.
has
(
"universe"
),
'drop() dropped option'
);
t
.
assertEquals
(
parsed
.
args
,
[
"baz & boz"
],
'drop() did not affect other args'
);
t
.
assertEquals
(
parsed
.
options
,
{
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'drop() did not affect other options'
);
})(
cli
.
parse
([
'foo & bar'
,
'baz & boz'
,
'--universe=42'
,
'--lap=13.37'
,
'--chucknorris'
,
'--oops=false'
]));
t
.
done
();
})(
casper
.
test
);
t
.
done
();
...
...
tests/suites/coffee.coffee
View file @
90f3373
"A small subset of the run.js written in coffeescript"
do
(
casper
)
->
steps
=
0
steps
=
0
casper
.
options
.
onStepComplete
=
->
steps
++
casper
.
options
.
onStepComplete
=
->
steps
++
casper
.
start
"tests/site/index.html"
,
->
@
test
.
assertTitle
"CasperJS test index"
,
"Casper.start() casper can start itself an open an url"
@
test
.
assertEquals
@
fetchText
(
"ul li"
),
"onetwothree"
,
"Casper.fetchText() can retrieves text contents"
@
click
"a[href=
\"
test.html
\"
]"
casper
.
start
"tests/site/index.html"
,
->
@
test
.
assertTitle
"CasperJS test index"
,
"Casper.start() casper can start itself an open an url"
@
test
.
assertEquals
@
fetchText
(
"ul li"
),
"onetwothree"
,
"Casper.fetchText() can retrieves text contents"
@
click
"a[href=
\"
test.html
\"
]"
casper
.
then
->
@
test
.
assertTitle
"CasperJS test target"
,
"Casper.click() casper can click on a text link"
@
click
"a[href=
\"
form.html
\"
]"
casper
.
then
->
@
test
.
assertTitle
"CasperJS test target"
,
"Casper.click() casper can click on a text link"
@
click
"a[href=
\"
form.html
\"
]"
casper
.
run
->
@
test
.
assertEquals
steps
,
3
,
"Casper.options.onStepComplete() is called on step complete"
@
options
.
onStepComplete
=
null
@
test
.
done
()
casper
.
run
->
@
test
.
assertEquals
steps
,
3
,
"Casper.options.onStepComplete() is called on step complete"
@
options
.
onStepComplete
=
null
@
test
.
done
()
...
...
tests/suites/error.js
View file @
90f3373
(
function
(
t
)
{
var
error
;
var
error
;
function
foo
()
{
bar
();
}
function
foo
()
{
bar
();
}
function
bar
()
{
throw
new
CasperError
(
'bar'
);
}
function
bar
()
{
throw
new
CasperError
(
'bar'
);
}
try
{
foo
();
}
catch
(
e
)
{
error
=
e
;
}
try
{
foo
();
}
catch
(
e
)
{
error
=
e
;
}
t
.
assertType
(
error
.
stack
,
"string"
,
"CasperError() has a stack string property set"
);
t
.
assertMatch
(
error
.
stack
,
/^CasperError: bar
\s
/
,
"CasperError() has the expected stack value"
);
casper
.
tes
t
.
assertType
(
error
.
stack
,
"string"
,
"CasperError() has a stack string property set"
);
casper
.
tes
t
.
assertMatch
(
error
.
stack
,
/^CasperError: bar
\s
/
,
"CasperError() has the expected stack value"
);
t
.
done
();
})(
casper
.
test
);
\ No newline at end of file
casper
.
test
.
done
();
...
...
tests/suites/injector.js
View file @
90f3373
(
function
(
t
)
{
function
createInjector
(
fn
,
values
)
{
return
require
(
'injector'
).
create
(
fn
,
values
);
}
var
t
=
casper
.
test
;
var
createInjector
=
function
(
fn
,
values
)
{
return
require
(
'injector'
).
create
(
fn
,
values
);
};
var
testFn
=
function
(
a
,
b
)
{
return
a
+
b
;
};
var
injector
=
createInjector
(
testFn
);
var
extract
=
injector
.
extract
(
testFn
);
var
testFn
=
function
(
a
,
b
)
{
return
a
+
b
;
};
var
injector
=
createInjector
(
testFn
);
var
extract
=
injector
.
extract
(
testFn
);
t
.
comment
(
'FunctionArgsInjector.extract()'
);
t
.
assertType
(
extract
,
"object"
,
'FunctionArgsInjector.extract() returns an object'
);
t
.
assertEquals
(
extract
.
name
,
null
,
'FunctionArgsInjector.extract() process function name as expected'
);
t
.
assertEquals
(
extract
.
body
,
'return a + b;'
,
'FunctionArgsInjector.extract() process function body as expected'
);
t
.
assertEquals
(
extract
.
args
,
[
'a'
,
'b'
],
'FunctionArgsInjector.extract() process function args as expected'
);
t
.
comment
(
'FunctionArgsInjector.extract()'
);
t
.
assertType
(
extract
,
"object"
,
'FunctionArgsInjector.extract() returns an object'
);
t
.
assertEquals
(
extract
.
name
,
null
,
'FunctionArgsInjector.extract() process function name as expected'
);
t
.
assertEquals
(
extract
.
body
,
'return a + b;'
,
'FunctionArgsInjector.extract() process function body as expected'
);
t
.
assertEquals
(
extract
.
args
,
[
'a'
,
'b'
],
'FunctionArgsInjector.extract() process function args as expected'
);
function
Plop
(
foo
,
bar
)
{
return
'foo: '
+
foo
+
', bar: '
+
bar
;
}
function
Plip
()
{
return
'plop'
;
}
function
foo_bar
(
boz
)
{}
var
gni
=
function
(
$bubu_bibi
,
__popo__
)
{};
var
gno
=
function
(
arg1
,
/*plop*/
arg2
)
{
};
t
.
assertEquals
(
injector
.
extract
(
Plop
),
{
name
:
'Plop'
,
args
:
[
'foo'
,
'bar'
],
body
:
"return 'foo: ' + foo +', bar: ' + bar;"
},
'FunctionArgsInjector.extract() handles named functions with arguments and body'
);
t
.
assertEquals
(
injector
.
extract
(
Plip
),
{
name
:
'Plip'
,
args
:
[],
body
:
"return 'plop';"
},
'FunctionArgsInjector.extract() handles functions with no arguments'
);
t
.
assertEquals
(
injector
.
extract
(
foo_bar
),
{
name
:
'foo_bar'
,
args
:
[
'boz'
],
body
:
""
},
'FunctionArgsInjector.extract() handles functions with no body'
);
t
.
assertEquals
(
injector
.
extract
(
gni
),
{
name
:
null
,
args
:
[
'$bubu_bibi'
,
'__popo__'
],
body
:
""
},
'FunctionArgsInjector.extract() handles anonymous functions with complex args passed'
);
t
.
assertEquals
(
injector
.
extract
(
gno
),
{
name
:
null
,
args
:
[
'arg1'
,
'arg2'
],
body
:
""
},
'FunctionArgsInjector.extract() handles can filter comments in function args'
);
function
Plop
(
foo
,
bar
)
{
return
'foo: '
+
foo
+
', bar: '
+
bar
;
}
function
Plip
()
{
return
'plop'
;
}
function
foo_bar
(
boz
)
{}
var
gni
=
function
(
$bubu_bibi
,
__popo__
)
{};
var
gno
=
function
(
arg1
,
/*plop*/
arg2
)
{
};
t
.
assertEquals
(
injector
.
extract
(
Plop
),
{
name
:
'Plop'
,
args
:
[
'foo'
,
'bar'
],
body
:
"return 'foo: ' + foo +', bar: ' + bar;"
},
'FunctionArgsInjector.extract() handles named functions with arguments and body'
);
t
.
assertEquals
(
injector
.
extract
(
Plip
),
{
name
:
'Plip'
,
args
:
[],
body
:
"return 'plop';"
},
'FunctionArgsInjector.extract() handles functions with no arguments'
);
t
.
assertEquals
(
injector
.
extract
(
foo_bar
),
{
name
:
'foo_bar'
,
args
:
[
'boz'
],
body
:
""
},
'FunctionArgsInjector.extract() handles functions with no body'
);
t
.
assertEquals
(
injector
.
extract
(
gni
),
{
name
:
null
,
args
:
[
'$bubu_bibi'
,
'__popo__'
],
body
:
""
},
'FunctionArgsInjector.extract() handles anonymous functions with complex args passed'
);
t
.
assertEquals
(
injector
.
extract
(
gno
),
{
name
:
null
,
args
:
[
'arg1'
,
'arg2'
],
body
:
""
},
'FunctionArgsInjector.extract() handles can filter comments in function args'
);
t
.
comment
(
'FunctionArgsInjector.process()'
);
var
processed
;
eval
(
'processed = '
+
injector
.
process
({
a
:
1
,
b
:
2
}));
t
.
comment
(
'FunctionArgsInjector.process()'
);
var
processed
;
eval
(
'processed = '
+
injector
.
process
({
a
:
1
,
b
:
2
}));
t
.
assertType
(
processed
,
"function"
,
'FunctionArgsInjector.process() processed a function'
);
t
.
assertEquals
(
processed
(),
3
,
'FunctionArgsInjector.process() processed the function correctly'
);
t
.
assertType
(
processed
,
"function"
,
'FunctionArgsInjector.process() processed a function'
);
t
.
assertEquals
(
processed
(),
3
,
'FunctionArgsInjector.process() processed the function correctly'
);
t
.
done
();
})(
casper
.
test
);
t
.
done
();
...
...
tests/suites/tester.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'Tester.testEquals()'
);
t
.
assert
(
casper
.
test
.
testEquals
(
null
,
null
),
'Tester.testEquals() null equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
null
,
undefined
),
'Tester.testEquals() null vs. undefined inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
(
"hi"
,
"hi"
),
'Tester.testEquals() string equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
"hi"
,
"ih"
),
'Tester.testEquals() string inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
(
5
,
5
),
'Tester.testEquals() number equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
"5"
,
5
),
'Tester.testEquals() number equality without implicit cast'
);
t
.
assert
(
casper
.
test
.
testEquals
(
5
,
5.0
),
'Tester.testEquals() number equality with cast'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
5
,
10
),
'Tester.testEquals() number inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
([],
[]),
'Tester.testEquals() empty array equality'
);
t
.
assert
(
casper
.
test
.
testEquals
([
1
,
2
],
[
1
,
2
]),
'Tester.testEquals() array equality'
);
t
.
assert
(
casper
.
test
.
testEquals
([
1
,
2
,[
1
,
2
,
function
(){}]],
[
1
,
2
,[
1
,
2
,
function
(){}]]),
'Tester.testEquals() complex array equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
([
1
,
2
,[
1
,
2
,
function
(
a
){}]],
[
1
,
2
,[
1
,
2
,
function
(
b
){}]]),
'Tester.testEquals() complex array inequality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
([
1
,
2
],
[
2
,
1
]),
'Tester.testEquals() shuffled array inequality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
([
1
,
2
],
[
1
,
2
,
3
]),
'Tester.testEquals() array length inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
({},
{}),
'Tester.testEquals() empty object equality'
);
t
.
assert
(
casper
.
test
.
testEquals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
}),
'Tester.testEquals() object length equality'
);
t
.
assert
(
casper
.
test
.
testEquals
({
a
:
1
,
b
:
2
},
{
b
:
2
,
a
:
1
}),
'Tester.testEquals() shuffled object keys equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
3
}),
'Tester.testEquals() object inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}}),
'Tester.testEquals() complex object equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
27
}}),
'Tester.testEquals() complex object inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
(
function
(
x
){
return
x
;},
function
(
x
){
return
x
;}),
'Tester.testEquals() function equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
function
(
x
){
return
x
;},
function
(
y
){
return
y
+
2
;}),
'Tester.testEquals() function inequality'
);
var
t
=
casper
.
test
;
t
.
done
();
})(
casper
.
test
);
t
.
comment
(
'Tester.testEquals()'
);
t
.
assert
(
casper
.
test
.
testEquals
(
null
,
null
),
'Tester.testEquals() null equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
null
,
undefined
),
'Tester.testEquals() null vs. undefined inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
(
"hi"
,
"hi"
),
'Tester.testEquals() string equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
"hi"
,
"ih"
),
'Tester.testEquals() string inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
(
5
,
5
),
'Tester.testEquals() number equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
"5"
,
5
),
'Tester.testEquals() number equality without implicit cast'
);
t
.
assert
(
casper
.
test
.
testEquals
(
5
,
5.0
),
'Tester.testEquals() number equality with cast'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
5
,
10
),
'Tester.testEquals() number inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
([],
[]),
'Tester.testEquals() empty array equality'
);
t
.
assert
(
casper
.
test
.
testEquals
([
1
,
2
],
[
1
,
2
]),
'Tester.testEquals() array equality'
);
t
.
assert
(
casper
.
test
.
testEquals
([
1
,
2
,[
1
,
2
,
function
(){}]],
[
1
,
2
,[
1
,
2
,
function
(){}]]),
'Tester.testEquals() complex array equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
([
1
,
2
,[
1
,
2
,
function
(
a
){}]],
[
1
,
2
,[
1
,
2
,
function
(
b
){}]]),
'Tester.testEquals() complex array inequality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
([
1
,
2
],
[
2
,
1
]),
'Tester.testEquals() shuffled array inequality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
([
1
,
2
],
[
1
,
2
,
3
]),
'Tester.testEquals() array length inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
({},
{}),
'Tester.testEquals() empty object equality'
);
t
.
assert
(
casper
.
test
.
testEquals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
}),
'Tester.testEquals() object length equality'
);
t
.
assert
(
casper
.
test
.
testEquals
({
a
:
1
,
b
:
2
},
{
b
:
2
,
a
:
1
}),
'Tester.testEquals() shuffled object keys equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
3
}),
'Tester.testEquals() object inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}}),
'Tester.testEquals() complex object equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
27
}}),
'Tester.testEquals() complex object inequality'
);
t
.
assert
(
casper
.
test
.
testEquals
(
function
(
x
){
return
x
;},
function
(
x
){
return
x
;}),
'Tester.testEquals() function equality'
);
t
.
assertNot
(
casper
.
test
.
testEquals
(
function
(
x
){
return
x
;},
function
(
y
){
return
y
+
2
;}),
'Tester.testEquals() function inequality'
);
t
.
done
();
...
...
tests/suites/utils.js
View file @
90f3373
(
function
(
t
)
{
var
utils
=
require
(
'utils'
);
var
utils
=
require
(
'utils'
),
t
=
casper
.
test
;
t
.
comment
(
'fileExt()'
);
(
function
()
{
var
testCases
=
{
'foo.ext'
:
'ext'
,
'FOO.EXT'
:
'ext'
,
'a.ext'
:
'ext'
,
'.ext'
:
'ext'
,
'toto.'
:
''
,
' plop.ext '
:
'ext'
};
t
.
comment
(
'fileExt()'
);
(
function
()
{
var
testCases
=
{
'foo.ext'
:
'ext'
,
'FOO.EXT'
:
'ext'
,
'a.ext'
:
'ext'
,
'.ext'
:
'ext'
,
'toto.'
:
''
,
' plop.ext '
:
'ext'
};
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
fileExt
(
testCase
),
testCases
[
testCase
],
'fileExt() extract file extension'
);
}
})();
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
fileExt
(
testCase
),
testCases
[
testCase
],
'fileExt() extract file extension'
);
}
})();
t
.
comment
(
'fillBlanks()'
);
(
function
()
{
testCases
=
{
'foo'
:
'foo '
,
' foo bar '
:
' foo bar '
,
' foo bar '
:
' foo bar '
};
t
.
comment
(
'fillBlanks()'
);
(
function
()
{
testCases
=
{
'foo'
:
'foo '
,
' foo bar '
:
' foo bar '
,
' foo bar '
:
' foo bar '
};
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
fillBlanks
(
testCase
,
10
),
testCases
[
testCase
],
'fillBlanks() fills blanks'
);
}
})();
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
fillBlanks
(
testCase
,
10
),
testCases
[
testCase
],
'fillBlanks() fills blanks'
);
}
})();
t
.
comment
(
'isClipRect()'
);
(
function
()
{
testCases
=
[
[{},
false
],
[{
top
:
2
},
false
],
[{
top
:
2
,
left
:
2
,
width
:
2
,
height
:
2
},
true
],
[{
top
:
2
,
left
:
2
,
height
:
2
,
width
:
2
},
true
],
[{
top
:
2
,
left
:
2
,
width
:
2
,
height
:
new
Date
()},
false
]
];
t
.
comment
(
'isClipRect()'
);
(
function
()
{
testCases
=
[
[{},
false
],
[{
top
:
2
},
false
],
[{
top
:
2
,
left
:
2
,
width
:
2
,
height
:
2
},
true
],
[{
top
:
2
,
left
:
2
,
height
:
2
,
width
:
2
},
true
],
[{
top
:
2
,
left
:
2
,
width
:
2
,
height
:
new
Date
()},
false
]
];
testCases
.
forEach
(
function
(
testCase
)
{
t
.
assertEquals
(
utils
.
isClipRect
(
testCase
[
0
]),
testCase
[
1
],
'isClipRect() checks for a ClipRect'
);
});
})();
testCases
.
forEach
(
function
(
testCase
)
{
t
.
assertEquals
(
utils
.
isClipRect
(
testCase
[
0
]),
testCase
[
1
],
'isClipRect() checks for a ClipRect'
);
});
})();
t
.
comment
(
'isJsFile()'
);
(
function
()
{
testCases
=
{
''
:
false
,
'toto.png'
:
false
,
'plop'
:
false
,
'gniii.coffee'
:
true
,
'script.js'
:
true
};
t
.
comment
(
'isJsFile()'
);
(
function
()
{
testCases
=
{
''
:
false
,
'toto.png'
:
false
,
'plop'
:
false
,
'gniii.coffee'
:
true
,
'script.js'
:
true
};
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
isJsFile
(
testCase
),
testCases
[
testCase
],
'isJsFile() checks for js file'
);
}
})();
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
isJsFile
(
testCase
),
testCases
[
testCase
],
'isJsFile() checks for js file'
);
}
})();
t
.
comment
(
'mergeObjects()'
);
(
function
()
{
testCases
=
[
{
obj1
:
{
a
:
1
},
obj2
:
{
b
:
2
},
merged
:
{
a
:
1
,
b
:
2
}
},
{
obj1
:
{},
obj2
:
{
a
:
1
},
merged
:
{
a
:
1
}
},
{
obj1
:
{
a
:
1
},
obj2
:
{},
merged
:
{
a
:
1
}
},
{
obj1
:
{
a
:
1
},
obj2
:
{
a
:
2
},
merged
:
{
a
:
2
}
},
{
obj1
:
{
x
:
0
,
double
:
function
(){
return
this
.
x
*
2
;}},
obj2
:
{
triple
:
function
(){
return
this
.
x
*
3
;}},
merged
:
{
x
:
0
,
double
:
function
(){
return
this
.
x
*
2
;},
triple
:
function
(){
return
this
.
x
*
3
;}
}
t
.
comment
(
'mergeObjects()'
);
(
function
()
{
testCases
=
[
{
obj1
:
{
a
:
1
},
obj2
:
{
b
:
2
},
merged
:
{
a
:
1
,
b
:
2
}
},
{
obj1
:
{},
obj2
:
{
a
:
1
},
merged
:
{
a
:
1
}
},
{
obj1
:
{
a
:
1
},
obj2
:
{},
merged
:
{
a
:
1
}
},
{
obj1
:
{
a
:
1
},
obj2
:
{
a
:
2
},
merged
:
{
a
:
2
}
},
{
obj1
:
{
x
:
0
,
double
:
function
(){
return
this
.
x
*
2
;}},
obj2
:
{
triple
:
function
(){
return
this
.
x
*
3
;}},
merged
:
{
x
:
0
,
double
:
function
(){
return
this
.
x
*
2
;},
triple
:
function
(){
return
this
.
x
*
3
;}
}
];
}
];
testCases
.
forEach
(
function
(
testCase
)
{
t
.
assertEquals
(
utils
.
mergeObjects
(
testCase
.
obj1
,
testCase
.
obj2
),
testCase
.
merged
,
'mergeObjects() can merge objects'
);
});
})();
testCases
.
forEach
(
function
(
testCase
)
{
t
.
assertEquals
(
utils
.
mergeObjects
(
testCase
.
obj1
,
testCase
.
obj2
),
testCase
.
merged
,
'mergeObjects() can merge objects'
);
});
})();
t
.
done
();
})(
casper
.
test
);
t
.
done
();
...
...
tests/suites/xunit.js
View file @
90f3373
(
function
(
t
)
{
t
.
comment
(
'phantom.Casper.XUnitExporter'
);
casper
.
test
.
comment
(
'phantom.Casper.XUnitExporter'
);
xunit
=
require
(
'xunit'
).
create
();
xunit
.
addSuccess
(
'foo'
,
'bar'
);
t
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="foo" name="bar"/
,
'XUnitExporter.addSuccess() adds a successful testcase'
);
xunit
.
addFailure
(
'bar'
,
'baz'
,
'wrong'
,
'chucknorriz'
);
t
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/
,
'XUnitExporter.addFailure() adds a failed testcase'
);
xunit
=
require
(
'xunit'
).
create
();
xunit
.
addSuccess
(
'foo'
,
'bar'
);
casper
.
tes
t
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="foo" name="bar"/
,
'XUnitExporter.addSuccess() adds a successful testcase'
);
xunit
.
addFailure
(
'bar'
,
'baz'
,
'wrong'
,
'chucknorriz'
);
casper
.
tes
t
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/
,
'XUnitExporter.addFailure() adds a failed testcase'
);
t
.
done
();
})(
casper
.
test
);
casper
.
test
.
done
();
...
...
Please
register
or
sign in
to post a comment