mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
add tests for Frame class
This patch: - improves documentation of frame.name() - adds a test for frame.name() - adds a test for frame.parent() References #50.
This commit is contained in:
parent
dd1459b733
commit
70f77c1981
@ -861,7 +861,11 @@ Returns `true` if the frame has being detached, or `false` otherwise.
|
||||
#### frame.name()
|
||||
- returns: <[string]>
|
||||
|
||||
Returns frame's name as specified in the tag.
|
||||
Returns frame's name attribute as specified in the tag.
|
||||
|
||||
If the name is empty, returns the id attribute instead.
|
||||
|
||||
Note: This value is calculated once when the frame is created, and will not update if the attribute is changed later.
|
||||
|
||||
#### frame.parentFrame()
|
||||
- returns: <[Frame]> Returns parent frame, if any. Detached frames and main frames return `null`.
|
||||
|
20
test/test.js
20
test/test.js
@ -740,6 +740,26 @@ describe('Puppeteer', function() {
|
||||
expect(detachedFrames.length).toBe(4);
|
||||
expect(navigatedFrames.length).toBe(1);
|
||||
}));
|
||||
it('should report frame.name()', SX(async function() {
|
||||
await FrameUtils.attachFrame(page, 'theFrameId', EMPTY_PAGE);
|
||||
await page.evaluate(url => {
|
||||
let frame = document.createElement('iframe');
|
||||
frame.name = 'theFrameName';
|
||||
frame.src = url;
|
||||
document.body.appendChild(frame);
|
||||
return new Promise(x => frame.onload = x);
|
||||
}, EMPTY_PAGE);
|
||||
expect(page.frames()[0].name()).toBe('');
|
||||
expect(page.frames()[1].name()).toBe('theFrameId');
|
||||
expect(page.frames()[2].name()).toBe('theFrameName');
|
||||
}));
|
||||
it('should report frame.parent()', SX(async function() {
|
||||
await FrameUtils.attachFrame(page, 'frame1', EMPTY_PAGE);
|
||||
await FrameUtils.attachFrame(page, 'frame2', EMPTY_PAGE);
|
||||
expect(page.frames()[0].parentFrame()).toBe(null);
|
||||
expect(page.frames()[1].parentFrame()).toBe(page.mainFrame());
|
||||
expect(page.frames()[2].parentFrame()).toBe(page.mainFrame());
|
||||
}));
|
||||
});
|
||||
|
||||
describe('input', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user