From 91bb118bf9a49655ca389f8b970683faa3de95a8 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Tue, 24 Oct 2017 23:23:25 +0200 Subject: [PATCH 1/7] [WebDriverIO] Added support for nested iframes in the within block --- docs/acceptance.md | 2 +- lib/helper/WebDriverIO.js | 6 +++++ test/acceptance/within_test.js | 33 ++++++++++++++++++++++++++++ test/data/app/controllers.php | 7 ++++++ test/data/app/index.php | 1 + test/data/app/view/iframe_nested.php | 13 +++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/data/app/view/iframe_nested.php diff --git a/docs/acceptance.md b/docs/acceptance.md index 33d44b2f7..71f49e5bf 100644 --- a/docs/acceptance.md +++ b/docs/acceptance.md @@ -246,7 +246,7 @@ 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"]); 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..bc267dbf4 100644 --- a/test/acceptance/within_test.js +++ b/test/acceptance/within_test.js @@ -31,4 +31,37 @@ Scenario('within on nested iframe @nightmare', (I) => { }); I.see('Iframe test'); I.dontSee('Email Address'); +}); + +Scenario('within on nested iframe with a depth of 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 with a depth of 2 using ids @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 with a depth of 2 using class @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..2aac4a7d9 --- /dev/null +++ b/test/data/app/view/iframe_nested.php @@ -0,0 +1,13 @@ + + + + + + + +

Nested Iframe test

+ +