Commit c132c434 c132c434f6ea75559fb419495d3bcc356d022306 by Nicolas Perriault

Merge remote-tracking branch 'rbarreca/master' into pr-322

2 parents a2ebe03a 109c157e
1 Subproject commit b0f51d643a839fb66c174086c426b9c7b49e2a80 1 Subproject commit 78743d45ac54a56fa6276ed98f46c4a3ca938c01
......
...@@ -1873,18 +1873,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on ...@@ -1873,18 +1873,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on
1873 * Makes the provided frame page as the currently active one. Note that the 1873 * Makes the provided frame page as the currently active one. Note that the
1874 * active page will be reverted when finished. 1874 * active page will be reverted when finished.
1875 * 1875 *
1876 * @param String frameName Target frame name 1876 * @param String|Number frameInfo Target frame name or number
1877 * @param Function then Next step function 1877 * @param Function then Next step function
1878 * @return Casper 1878 * @return Casper
1879 */ 1879 */
1880 Casper.prototype.withFrame = function withFrame(frameName, then) { 1880 Casper.prototype.withFrame = function withFrame(frameInfo, then) {
1881 "use strict"; 1881 "use strict";
1882 this.then(function _step() { 1882 this.then(function _step() {
1883 if (this.page.childFramesName().indexOf(frameName) === -1) { 1883 if (utils.isNumber(frameInfo)) {
1884 throw new CasperError(f('No frame named "%s" was found.', frameName)); 1884 if (frameInfo > this.page.childFramesCount() - 1) {
1885 throw new CasperError(f('Frame number "%d" is out of bounds.', frameInfo));
1886 }
1887 } else if (this.page.childFramesName().indexOf(frameInfo) === -1) {
1888 throw new CasperError(f('No frame named "%s" was found.', frameInfo));
1885 } 1889 }
1886 // make the frame page the currently active one 1890 // make the frame page the currently active one
1887 this.page.switchToChildFrame(frameName); 1891 this.page.switchToChildFrame(frameInfo);
1888 }); 1892 });
1889 try { 1893 try {
1890 this.then(then); 1894 this.then(then);
......
...@@ -25,7 +25,17 @@ casper.withFrame('frame2', function() { ...@@ -25,7 +25,17 @@ casper.withFrame('frame2', function() {
25 this.test.assertTitle('CasperJS frame 3'); 25 this.test.assertTitle('CasperJS frame 3');
26 }); 26 });
27 27
28 casper.withFrame(0, function() {
29 this.test.assertTitle('CasperJS frame 1');
30 this.test.assertExists("#f1");
31 this.test.assertDoesntExist("#f2");
32 });
33
34 casper.withFrame(1, function() {
35 this.test.assertTitle('CasperJS frame 3');
36 });
37
28 casper.run(function() { 38 casper.run(function() {
29 this.test.assertTitle('CasperJS test frames'); 39 this.test.assertTitle('CasperJS test frames');
30 this.test.done(10); 40 this.test.done(14);
31 }); 41 });
......