1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/**
* @license
* Copyright 2018 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import expect from 'expect';
import {getTestState, setupTestBrowserHooks} from './mocha-utils.js';
describe('Browser specs', function () {
setupTestBrowserHooks();
describe('Browser.version', function () {
it('should return version', async () => {
const {browser} = await getTestState();
const version = await browser.version();
expect(version.length).toBeGreaterThan(0);
expect(version.toLowerCase()).atLeastOneToContain(['firefox', 'chrome']);
});
});
describe('Browser.userAgent', function () {
it('should include Browser engine', async () => {
const {browser, isChrome} = await getTestState();
const userAgent = await browser.userAgent();
expect(userAgent.length).toBeGreaterThan(0);
if (isChrome) {
expect(userAgent).toContain('WebKit');
} else {
expect(userAgent).toContain('Gecko');
}
});
});
describe('Browser.target', function () {
it('should return browser target', async () => {
const {browser} = await getTestState();
const target = browser.target();
expect(target.type()).toBe('browser');
});
});
describe('Browser.process', function () {
it('should return child_process instance', async () => {
const {browser} = await getTestState();
const process = await browser.process();
expect(process!.pid).toBeGreaterThan(0);
});
it('should not return child_process for remote browser', async () => {
const {browser, puppeteer} = await getTestState({
skipContextCreation: true,
});
const browserWSEndpoint = browser.wsEndpoint();
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
expect(remoteBrowser.process()).toBe(null);
await remoteBrowser.disconnect();
});
});
describe('Browser.isConnected', () => {
it('should set the browser connected state', async () => {
const {browser, puppeteer} = await getTestState({
skipContextCreation: true,
});
const browserWSEndpoint = browser.wsEndpoint();
const newBrowser = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
expect(newBrowser.isConnected()).toBe(true);
await newBrowser.disconnect();
expect(newBrowser.isConnected()).toBe(false);
});
});
});
|