diff --git a/docs/acceptance.md b/docs/acceptance.md index 33d44b2f7..57e7a4309 100644 --- a/docs/acceptance.md +++ b/docs/acceptance.md @@ -246,10 +246,12 @@ within({frame: "#editor"}, () => { }); ``` -Nested IFrames can be set by passing array *(Nightmare only)*: +Nested IFrames can be set by passing array *(WebDriverIO & Nightmare only)*: ```js -within({frame: [".content", "#editor"]); +within({frame: [".content", "#editor"]}, () => { + I.see('Page'); +}); ``` --- diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index a92796d76..43d06b9aa 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -379,6 +379,12 @@ class WebDriverIO extends Helper { let frame = isFrameLocator(locator); let client = this.browser; if (frame) { + if (Array.isArray(frame)) { + withinStore.frame = frame.join('>'); + return client + .frame(null) + .then(() => frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve())); + } withinStore.frame = frame; return this.switchTo(frame); } diff --git a/test/acceptance/within_test.js b/test/acceptance/within_test.js index 1f372ff75..4ad2e27a4 100644 --- a/test/acceptance/within_test.js +++ b/test/acceptance/within_test.js @@ -11,7 +11,7 @@ Scenario('within on form @WebDriverIO @protractor @nightmare', (I) => { I.dontSeeCheckboxIsChecked({css: "form[name=form1] input[name=first_test_radio]"}); }); -Scenario('within on iframe @WebDriverIO @Nightmare', (I) => { +Scenario('within on iframe @WebDriverIO', (I) => { I.amOnPage('/iframe'); within({frame: 'iframe'}, () => { I.fillField('rus', 'Updated'); @@ -22,7 +22,27 @@ Scenario('within on iframe @WebDriverIO @Nightmare', (I) => { I.dontSee('Email Address'); }); -Scenario('within on nested iframe @nightmare', (I) => { +Scenario('within on iframe (without iframe navigation) @WebDriverIO @nightmare', (I) => { + I.amOnPage('/iframe'); + within({frame: 'iframe'}, () => { + I.fillField('rus', 'Updated'); + I.see('Sign in!'); + }); + I.see('Iframe test'); + I.dontSee('Sign in!'); +}); + +Scenario('within on nested iframe (without iframe navigation) (depth=2) @WebDriverIO @nightmare', (I) => { + I.amOnPage('/iframe_nested'); + within({frame: ['[name=wrapper]', '[name=content]']}, () => { + I.fillField('rus', 'Updated'); + I.see('Sign in!'); + }); + I.see('Nested Iframe test'); + I.dontSee('Sign in!'); +}); + +Scenario('within on nested iframe (depth=1) @WebDriverIO', (I) => { I.amOnPage('/iframe'); within({frame: ['[name=content]']}, () => { I.fillField('rus', 'Updated'); @@ -31,4 +51,37 @@ Scenario('within on nested iframe @nightmare', (I) => { }); I.see('Iframe test'); I.dontSee('Email Address'); +}); + +Scenario('within on nested iframe (depth=2) @WebDriverIO', (I) => { + I.amOnPage('/iframe_nested'); + within({frame: ['[name=wrapper]', '[name=content]']}, () => { + I.fillField('rus', 'Updated'); + I.click('Sign in!'); + I.see('Email Address'); + }); + I.see('Nested Iframe test'); + I.dontSee('Email Address'); +}); + +Scenario('within on nested iframe (depth=2) and mixed id and xpath selector @WebDriverIO', (I) => { + I.amOnPage('/iframe_nested'); + within({frame: ['#wrapperId', '[name=content]']}, () => { + I.fillField('rus', 'Updated'); + I.click('Sign in!'); + I.see('Email Address'); + }); + I.see('Nested Iframe test'); + I.dontSee('Email Address'); +}); + +Scenario('within on nested iframe (depth=2) and mixed class and xpath selector @WebDriverIO', (I) => { + I.amOnPage('/iframe_nested'); + within({frame: ['.wrapperClass', '[name=content]']}, () => { + I.fillField('rus', 'Updated'); + I.click('Sign in!'); + I.see('Email Address'); + }); + I.see('Nested Iframe test'); + I.dontSee('Email Address'); }); \ No newline at end of file diff --git a/test/data/app/controllers.php b/test/data/app/controllers.php index f64d559a7..e22396679 100755 --- a/test/data/app/controllers.php +++ b/test/data/app/controllers.php @@ -154,6 +154,13 @@ public function GET() } } +class iframe_nested { + public function GET() + { + include __DIR__.'/view/iframe_nested.php'; + } +} + class facebookController { function GET($matches) { include __DIR__.'/view/facebook.php'; diff --git a/test/data/app/index.php b/test/data/app/index.php index b24e41737..c04b259e9 100755 --- a/test/data/app/index.php +++ b/test/data/app/index.php @@ -38,6 +38,7 @@ '/external_url' => 'external_url', '/spinner' => 'spinner', '/iframe' => 'iframe', + '/iframe_nested' => 'iframe_nested', '/dynamic' => 'dynamic', '/timeout' => 'timeout', ); diff --git a/test/data/app/view/iframe_nested.php b/test/data/app/view/iframe_nested.php new file mode 100644 index 000000000..49b2c4f82 --- /dev/null +++ b/test/data/app/view/iframe_nested.php @@ -0,0 +1,13 @@ + + + + + + + +

Nested Iframe test

+ +