Added some basic tests for withFrame(Number).
Showing
2 changed files
with
19 additions
and
9 deletions
... | @@ -1870,22 +1870,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on | ... | @@ -1870,22 +1870,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on |
1870 | * Makes the provided frame page as the currently active one. Note that the | 1870 | * Makes the provided frame page as the currently active one. Note that the |
1871 | * active page will be reverted when finished. | 1871 | * active page will be reverted when finished. |
1872 | * | 1872 | * |
1873 | * @param String|Number frameNameOrNumber Target frame name or number | 1873 | * @param String|Number frameInfo Target frame name or number |
1874 | * @param Function then Next step function | 1874 | * @param Function then Next step function |
1875 | * @return Casper | 1875 | * @return Casper |
1876 | */ | 1876 | */ |
1877 | Casper.prototype.withFrame = function withFrame(frameNameOrNumber, then) { | 1877 | Casper.prototype.withFrame = function withFrame(frameInfo, then) { |
1878 | "use strict"; | 1878 | "use strict"; |
1879 | this.then(function _step() { | 1879 | this.then(function _step() { |
1880 | if (utils.isNumber(frameNameOrNumber)) { | 1880 | if (utils.isNumber(frameInfo)) { |
1881 | if (frameNameOrNumber > this.page.childFramesCount() - 1) { | 1881 | if (frameInfo > this.page.childFramesCount() - 1) { |
1882 | throw new CasperError(f('Frame number "%d" is out of bounds.', frameNameOrNumber)); | 1882 | throw new CasperError(f('Frame number "%d" is out of bounds.', frameInfo)); |
1883 | } | 1883 | } |
1884 | } else if (this.page.childFramesName().indexOf(frameNameOrNumber) === -1) { | 1884 | } else if (this.page.childFramesName().indexOf(frameInfo) === -1) { |
1885 | throw new CasperError(f('No frame named "%s" was found.', frameNameOrNumber)); | 1885 | throw new CasperError(f('No frame named "%s" was found.', frameInfo)); |
1886 | } | 1886 | } |
1887 | // make the frame page the currently active one | 1887 | // make the frame page the currently active one |
1888 | this.page.switchToChildFrame(frameNameOrNumber); | 1888 | this.page.switchToChildFrame(frameInfo); |
1889 | }); | 1889 | }); |
1890 | try { | 1890 | try { |
1891 | this.then(then); | 1891 | 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 | }); | ... | ... |
-
Please register or sign in to post a comment