Commit 2b0a2025 2b0a20258f978713cc59c50c3f17a60e989b8efd by Rob Barreca

Added some basic tests for withFrame(Number).

1 parent 50a1ffbf
......@@ -1870,22 +1870,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on
* Makes the provided frame page as the currently active one. Note that the
* active page will be reverted when finished.
*
* @param String|Number frameNameOrNumber Target frame name or number
* @param String|Number frameInfo Target frame name or number
* @param Function then Next step function
* @return Casper
*/
Casper.prototype.withFrame = function withFrame(frameNameOrNumber, then) {
Casper.prototype.withFrame = function withFrame(frameInfo, then) {
"use strict";
this.then(function _step() {
if (utils.isNumber(frameNameOrNumber)) {
if (frameNameOrNumber > this.page.childFramesCount() - 1) {
throw new CasperError(f('Frame number "%d" is out of bounds.', frameNameOrNumber));
if (utils.isNumber(frameInfo)) {
if (frameInfo > this.page.childFramesCount() - 1) {
throw new CasperError(f('Frame number "%d" is out of bounds.', frameInfo));
}
} else if (this.page.childFramesName().indexOf(frameNameOrNumber) === -1) {
throw new CasperError(f('No frame named "%s" was found.', frameNameOrNumber));
} else if (this.page.childFramesName().indexOf(frameInfo) === -1) {
throw new CasperError(f('No frame named "%s" was found.', frameInfo));
}
// make the frame page the currently active one
this.page.switchToChildFrame(frameNameOrNumber);
this.page.switchToChildFrame(frameInfo);
});
try {
this.then(then);
......
......@@ -25,7 +25,17 @@ casper.withFrame('frame2', function() {
this.test.assertTitle('CasperJS frame 3');
});
casper.withFrame(0, function() {
this.test.assertTitle('CasperJS frame 1');
this.test.assertExists("#f1");
this.test.assertDoesntExist("#f2");
});
casper.withFrame(1, function() {
this.test.assertTitle('CasperJS frame 3');
});
casper.run(function() {
this.test.assertTitle('CasperJS test frames');
this.test.done(10);
this.test.done(14);
});
......