Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ class Playwright extends Helper {
await this.switchTo(null);
return frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve());
}
await this.switchTo(locator);
this.withinLocator = new Locator(locator);
await this.switchTo(frame);
this.withinLocator = new Locator(frame);
return;
}

Expand Down Expand Up @@ -2551,22 +2551,25 @@ class Playwright extends Helper {

// iframe by selector
const els = await this._locate(locator);
// assertElementExists(els, locator);
if (!els[0]) {
throw new Error(`Element ${JSON.stringify(locator)} was not found by text|CSS|XPath`);
}

// get content of the first iframe
if ((locator.frame && locator.frame === 'iframe') || locator.toLowerCase() === 'iframe') {
locator = new Locator(locator, 'css');
if ((locator.frame && locator.frame === 'iframe') || locator.value.toLowerCase() === 'iframe') {
contentFrame = await this.page.frames()[1];
// get content of the iframe using its name
} else if (locator.toLowerCase().includes('name=')) {
const frameName = locator.split('=')[1].replace(/"/g, '').replaceAll(/]/g, '');
} else if (locator.value.toLowerCase().includes('name=')) {
const frameName = locator.value.split('=')[1].replace(/"/g, '').replaceAll(/]/g, '');
contentFrame = await this.page.frame(frameName);
}

if (contentFrame) {
this.context = contentFrame;
this.contextLocator = null;
} else {
this.context = els[0];
this.context = this.page.frame(this.page.frames()[1].name());
this.contextLocator = locator;
}
}
Expand Down Expand Up @@ -3514,7 +3517,10 @@ async function elementSelected(element) {

function isFrameLocator(locator) {
locator = new Locator(locator);
if (locator.isFrame()) return locator.value;
if (locator.isFrame()) {
const _locator = new Locator(locator.value);
return _locator.value;
}
return false;
}

Expand Down
9 changes: 6 additions & 3 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ class Puppeteer extends Helper {
return this.switchTo(null)
.then(() => frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve()));
}
await this.switchTo(locator);
this.withinLocator = new Locator(locator);
await this.switchTo(frame);
this.withinLocator = new Locator(frame);
return;
}

Expand Down Expand Up @@ -2602,7 +2602,10 @@ async function elementSelected(element) {

function isFrameLocator(locator) {
locator = new Locator(locator);
if (locator.isFrame()) return locator.value;
if (locator.isFrame()) {
const _locator = new Locator(locator);
return _locator.value;
}
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions test/data/app/view/iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<h1>Iframe test</h1>

<iframe name="content" src="info" />
<iframe name="content" src="info" id="number-frame-1234"/>

</body>
</html>
</html>
32 changes: 31 additions & 1 deletion test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ module.exports.tests = function () {
if (isHelper('TestCafe')) this.skip(); // TODO Not yet implemented

await I.amOnPage('/iframe');
await I.switchTo('iframe');
await I.switchTo({ css: 'iframe' });
const val = await I.executeScript(() => document.getElementsByTagName('h1')[0].innerText);
assert.equal(val, 'Information');
});
Expand Down Expand Up @@ -1195,6 +1195,36 @@ module.exports.tests = function () {
if (!err) assert.fail('seen "Iframe test"');
}
});

it('within should respect context in see when using frame', async function () {
if (isHelper('TestCafe')) this.skip();

await I.amOnPage('/iframe');
await I._withinBegin({
frame: '#number-frame-1234',
});

try {
await I.see('Information');
} catch (err) {
if (!err) assert.fail('seen "Information"');
}
});

it('within should respect context in see when using frame with strict locator', async function () {
if (isHelper('TestCafe')) this.skip();

await I.amOnPage('/iframe');
await I._withinBegin({
frame: { css: '#number-frame-1234' },
});

try {
await I.see('Information');
} catch (err) {
if (!err) assert.fail('seen "Information"');
}
});
});

describe('scroll: #scrollTo, #scrollPageToTop, #scrollPageToBottom', () => {
Expand Down