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
c53882b8
...
c53882b84ecae5bf700d999c02371d70848bd34a
authored
2012-12-13 08:27:51 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #317, fixes #313: revert to emulated mouse events
1 parent
a36a7fad
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
13 deletions
CHANGELOG.md
modules/casper.js
tests/site/frame1.html
tests/site/frame2.html
tests/site/frame3.html
tests/suites/casper/frames.js
CHANGELOG.md
View file @
c53882b
...
...
@@ -6,6 +6,12 @@ XXXX-XX-XX, v1.0.0
### Important Changes & Caveats
#### Reverted to emulated mouse events
For some (weird) reason, emulated mouse events are actually more accurate than native ones.
Weird, I said.
#### Added support for frames
Short excerpt of related tests:
...
...
modules/casper.js
View file @
c53882b
...
...
@@ -1135,18 +1135,22 @@ Casper.prototype.log = function log(message, level, space) {
Casper
.
prototype
.
mouseEvent
=
function
mouseEvent
(
type
,
selector
)
{
"use strict"
;
this
.
checkStarted
();
this
.
log
(
f
(
"Mouse event '%s' on selector: %s"
,
type
,
selector
)
,
"debug"
);
this
.
log
(
"Mouse event '"
+
type
+
"' on selector: "
+
selector
,
"debug"
);
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
f
(
"Cannot dispatch
'%s'
event on nonexistent selector: %s"
,
type
,
selector
));
throw
new
CasperError
(
f
(
"Cannot dispatch
%s
event on nonexistent selector: %s"
,
type
,
selector
));
}
// PhantomJS doesn't provide native events for mouseover & mouseout
if
(
type
===
"mouseover"
||
type
===
"mouseout"
)
{
return
this
.
evaluate
(
function
(
type
,
selector
)
{
return
__utils__
.
mouseEvent
(
type
,
selector
);
},
type
,
selector
);
}
this
.
mouse
.
processEvent
(
type
,
selector
);
if
(
this
.
evaluate
(
function
(
type
,
selector
)
{
return
window
.
__utils__
.
mouseEvent
(
type
,
selector
);
},
type
,
selector
))
{
return
true
;
}
// fallback onto native QtWebKit mouse events
try
{
return
this
.
mouse
.
processEvent
(
type
,
selector
);
}
catch
(
e
)
{
this
.
log
(
f
(
"Couldn't emulate '%s' event on %s: %s"
,
type
,
selector
,
e
),
"error"
);
}
return
false
;
};
/**
...
...
@@ -1891,6 +1895,9 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on
Casper
.
prototype
.
withFrame
=
function
withFrame
(
frameName
,
then
)
{
"use strict"
;
this
.
then
(
function
_step
()
{
if
(
this
.
page
.
childFramesName
().
indexOf
(
frameName
)
===
-
1
)
{
throw
new
CasperError
(
f
(
'No frame named "%s" was found.'
,
frameName
));
}
// make the frame page the currently active one
this
.
page
.
switchToChildFrame
(
frameName
);
});
...
...
@@ -1898,7 +1905,7 @@ Casper.prototype.withFrame = function withFrame(frameName, then) {
this
.
then
(
then
);
}
catch
(
e
)
{
// revert to main page on error
this
.
log
(
"error while processing frame step: "
+
e
,
"error"
);
this
.
warn
(
"Error while processing frame step: "
+
e
);
this
.
page
.
switchToMainFrame
();
throw
e
;
}
...
...
tests/site/frame1.html
View file @
c53882b
...
...
@@ -4,5 +4,7 @@
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>
CasperJS frame 1
</title>
</head>
<body
id=
"f1"
>
This is frame 1.
</body>
<body
id=
"f1"
>
<h1>
This is frame 1.
</h1>
</body>
</html>
...
...
tests/site/frame2.html
View file @
c53882b
...
...
@@ -4,5 +4,8 @@
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>
CasperJS frame 2
</title>
</head>
<body
id=
"f2"
>
This is frame 2.
</body>
<body
id=
"f2"
>
<h1>
This is frame 2.
</h1>
<p><a
href=
"frame3.html"
target=
"frame2"
>
frame 3
</a></p>
</body>
</html>
...
...
tests/site/frame3.html
0 → 100644
View file @
c53882b
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>
CasperJS frame 3
</title>
</head>
<body
id=
"f3"
>
<h1>
This is frame 3.
</h1>
<p><a
href=
"frame2.html"
>
frame 2
</a></p>
</body>
</html>
tests/suites/casper/frames.js
View file @
c53882b
...
...
@@ -28,9 +28,14 @@ casper.withFrame('frame2', function() {
this
.
test
.
assertEval
(
function
()
{
return
'__utils__'
in
window
&&
'getBinary'
in
__utils__
;
},
'__utils__ object is available in other child frame'
);
this
.
clickLabel
(
'frame 3'
);
});
casper
.
withFrame
(
'frame2'
,
function
()
{
this
.
test
.
assertTitle
(
'CasperJS frame 3'
);
});
casper
.
run
(
function
()
{
this
.
test
.
assertTitle
(
'CasperJS test frames'
);
this
.
test
.
done
(
1
3
);
this
.
test
.
done
(
1
4
);
});
...
...
Please
register
or
sign in
to post a comment