feat(Targets): expose browser target (#2036)

This patch exposes "browser" target to the list of targets.
This commit is contained in:
Andrey Lushnikov 2018-02-15 13:24:24 -08:00 committed by GitHub
parent e8a085ccfb
commit fc94f98247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -2483,7 +2483,7 @@ If the target is not of type `"page"`, returns `null`.
#### target.type()
- returns: <[string]>
Identifies what kind of target this is. Can be `"page"`, `"service_worker"`, or `"other"`.
Identifies what kind of target this is. Can be `"page"`, `"service_worker"`, `"browser"` or `"other"`.
#### target.url()
- returns: <[string]>

View File

@ -229,11 +229,11 @@ class Target {
}
/**
* @return {"page"|"service_worker"|"other"}
* @return {"page"|"service_worker"|"other"|"browser"}
*/
type() {
const type = this._targetInfo.type;
if (type === 'page' || type === 'service_worker')
if (type === 'page' || type === 'service_worker' || type === 'browser')
return type;
return 'other';
}

View File

@ -3608,8 +3608,7 @@ describe('Page', function() {
const targets = browser.targets();
expect(targets.some(target => target.type() === 'page' &&
target.url() === 'about:blank')).toBeTruthy('Missing blank page');
expect(targets.some(target => target.type() === 'other' &&
target.url() === '')).toBeTruthy('Missing browser target');
expect(targets.some(target => target.type() === 'browser')).toBeTruthy('Missing browser target');
});
it('Browser.pages should return all of the pages', async({page, server, browser}) => {
// The pages will be the testing page and the original newtab page
@ -3618,6 +3617,11 @@ describe('Page', function() {
expect(allPages).toContain(page);
expect(allPages[0]).not.toBe(allPages[1]);
});
it('should contain browser target', async({browser}) => {
const targets = browser.targets();
const browserTarget = targets.find(target => target.type() === 'browser');
expect(browserTarget).toBeTruthy();
});
it('should be able to use the default page in the browser', async({page, server, browser}) => {
// The pages will be the testing page and the original newtab page
const allPages = await browser.pages();