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
1cd9d85f
...
1cd9d85fcfad9a9ea2218dd9cfc8a19de33092f9
authored
2012-12-10 19:38:16 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refs #279 - support for frames through waitForFrame() and withFrame()
1 parent
59f0d1f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
18 deletions
modules/casper.js
tests/suites/casper/frames.js
modules/casper.js
View file @
1cd9d85
...
...
@@ -1728,10 +1728,28 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
};
/**
* Waits for a child page having its url matching the provided pattern to be opened
* Waits for a child frame page to be loaded.
*
* @param String frameName The frame name
* @param Function then The next step function (optional)
* @param Function onTimeout Function to call on operation timeout (optional)
* @param Number timeout Timeout in milliseconds (optional)
* @return Casper
*/
Casper
.
prototype
.
waitForFrame
=
function
waitForFrame
(
frameName
,
then
,
onTimeout
,
timeout
)
{
"use strict"
;
return
this
.
waitFor
(
function
()
{
return
this
.
page
.
childFramesName
().
some
(
function
(
name
)
{
return
name
===
frameName
;
});
},
then
,
onTimeout
,
timeout
);
};
/**
* Waits for a popup page having its url matching the provided pattern to be opened
* and loaded.
*
* @param String|RegExp urlPattern The
child page
url pattern
* @param String|RegExp urlPattern The
popup
url pattern
* @param Function then The next step function (optional)
* @param Function onTimeout Function to call on operation timeout (optional)
* @param Number timeout Timeout in milliseconds (optional)
...
...
@@ -1863,11 +1881,39 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on
};
/**
* Makes the provided child page as the currently active one. Note that the
* Makes the provided frame page as the currently active one. Note that the
* active page will be reverted when finished.
*
* @param String frameName Target frame name
* @param Function then Next step function
* @return Casper
*/
Casper
.
prototype
.
withFrame
=
function
withFrame
(
frameName
,
then
)
{
"use strict"
;
this
.
then
(
function
_step
()
{
// make the frame page the currently active one
this
.
page
.
switchToChildFrame
(
frameName
);
});
try
{
this
.
then
(
then
);
}
catch
(
e
)
{
// revert to main page on error
this
.
log
(
"error while processing frame step: "
+
e
,
"error"
);
this
.
page
.
switchToMainFrame
();
throw
e
;
}
return
this
.
then
(
function
_step
()
{
// revert to main page
this
.
page
.
switchToMainFrame
();
});
};
/**
* Makes the provided frame page as the currently active one. Note that the
* active page will be reverted when finished.
*
* @param String|RegExp|WebPage popup Target
child
page information
* @param Function then
Next step function
* @param String|RegExp|WebPage popup Target
frame
page information
* @param Function then Next step function
* @return Casper
*/
Casper
.
prototype
.
withPopup
=
function
withPopup
(
popupInfo
,
then
)
{
...
...
tests/suites/casper/frames.js
View file @
1cd9d85
/*global casper __utils__*/
/*jshint strict:false*/
casper
.
start
(
'tests/site/frames.html'
,
function
()
{
casper
.
start
(
'tests/site/frames.html'
);
casper
.
waitForFrame
(
'frame1'
,
function
()
{
this
.
test
.
pass
(
'Casper.waithForFrame() can wait for a frame to be loaded.'
);
this
.
test
.
assertTitle
(
'CasperJS test frames'
);
this
.
page
.
switchToChildFrame
(
"frame1"
);
});
casper
.
waitForFrame
(
'frame2'
,
function
()
{
this
.
test
.
pass
(
'Casper.waithForFrame() can wait for another frame to be loaded.'
);
this
.
test
.
assertTitle
(
'CasperJS test frames'
);
});
casper
.
withFrame
(
'frame1'
,
function
()
{
this
.
test
.
assertTitle
(
'CasperJS frame 1'
);
this
.
test
.
assertExists
(
"#f1"
);
this
.
test
.
assertDoesntExist
(
"#f2"
);
this
.
page
.
switchToParentFrame
();
this
.
page
.
switchToChildFrame
(
"frame2"
);
});
casper
.
withFrame
(
'frame2'
,
function
()
{
this
.
test
.
assertTitle
(
'CasperJS frame 2'
);
this
.
test
.
assertExists
(
"#f2"
);
this
.
test
.
assertDoesntExist
(
"#f1"
);
this
.
test
.
assertEval
(
function
()
{
return
'__utils__'
in
window
&&
'getBinary'
in
__utils__
;
},
'__utils__ object is available in child frame'
);
});
casper
.
run
(
function
()
{
this
.
page
.
switchToMainFrame
(
);
this
.
test
.
done
(
8
);
this
.
test
.
assertTitle
(
'CasperJS test frames'
);
this
.
test
.
done
(
7
);
});
...
...
Please
register
or
sign in
to post a comment