2020-08-05 01:57:25 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-08-20 07:32:12 +03:00
|
|
|
import { options } from './playwright.fixtures';
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-08-19 23:30:54 +03:00
|
|
|
it.skip(options.WIRE).slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
|
|
|
{
|
|
|
|
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
|
|
|
|
const browserContext = await browser.newContext();
|
|
|
|
const page = await browserContext.newPage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await browser.close();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
|
|
|
|
const browserContext = await browser.newContext();
|
|
|
|
const page = await browserContext.newPage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await browser.close();
|
|
|
|
}
|
|
|
|
await browserServer.close();
|
|
|
|
});
|
|
|
|
|
2020-08-20 22:51:05 +03:00
|
|
|
it.skip(options.WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
|
|
|
const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') };
|
2020-08-07 00:12:14 +03:00
|
|
|
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e);
|
2020-08-05 01:57:25 +03:00
|
|
|
await browserServer.close();
|
|
|
|
expect(error.message).toContain('Dummy');
|
|
|
|
});
|
|
|
|
|
2020-08-19 23:30:54 +03:00
|
|
|
it.skip(options.WIRE)('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
|
|
|
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
|
|
|
|
expect(remote.isConnected()).toBe(true);
|
|
|
|
await remote.close();
|
|
|
|
expect(remote.isConnected()).toBe(false);
|
|
|
|
await browserServer.close();
|
|
|
|
});
|
|
|
|
|
2020-08-19 23:30:54 +03:00
|
|
|
it.skip(options.WIRE)('should throw when used after isConnected returns false', async({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
|
|
|
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
|
|
|
|
const page = await remote.newPage();
|
|
|
|
await Promise.all([
|
|
|
|
browserServer.close(),
|
|
|
|
new Promise(f => remote.once('disconnected', f)),
|
|
|
|
]);
|
|
|
|
expect(remote.isConnected()).toBe(false);
|
2020-08-07 00:12:14 +03:00
|
|
|
const error = await page.evaluate('1 + 1').catch(e => e) as Error;
|
2020-08-05 01:57:25 +03:00
|
|
|
expect(error.message).toContain('has been closed');
|
|
|
|
});
|