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
257e66b0
...
257e66b0cab0cd84fcbe4eeaa27a53e1cd6a4f63
authored
2012-01-09 11:14:30 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added more tests for the Mouse class
1 parent
ba692c36
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
11 deletions
modules/mouse.js
tests/site/click.html
tests/suites/casper/click.js
modules/mouse.js
View file @
257e66b
...
...
@@ -52,30 +52,30 @@ var Mouse = function(casper) {
var
processEvent
=
function
(
type
,
args
)
{
if
(
!
utils
.
isString
(
type
)
||
supportedEvents
.
indexOf
(
type
)
===
-
1
)
{
throw
new
Error
(
'Unsupported mouse event type: '
+
type
);
throw
new
Error
(
'
Mouse.processEvent():
Unsupported mouse event type: '
+
type
);
}
args
=
Array
.
prototype
.
slice
.
call
(
args
);
// cast Arguments -> Array
casper
.
emit
(
'mouse.'
+
type
.
replace
(
'mouse'
,
''
),
args
);
switch
(
args
.
length
)
{
case
0
:
throw
new
Error
(
'Too few arguments'
);
throw
new
Error
(
'
Mouse.processEvent():
Too few arguments'
);
case
1
:
// selector
var
selector
=
args
[
0
];
if
(
!
utils
.
isString
(
selector
))
{
throw
new
Error
(
'No valid CSS selector passed: '
+
selector
);
throw
new
Error
(
'
Mouse.processEvent():
No valid CSS selector passed: '
+
selector
);
}
casper
.
page
.
sendEvent
.
apply
(
casper
.
page
,
[
type
].
concat
(
computeCenter
(
selector
)));
break
;
case
2
:
// coordinates
if
(
!
utils
.
isNumber
(
args
[
0
])
||
!
utils
.
isNumber
(
args
[
1
]))
{
throw
new
Error
(
'
No valid coordinates passed'
);
throw
new
Error
(
'
Mouse.processEvent(): No valid coordinates passed: '
+
args
);
}
casper
.
page
.
sendEvent
(
type
,
args
[
0
],
args
[
1
]);
break
;
default
:
throw
new
Error
(
'Too many arguments'
);
throw
new
Error
(
'
Mouse.processEvent():
Too many arguments'
);
}
};
...
...
tests/site/click.html
View file @
257e66b
...
...
@@ -16,15 +16,24 @@
test2
:
false
,
test3
:
false
,
test4
:
false
,
test5
:
[]
testdown
:
[],
testup
:
[],
testmove
:
[],
testclick
:
[]
};
document
.
querySelector
(
'#test4'
).
onclick
=
function
(
event
)
{
results
.
test4
=
true
;
event
.
preventDefault
();
};
window
.
onmousedown
=
function
(
e
)
{
results
.
test5
=
[
e
.
x
,
e
.
y
];
}
window
.
onmousedown
=
function
(
event
)
{
results
.
testdown
=
[
event
.
x
,
event
.
y
];
};
window
.
onmouseup
=
function
(
event
)
{
results
.
testup
=
[
event
.
x
,
event
.
y
];
};
window
.
onmousemove
=
function
(
event
)
{
results
.
testmove
=
[
event
.
x
,
event
.
y
];
};
})(
window
);
</script>
</body>
...
...
tests/suites/casper/click.js
View file @
257e66b
...
...
@@ -25,12 +25,22 @@
this
.
test
.
assert
(
results
.
test4
,
'CasperUtils.click() has clicked an unobstrusive js handled link'
);
});
//
mouse.down
//
casper.mouse
casper
.
then
(
function
()
{
t
.
comment
(
'Mouse.down()'
);
this
.
mouse
.
down
(
200
,
100
);
var
results
=
this
.
getGlobal
(
'results'
);
this
.
test
.
assertEquals
(
results
.
test5
,
[
200
,
100
],
'Mouse.down() has clicked the specified position'
);
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'
);
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
()
{
...
...
Please
register
or
sign in
to post a comment