-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathkarma-playwright-launcher.cjs
More file actions
105 lines (89 loc) · 2.7 KB
/
Copy pathkarma-playwright-launcher.cjs
File metadata and controls
105 lines (89 loc) · 2.7 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const { devices, chromium, firefox, webkit } = require('playwright');
function playwrightBrowser(self, name, browserType, headless, args, logger) {
self.name = self.displayName = name;
self.on('start', async url => {
const log = logger.create(self.displayName);
try {
self._browser = await browserType.launch({ headless, ...args.launchOptions });
self._page = await self._browser.newPage({ ...devices[args.device], ...args.contextOptions });
await self._page.goto(url);
} catch (err) {
log.error(err);
self._done('failure');
}
});
self.on('kill', async done => {
const log = logger.create(self.displayName);
try {
if (self._page) {
// explicitly closing the page avoids page reload errors using new headless mode
await self._page.close();
}
if (self._browser) {
await self._browser.close();
}
} catch (err) {
log.error(err);
}
self._done();
return process.nextTick(done);
});
}
function ChromiumHeadlessBrowser(
args,
logger,
baseLauncherDecorator,
captureTimeoutLauncherDecorator,
retryLauncherDecorator
) {
baseLauncherDecorator(this);
captureTimeoutLauncherDecorator(this);
retryLauncherDecorator(this);
const defaultArgs = {
device: 'Desktop Chrome',
launchOptions: {
// this enables the new headless mode
channel: 'chromium'
}
};
playwrightBrowser(this, 'ChromiumHeadless', chromium, true, { ...defaultArgs, ...args }, logger);
}
function FirefoxHeadlessBrowser(
args,
logger,
baseLauncherDecorator,
captureTimeoutLauncherDecorator,
retryLauncherDecorator
) {
baseLauncherDecorator(this);
captureTimeoutLauncherDecorator(this);
retryLauncherDecorator(this);
const defaultArgs = {
device: 'Desktop Firefox',
launchOptions: {
// this aligns the default font with Chromium where setting this is...hard
firefoxUserPrefs: { 'font.name.sans-serif.x-western': 'Liberation Sans' }
}
};
playwrightBrowser(this, 'FirefoxHeadless', firefox, true, { ...defaultArgs, ...args }, logger);
}
function SafariHeadlessBrowser(
args,
logger,
baseLauncherDecorator,
captureTimeoutLauncherDecorator,
retryLauncherDecorator
) {
baseLauncherDecorator(this);
captureTimeoutLauncherDecorator(this);
retryLauncherDecorator(this);
const defaultArgs = {
device: 'Desktop Safari'
};
playwrightBrowser(this, 'SafariHeadless', webkit, true, { ...defaultArgs, ...args }, logger);
}
module.exports = {
'launcher:PlaywrightChromiumHeadless': ['type', ChromiumHeadlessBrowser],
'launcher:PlaywrightFirefoxHeadless': ['type', FirefoxHeadlessBrowser],
'launcher:PlaywrightSafariHeadless': ['type', SafariHeadlessBrowser]
};