Thanks to visit codestin.com
Credit goes to github.com

Skip to content
6 changes: 4 additions & 2 deletions docs/acceptance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
```

---
Expand Down
6 changes: 6 additions & 0 deletions lib/helper/WebDriverIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
57 changes: 55 additions & 2 deletions test/acceptance/within_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
});
7 changes: 7 additions & 0 deletions test/data/app/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions test/data/app/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'/external_url' => 'external_url',
'/spinner' => 'spinner',
'/iframe' => 'iframe',
'/iframe_nested' => 'iframe_nested',
'/dynamic' => 'dynamic',
'/timeout' => 'timeout',
);
Expand Down
13 changes: 13 additions & 0 deletions test/data/app/view/iframe_nested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>

<h1>Nested Iframe test</h1>

<iframe id="wrapperId" name="wrapper" class="wrapperClass" src="iframe" style="width: 600px; height: 600px"/>

</body>
</html>
2 changes: 1 addition & 1 deletion test/helper/Nightmare_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Nightmare', function () {

I = new Nightmare({
url: site_url,
windowSize: '500x400',
windowSize: '500x700',
show: false
});
I._init();
Expand Down
2 changes: 1 addition & 1 deletion test/helper/SeleniumWebdriver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('SeleniumWebdriver', function () {
I = new SeleniumWebdriver({
url: site_url,
browser: 'chrome',
windowSize: '500x400',
windowSize: '500x700',
restart: false

});
Expand Down
2 changes: 1 addition & 1 deletion test/helper/WebDriverIO_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('WebDriverIO', function () {
wd = new WebDriverIO({
url: site_url,
browser: 'chrome',
windowSize: '500x400',
windowSize: '500x700',
smartWait: 10 // just to try
});
});
Expand Down
19 changes: 18 additions & 1 deletion test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ module.exports.tests = function() {
it('should set initial window size', () => {
return I.amOnPage('/form/resize')
.then(() => I.click('Window Size'))
.then(() => I.see('Height 400', '#height'))
.then(() => I.see('Height 700', '#height'))
.then(() => I.see('Width 500', '#width'));
});

Expand Down Expand Up @@ -678,6 +678,23 @@ module.exports.tests = function() {
if (!err) assert.fail('seen fieldset');
});
});

it('within should respect context in see when using nested frames', () => {
return I.amOnPage('/iframe_nested')
.then(() => I._withinBegin({frame: ['#wrapperId', '[name=content]']}))
.then(() => I.see('Kill & Destroy'))
.catch((err) => {
if (!err) assert.fail('seen "Kill & Destroy"');
})
.then(() => I.dontSee('Nested Iframe test'))
.catch((err) => {
if (!err) assert.fail('seen "Nested Iframe test"');
})
.then(() => I.dontSee('Iframe test'))
.catch((err) => {
if (!err) assert.fail('seen "Iframe test"');
});
});
});

};