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:
JoelEinbinder 2017-07-27 11:36:03 -07:00 committed by Andrey Lushnikov
parent dd1459b733
commit 70f77c1981
2 changed files with 25 additions and 1 deletions

View File

@ -861,7 +861,11 @@ Returns `true` if the frame has being detached, or `false` otherwise.
#### frame.name() #### frame.name()
- returns: <[string]> - 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() #### frame.parentFrame()
- returns: <[Frame]> Returns parent frame, if any. Detached frames and main frames return `null`. - returns: <[Frame]> Returns parent frame, if any. Detached frames and main frames return `null`.

View File

@ -740,6 +740,26 @@ describe('Puppeteer', function() {
expect(detachedFrames.length).toBe(4); expect(detachedFrames.length).toBe(4);
expect(navigatedFrames.length).toBe(1); 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() { describe('input', function() {