@wdio/selenium-devtools 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assertPatcher.d.ts +11 -0
- package/dist/assertPatcher.js +123 -0
- package/dist/assertPatcher.js.map +1 -0
- package/dist/bidi.d.ts +6 -0
- package/dist/bidi.js +222 -0
- package/dist/bidi.js.map +1 -0
- package/dist/constants.d.ts +75 -0
- package/dist/constants.js +146 -0
- package/dist/constants.js.map +1 -0
- package/dist/driverPatcher.d.ts +4 -0
- package/dist/driverPatcher.js +256 -0
- package/dist/driverPatcher.js.map +1 -0
- package/dist/helpers/detachedBackend.d.ts +7 -0
- package/dist/helpers/detachedBackend.js +34 -0
- package/dist/helpers/detachedBackend.js.map +1 -0
- package/dist/helpers/runtime.d.ts +3 -0
- package/dist/helpers/runtime.js +47 -0
- package/dist/helpers/runtime.js.map +1 -0
- package/dist/helpers/suiteManager.d.ts +19 -0
- package/dist/helpers/suiteManager.js +131 -0
- package/dist/helpers/suiteManager.js.map +1 -0
- package/dist/helpers/testManager.d.ts +47 -0
- package/dist/helpers/testManager.js +158 -0
- package/dist/helpers/testManager.js.map +1 -0
- package/dist/helpers/utils.d.ts +26 -0
- package/dist/helpers/utils.js +187 -0
- package/dist/helpers/utils.js.map +1 -0
- package/dist/helpers/videoEncoder.d.ts +2 -0
- package/dist/helpers/videoEncoder.js +89 -0
- package/dist/helpers/videoEncoder.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +801 -0
- package/dist/index.js.map +1 -0
- package/dist/reporter.d.ts +18 -0
- package/dist/reporter.js +72 -0
- package/dist/reporter.js.map +1 -0
- package/dist/rerunManager.d.ts +8 -0
- package/dist/rerunManager.js +78 -0
- package/dist/rerunManager.js.map +1 -0
- package/dist/runnerHooks.d.ts +6 -0
- package/dist/runnerHooks.js +594 -0
- package/dist/runnerHooks.js.map +1 -0
- package/dist/screencast.d.ts +11 -0
- package/dist/screencast.js +179 -0
- package/dist/screencast.js.map +1 -0
- package/dist/session.d.ts +48 -0
- package/dist/session.js +480 -0
- package/dist/session.js.map +1 -0
- package/dist/setupConsole.d.ts +1 -0
- package/dist/setupConsole.js +13 -0
- package/dist/setupConsole.js.map +1 -0
- package/dist/types.d.ts +235 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CapturedCommand } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Patch `node:assert` so each tracked method emits a `CapturedCommand` to
|
|
4
|
+
* the supplied hook. Idempotent — calling twice doesn't double-wrap.
|
|
5
|
+
*
|
|
6
|
+
* Note: we patch BOTH the function-form (`assert(...)`) and the namespace
|
|
7
|
+
* methods (`assert.equal(...)`). User code that imported the methods BEFORE
|
|
8
|
+
* this patcher loaded will already have stale references — to be safe,
|
|
9
|
+
* the plugin's main entry imports node:assert before the user's test files.
|
|
10
|
+
*/
|
|
11
|
+
export declare function patchNodeAssert(onCommand: (cmd: CapturedCommand) => void): boolean;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import logger from '@wdio/logger';
|
|
3
|
+
import { ASSERT_PATCHED_SYMBOL, TRACKED_ASSERT_METHODS } from './constants.js';
|
|
4
|
+
import { getCallSourceFromStack } from './helpers/utils.js';
|
|
5
|
+
const log = logger('@wdio/selenium-devtools:assertPatcher');
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
function safeSerialize(value) {
|
|
8
|
+
if (value === null || value === undefined) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
if (value instanceof RegExp) {
|
|
12
|
+
return value.toString();
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'function') {
|
|
15
|
+
return '[Function]';
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'object') {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(JSON.stringify(value));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return String(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Patch `node:assert` so each tracked method emits a `CapturedCommand` to
|
|
29
|
+
* the supplied hook. Idempotent — calling twice doesn't double-wrap.
|
|
30
|
+
*
|
|
31
|
+
* Note: we patch BOTH the function-form (`assert(...)`) and the namespace
|
|
32
|
+
* methods (`assert.equal(...)`). User code that imported the methods BEFORE
|
|
33
|
+
* this patcher loaded will already have stale references — to be safe,
|
|
34
|
+
* the plugin's main entry imports node:assert before the user's test files.
|
|
35
|
+
*/
|
|
36
|
+
export function patchNodeAssert(onCommand) {
|
|
37
|
+
let assertModule;
|
|
38
|
+
try {
|
|
39
|
+
assertModule = require('node:assert');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
log.warn('node:assert not available — skipping assertion capture');
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (assertModule[ASSERT_PATCHED_SYMBOL]) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
;
|
|
49
|
+
assertModule[ASSERT_PATCHED_SYMBOL] = true;
|
|
50
|
+
// Wrap each tracked method on `assert` and `assert.strict`. We don't
|
|
51
|
+
// overwrite `assert.strict.equal` separately because Node's strict
|
|
52
|
+
// namespace shares method bodies internally — patching the surface is
|
|
53
|
+
// enough.
|
|
54
|
+
const wrapMethod = (methodName) => {
|
|
55
|
+
const original = assertModule[methodName];
|
|
56
|
+
if (typeof original !== 'function') {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
assertModule[methodName] = function patchedAssert(...args) {
|
|
61
|
+
const callInfo = getCallSourceFromStack();
|
|
62
|
+
const startedAt = Date.now();
|
|
63
|
+
const sanitizedArgs = args.map(safeSerialize);
|
|
64
|
+
try {
|
|
65
|
+
const result = original.apply(this, args);
|
|
66
|
+
// Async assert methods (rejects/doesNotReject) return a Promise.
|
|
67
|
+
if (result && typeof result.then === 'function') {
|
|
68
|
+
return result.then((v) => {
|
|
69
|
+
onCommand({
|
|
70
|
+
command: `assert.${methodName}`,
|
|
71
|
+
args: sanitizedArgs,
|
|
72
|
+
result: 'passed',
|
|
73
|
+
error: undefined,
|
|
74
|
+
callSource: callInfo.callSource,
|
|
75
|
+
timestamp: startedAt,
|
|
76
|
+
fromElement: false
|
|
77
|
+
});
|
|
78
|
+
return v;
|
|
79
|
+
}, (err) => {
|
|
80
|
+
onCommand({
|
|
81
|
+
command: `assert.${methodName}`,
|
|
82
|
+
args: sanitizedArgs,
|
|
83
|
+
result: undefined,
|
|
84
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
85
|
+
callSource: callInfo.callSource,
|
|
86
|
+
timestamp: startedAt,
|
|
87
|
+
fromElement: false
|
|
88
|
+
});
|
|
89
|
+
throw err;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
onCommand({
|
|
93
|
+
command: `assert.${methodName}`,
|
|
94
|
+
args: sanitizedArgs,
|
|
95
|
+
result: 'passed',
|
|
96
|
+
error: undefined,
|
|
97
|
+
callSource: callInfo.callSource,
|
|
98
|
+
timestamp: startedAt,
|
|
99
|
+
fromElement: false
|
|
100
|
+
});
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
onCommand({
|
|
105
|
+
command: `assert.${methodName}`,
|
|
106
|
+
args: sanitizedArgs,
|
|
107
|
+
result: undefined,
|
|
108
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
109
|
+
callSource: callInfo.callSource,
|
|
110
|
+
timestamp: startedAt,
|
|
111
|
+
fromElement: false
|
|
112
|
+
});
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
for (const m of TRACKED_ASSERT_METHODS) {
|
|
118
|
+
wrapMethod(m);
|
|
119
|
+
}
|
|
120
|
+
log.info(`Patched ${TRACKED_ASSERT_METHODS.length} node:assert method(s)`);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=assertPatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertPatcher.js","sourceRoot":"","sources":["../src/assertPatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAG3D,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAA;AAC3D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C,SAAS,aAAa,CAAC,KAAU;IAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO,YAAY,CAAA;IACrB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAyC;IAEzC,IA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AAC;QACH,CAAC,CAAA;IACH,CAAC,CAAA;IAED,KAAK,MAAM,CAAC,IAAI,sBAAsB,EAAE,CAAC;QACvC,UAAU,CAAC,CAAC,CAAC,CAAA;IACf,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,WAAW,sBAAsB,CAAC,MAAM,wBAAwB,CAAC,CAAA;IAC1E,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/bidi.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BidiHandlerSinks } from './types.js';
|
|
2
|
+
import type { SessionCapturer } from './session.js';
|
|
3
|
+
export declare function ensureBidiCapability(builder: any): void;
|
|
4
|
+
export declare function ensureHeadlessChrome(builder: any): void;
|
|
5
|
+
export declare function attachBidiHandlers(driver: any, sinks: BidiHandlerSinks): Promise<boolean>;
|
|
6
|
+
export declare function buildBidiSinks(capturer: SessionCapturer): BidiHandlerSinks;
|
package/dist/bidi.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import logger from '@wdio/logger';
|
|
3
|
+
import { LOG_SOURCES } from './constants.js';
|
|
4
|
+
import { chromeLogLevelToLogLevel, getRequestType } from './helpers/utils.js';
|
|
5
|
+
const log = logger('@wdio/selenium-devtools:bidi');
|
|
6
|
+
function loadSeleniumSubmodule(subpath) {
|
|
7
|
+
try {
|
|
8
|
+
const userRequire = createRequire(`${process.cwd()}/`);
|
|
9
|
+
return userRequire(`selenium-webdriver/${subpath}`);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
try {
|
|
13
|
+
const localRequire = createRequire(import.meta.url);
|
|
14
|
+
return localRequire(`selenium-webdriver/${subpath}`);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Sets webSocketUrl=true so the driver actually exposes the BiDi channel.
|
|
22
|
+
export function ensureBidiCapability(builder) {
|
|
23
|
+
try {
|
|
24
|
+
const caps = typeof builder?.getCapabilities === 'function'
|
|
25
|
+
? builder.getCapabilities()
|
|
26
|
+
: null;
|
|
27
|
+
if (!caps || typeof caps.set !== 'function') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (typeof caps.has === 'function' && caps.has('webSocketUrl')) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
caps.set('webSocketUrl', true);
|
|
34
|
+
log.info('Set webSocketUrl=true on builder capabilities (BiDi enabled)');
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
log.warn(`Failed to set webSocketUrl capability: ${err.message}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// `--headless=old` (not `=new`) — `new` produces all-black frames under
|
|
41
|
+
// CDP `Page.startScreencast` on macOS (upstream Chrome bug).
|
|
42
|
+
export function ensureHeadlessChrome(builder) {
|
|
43
|
+
try {
|
|
44
|
+
const caps = typeof builder?.getCapabilities === 'function'
|
|
45
|
+
? builder.getCapabilities()
|
|
46
|
+
: null;
|
|
47
|
+
if (!caps || typeof caps.get !== 'function') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const existing = caps.get('goog:chromeOptions') ?? {};
|
|
51
|
+
const args = Array.isArray(existing.args)
|
|
52
|
+
? [...existing.args]
|
|
53
|
+
: [];
|
|
54
|
+
const hasHeadless = args.some((a) => typeof a === 'string' && a.startsWith('--headless'));
|
|
55
|
+
if (hasHeadless) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
args.push('--headless=old');
|
|
59
|
+
caps.set('goog:chromeOptions', { ...existing, args });
|
|
60
|
+
log.info('Injected --headless=old into Chrome capabilities');
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
log.warn(`Failed to set headless Chrome option: ${err.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Returns true when at least one stream connected — caller disables the
|
|
67
|
+
// equivalent script-injection collectors to avoid duplicates.
|
|
68
|
+
export async function attachBidiHandlers(driver, sinks) {
|
|
69
|
+
const logInspectorFactory = loadSeleniumSubmodule('bidi/logInspector');
|
|
70
|
+
const networkInspectorFactory = loadSeleniumSubmodule('bidi/networkInspector');
|
|
71
|
+
let attached = 0;
|
|
72
|
+
if (typeof logInspectorFactory === 'function') {
|
|
73
|
+
try {
|
|
74
|
+
const inspector = await logInspectorFactory(driver);
|
|
75
|
+
await inspector.onConsoleEntry((entry) => {
|
|
76
|
+
try {
|
|
77
|
+
const level = (entry?.level ?? entry?.type ?? 'info').toString();
|
|
78
|
+
const text = entry?.text ?? entry?.message ?? '';
|
|
79
|
+
sinks.pushConsoleLog({
|
|
80
|
+
timestamp: Number(entry?.timestamp) || Date.now(),
|
|
81
|
+
type: chromeLogLevelToLogLevel(level),
|
|
82
|
+
args: [text],
|
|
83
|
+
source: LOG_SOURCES.BROWSER
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
log.warn(`onConsoleEntry handler threw: ${err.message}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
await inspector.onJavascriptException((exception) => {
|
|
91
|
+
try {
|
|
92
|
+
const text = exception?.text ?? exception?.message ?? String(exception);
|
|
93
|
+
const trimmed = String(text).replace(/\s+/g, ' ').slice(0, 200);
|
|
94
|
+
log.warn(`🐛 JS error in page: ${trimmed}${String(text).length > 200 ? '…' : ''}`);
|
|
95
|
+
sinks.pushConsoleLog({
|
|
96
|
+
timestamp: Date.now(),
|
|
97
|
+
type: 'error',
|
|
98
|
+
args: [text],
|
|
99
|
+
source: LOG_SOURCES.BROWSER
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
log.warn(`onJavascriptException handler threw: ${err.message}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
attached++;
|
|
107
|
+
log.info('✓ BiDi LogInspector attached (console + JS exceptions)');
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
log.warn(`BiDi LogInspector attach failed: ${err.message}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
log.info('selenium-webdriver/bidi/logInspector not available — skipping');
|
|
115
|
+
}
|
|
116
|
+
if (typeof networkInspectorFactory === 'function') {
|
|
117
|
+
try {
|
|
118
|
+
const inspector = await networkInspectorFactory(driver);
|
|
119
|
+
const pending = new Map();
|
|
120
|
+
await inspector.beforeRequestSent((event) => {
|
|
121
|
+
try {
|
|
122
|
+
const requestId = String(event?.request?.request ?? event?.id ?? '');
|
|
123
|
+
if (!requestId) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const entry = {
|
|
127
|
+
id: requestId,
|
|
128
|
+
url: event?.request?.url ?? '',
|
|
129
|
+
method: event?.request?.method ?? 'GET',
|
|
130
|
+
requestHeaders: arrayHeadersToObject(event?.request?.headers),
|
|
131
|
+
timestamp: Date.now(),
|
|
132
|
+
startTime: Number(event?.timestamp ?? Date.now()),
|
|
133
|
+
type: getRequestType(event?.request?.url ?? '')
|
|
134
|
+
};
|
|
135
|
+
pending.set(requestId, entry);
|
|
136
|
+
sinks.pushNetworkRequest(entry);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
log.warn(`beforeRequestSent threw: ${err.message}`);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
await inspector.responseCompleted((event) => {
|
|
143
|
+
try {
|
|
144
|
+
const requestId = String(event?.request?.request ?? event?.id ?? '');
|
|
145
|
+
const previous = pending.get(requestId);
|
|
146
|
+
if (!previous) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const finalized = {
|
|
150
|
+
...previous,
|
|
151
|
+
status: Number(event?.response?.status) || previous.status,
|
|
152
|
+
statusText: event?.response?.statusText ?? previous.statusText,
|
|
153
|
+
responseHeaders: arrayHeadersToObject(event?.response?.headers),
|
|
154
|
+
type: getRequestType(previous.url, event?.response?.mimeType),
|
|
155
|
+
endTime: Number(event?.timestamp ?? Date.now()),
|
|
156
|
+
time: Number(event?.timestamp ?? Date.now()) - previous.startTime,
|
|
157
|
+
size: Number(event?.response?.bytesReceived) || undefined
|
|
158
|
+
};
|
|
159
|
+
pending.delete(requestId);
|
|
160
|
+
sinks.replaceNetworkRequest(requestId, finalized);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
log.warn(`responseCompleted threw: ${err.message}`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
attached++;
|
|
167
|
+
log.info('✓ BiDi NetworkInspector attached (request + response)');
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
log.warn(`BiDi NetworkInspector attach failed: ${err.message}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
log.info('selenium-webdriver/bidi/networkInspector not available — skipping');
|
|
175
|
+
}
|
|
176
|
+
return attached > 0;
|
|
177
|
+
}
|
|
178
|
+
// BiDi headers arrive as Array<{name, value:{value|type}}>; flatten to a
|
|
179
|
+
// lowercased dictionary.
|
|
180
|
+
function arrayHeadersToObject(headers) {
|
|
181
|
+
if (!Array.isArray(headers)) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
const out = {};
|
|
185
|
+
for (const h of headers) {
|
|
186
|
+
const name = String(h?.name ?? '').toLowerCase();
|
|
187
|
+
if (!name) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const v = h?.value;
|
|
191
|
+
out[name] =
|
|
192
|
+
typeof v === 'string'
|
|
193
|
+
? v
|
|
194
|
+
: typeof v?.value === 'string'
|
|
195
|
+
? v.value
|
|
196
|
+
: JSON.stringify(v ?? '');
|
|
197
|
+
}
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
200
|
+
export function buildBidiSinks(capturer) {
|
|
201
|
+
return {
|
|
202
|
+
pushConsoleLog: (entry) => {
|
|
203
|
+
capturer.consoleLogs.push(entry);
|
|
204
|
+
capturer.sendUpstream('consoleLogs', [entry]);
|
|
205
|
+
},
|
|
206
|
+
pushNetworkRequest: (entry) => {
|
|
207
|
+
capturer.networkRequests.push(entry);
|
|
208
|
+
capturer.sendUpstream('networkRequests', [entry]);
|
|
209
|
+
},
|
|
210
|
+
replaceNetworkRequest: (id, entry) => {
|
|
211
|
+
const idx = capturer.networkRequests.findIndex((r) => r.id === id);
|
|
212
|
+
if (idx !== -1) {
|
|
213
|
+
capturer.networkRequests[idx] = entry;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
capturer.networkRequests.push(entry);
|
|
217
|
+
}
|
|
218
|
+
capturer.sendUpstream('networkRequests', [entry]);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=bidi.js.map
|
package/dist/bidi.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bidi.js","sourceRoot":"","sources":["../src/bidi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAI7E,MAAM,GAAG,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAA;AAElD,SAAS,qBAAqB,CAAC,OAAe;IAC5C,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QACtD,OAAO,WAAW,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAA;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnD,OAAO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+
/**
|
|
2
|
+
* Selenium WebDriver methods we don't want to surface as user commands.
|
|
3
|
+
* These are either internal lifecycle (quit, close, getSession), capability
|
|
4
|
+
* inspection (getCapabilities), or low-level helpers (sleep, schedule).
|
|
5
|
+
*/
|
|
6
|
+
export declare const INTERNAL_DRIVER_METHODS: readonly ["constructor", "getSession", "getCapabilities", "getExecutor", "execute", "schedule", "manage", "navigate", "switchTo", "actions", "wait", "sleep", "setFileDetector", "getNetworkConnection", "setNetworkConnection", "on", "once", "addListener", "removeListener", "emit", "eventNames", "getBidi", "getCdpTargets", "createCDPConnection", "getWsUrl", "quit", "close"];
|
|
7
|
+
/**
|
|
8
|
+
* WebElement methods we DO surface (everything else is skipped).
|
|
9
|
+
* Whitelist approach because WebElement's prototype carries fewer interesting
|
|
10
|
+
* action methods than WebDriver's, and skipping is cheaper.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TRACKED_ELEMENT_METHODS: readonly ["click", "sendKeys", "clear", "submit", "getText", "getAttribute", "getCssValue", "getRect", "getTagName", "isDisplayed", "isEnabled", "isSelected"];
|
|
13
|
+
export declare const NAVIGATION_COMMANDS: readonly ["get", "navigate", "to", "back", "forward", "refresh"];
|
|
14
|
+
export declare const CONSOLE_METHODS: readonly ["log", "info", "warn", "error"];
|
|
15
|
+
export declare const LOG_SOURCES: {
|
|
16
|
+
readonly BROWSER: "browser";
|
|
17
|
+
readonly TEST: "test";
|
|
18
|
+
readonly TERMINAL: "terminal";
|
|
19
|
+
};
|
|
20
|
+
export declare const ANSI_REGEX: RegExp;
|
|
21
|
+
export declare const SPINNER_RE: RegExp;
|
|
22
|
+
export declare const DEFAULTS: {
|
|
23
|
+
readonly CID: "0-0";
|
|
24
|
+
readonly SESSION_TITLE: "Selenium Session";
|
|
25
|
+
readonly FILE_NAME: "selenium";
|
|
26
|
+
readonly RETRIES: 0;
|
|
27
|
+
readonly DURATION: 0;
|
|
28
|
+
};
|
|
29
|
+
export declare const TIMING: {
|
|
30
|
+
readonly UI_RENDER_DELAY: 150;
|
|
31
|
+
readonly TEST_START_DELAY: 100;
|
|
32
|
+
readonly SUITE_COMPLETE_DELAY: 200;
|
|
33
|
+
readonly UI_CONNECTION_WAIT: 2000;
|
|
34
|
+
readonly BROWSER_CLOSE_WAIT: 2000;
|
|
35
|
+
readonly INITIAL_CONNECTION_WAIT: 500;
|
|
36
|
+
readonly BROWSER_POLL_INTERVAL: 1000;
|
|
37
|
+
};
|
|
38
|
+
export declare const TEST_STATE: {
|
|
39
|
+
readonly PENDING: "pending";
|
|
40
|
+
readonly RUNNING: "running";
|
|
41
|
+
readonly PASSED: "passed";
|
|
42
|
+
readonly FAILED: "failed";
|
|
43
|
+
readonly SKIPPED: "skipped";
|
|
44
|
+
};
|
|
45
|
+
export declare const LOG_LEVEL_PATTERNS: ReadonlyArray<{
|
|
46
|
+
level: 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
47
|
+
pattern: RegExp;
|
|
48
|
+
}>;
|
|
49
|
+
export declare const SCREENCAST_DEFAULTS: {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
captureFormat: "jpeg";
|
|
52
|
+
quality: number;
|
|
53
|
+
maxWidth: number;
|
|
54
|
+
maxHeight: number;
|
|
55
|
+
pollIntervalMs: number;
|
|
56
|
+
};
|
|
57
|
+
/** Test-state environment markers used by the rerun handshake. */
|
|
58
|
+
export declare const REUSE_ENV: {
|
|
59
|
+
readonly REUSE: "DEVTOOLS_APP_REUSE";
|
|
60
|
+
readonly HOST: "DEVTOOLS_APP_HOST";
|
|
61
|
+
readonly PORT: "DEVTOOLS_APP_PORT";
|
|
62
|
+
readonly RERUN_LABEL: "DEVTOOLS_RERUN_LABEL";
|
|
63
|
+
readonly RERUN_ENTRY_TYPE: "DEVTOOLS_RERUN_ENTRY_TYPE";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Decoded JPEG bytes below which a frame is treated as blank/uniform
|
|
67
|
+
* (Chrome's about:blank — solid colour compresses to <2KB; real renders >5KB).
|
|
68
|
+
*/
|
|
69
|
+
export declare const BLANK_FRAME_THRESHOLD_BYTES = 4000;
|
|
70
|
+
/** Per-prototype "already patched" guard for driverPatcher / assertPatcher. */
|
|
71
|
+
export declare const PATCHED_SYMBOL: unique symbol;
|
|
72
|
+
/** Per-prototype guard for the (currently disabled) node:assert patcher. */
|
|
73
|
+
export declare const ASSERT_PATCHED_SYMBOL: unique symbol;
|
|
74
|
+
/** node:assert methods the (currently disabled) assertPatcher would wrap. */
|
|
75
|
+
export declare const TRACKED_ASSERT_METHODS: readonly ["equal", "strictEqual", "deepEqual", "deepStrictEqual", "notEqual", "notStrictEqual", "notDeepEqual", "notDeepStrictEqual", "ok", "fail", "throws", "doesNotThrow", "rejects", "doesNotReject", "match", "doesNotMatch"];
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selenium WebDriver methods we don't want to surface as user commands.
|
|
3
|
+
* These are either internal lifecycle (quit, close, getSession), capability
|
|
4
|
+
* inspection (getCapabilities), or low-level helpers (sleep, schedule).
|
|
5
|
+
*/
|
|
6
|
+
export const INTERNAL_DRIVER_METHODS = [
|
|
7
|
+
'constructor',
|
|
8
|
+
'getSession',
|
|
9
|
+
'getCapabilities',
|
|
10
|
+
'getExecutor',
|
|
11
|
+
'execute',
|
|
12
|
+
'schedule',
|
|
13
|
+
'manage',
|
|
14
|
+
'navigate',
|
|
15
|
+
'switchTo',
|
|
16
|
+
'actions',
|
|
17
|
+
'wait',
|
|
18
|
+
'sleep',
|
|
19
|
+
'setFileDetector',
|
|
20
|
+
'getNetworkConnection',
|
|
21
|
+
'setNetworkConnection',
|
|
22
|
+
'on',
|
|
23
|
+
'once',
|
|
24
|
+
'addListener',
|
|
25
|
+
'removeListener',
|
|
26
|
+
'emit',
|
|
27
|
+
'eventNames',
|
|
28
|
+
/* Plumbing — selenium-webdriver itself calls these during BiDi/CDP setup. */
|
|
29
|
+
'getBidi',
|
|
30
|
+
'getCdpTargets',
|
|
31
|
+
'createCDPConnection',
|
|
32
|
+
'getWsUrl',
|
|
33
|
+
/* These are wrapped separately — see patchSelenium quit/close interceptors. */
|
|
34
|
+
'quit',
|
|
35
|
+
'close'
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* WebElement methods we DO surface (everything else is skipped).
|
|
39
|
+
* Whitelist approach because WebElement's prototype carries fewer interesting
|
|
40
|
+
* action methods than WebDriver's, and skipping is cheaper.
|
|
41
|
+
*/
|
|
42
|
+
export const TRACKED_ELEMENT_METHODS = [
|
|
43
|
+
'click',
|
|
44
|
+
'sendKeys',
|
|
45
|
+
'clear',
|
|
46
|
+
'submit',
|
|
47
|
+
'getText',
|
|
48
|
+
'getAttribute',
|
|
49
|
+
'getCssValue',
|
|
50
|
+
'getRect',
|
|
51
|
+
'getTagName',
|
|
52
|
+
'isDisplayed',
|
|
53
|
+
'isEnabled',
|
|
54
|
+
'isSelected'
|
|
55
|
+
];
|
|
56
|
+
export const NAVIGATION_COMMANDS = [
|
|
57
|
+
'get',
|
|
58
|
+
'navigate',
|
|
59
|
+
'to',
|
|
60
|
+
'back',
|
|
61
|
+
'forward',
|
|
62
|
+
'refresh'
|
|
63
|
+
];
|
|
64
|
+
export const CONSOLE_METHODS = ['log', 'info', 'warn', 'error'];
|
|
65
|
+
export const LOG_SOURCES = {
|
|
66
|
+
BROWSER: 'browser',
|
|
67
|
+
TEST: 'test',
|
|
68
|
+
TERMINAL: 'terminal'
|
|
69
|
+
};
|
|
70
|
+
export const ANSI_REGEX = /\x1b\[[?]?[0-9;]*[A-Za-z]/g;
|
|
71
|
+
export const SPINNER_RE = /^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/u;
|
|
72
|
+
export const DEFAULTS = {
|
|
73
|
+
CID: '0-0',
|
|
74
|
+
SESSION_TITLE: 'Selenium Session',
|
|
75
|
+
FILE_NAME: 'selenium',
|
|
76
|
+
RETRIES: 0,
|
|
77
|
+
DURATION: 0
|
|
78
|
+
};
|
|
79
|
+
export const TIMING = {
|
|
80
|
+
UI_RENDER_DELAY: 150,
|
|
81
|
+
TEST_START_DELAY: 100,
|
|
82
|
+
SUITE_COMPLETE_DELAY: 200,
|
|
83
|
+
UI_CONNECTION_WAIT: 2000,
|
|
84
|
+
BROWSER_CLOSE_WAIT: 2000,
|
|
85
|
+
INITIAL_CONNECTION_WAIT: 500,
|
|
86
|
+
BROWSER_POLL_INTERVAL: 1000
|
|
87
|
+
};
|
|
88
|
+
export const TEST_STATE = {
|
|
89
|
+
PENDING: 'pending',
|
|
90
|
+
RUNNING: 'running',
|
|
91
|
+
PASSED: 'passed',
|
|
92
|
+
FAILED: 'failed',
|
|
93
|
+
SKIPPED: 'skipped'
|
|
94
|
+
};
|
|
95
|
+
export const LOG_LEVEL_PATTERNS = [
|
|
96
|
+
{ level: 'trace', pattern: /\btrace\b/i },
|
|
97
|
+
{ level: 'debug', pattern: /\bdebug\b/i },
|
|
98
|
+
{ level: 'info', pattern: /\binfo\b/i },
|
|
99
|
+
{ level: 'warn', pattern: /\bwarn(ing)?\b/i },
|
|
100
|
+
{ level: 'error', pattern: /\berror\b/i }
|
|
101
|
+
];
|
|
102
|
+
export const SCREENCAST_DEFAULTS = {
|
|
103
|
+
enabled: false,
|
|
104
|
+
captureFormat: 'jpeg',
|
|
105
|
+
quality: 70,
|
|
106
|
+
maxWidth: 1280,
|
|
107
|
+
maxHeight: 720,
|
|
108
|
+
pollIntervalMs: 200
|
|
109
|
+
};
|
|
110
|
+
/** Test-state environment markers used by the rerun handshake. */
|
|
111
|
+
export const REUSE_ENV = {
|
|
112
|
+
REUSE: 'DEVTOOLS_APP_REUSE',
|
|
113
|
+
HOST: 'DEVTOOLS_APP_HOST',
|
|
114
|
+
PORT: 'DEVTOOLS_APP_PORT',
|
|
115
|
+
RERUN_LABEL: 'DEVTOOLS_RERUN_LABEL',
|
|
116
|
+
RERUN_ENTRY_TYPE: 'DEVTOOLS_RERUN_ENTRY_TYPE'
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Decoded JPEG bytes below which a frame is treated as blank/uniform
|
|
120
|
+
* (Chrome's about:blank — solid colour compresses to <2KB; real renders >5KB).
|
|
121
|
+
*/
|
|
122
|
+
export const BLANK_FRAME_THRESHOLD_BYTES = 4_000;
|
|
123
|
+
/** Per-prototype "already patched" guard for driverPatcher / assertPatcher. */
|
|
124
|
+
export const PATCHED_SYMBOL = Symbol.for('@wdio/selenium-devtools/patched');
|
|
125
|
+
/** Per-prototype guard for the (currently disabled) node:assert patcher. */
|
|
126
|
+
export const ASSERT_PATCHED_SYMBOL = Symbol.for('@wdio/selenium-devtools/assert-patched');
|
|
127
|
+
/** node:assert methods the (currently disabled) assertPatcher would wrap. */
|
|
128
|
+
export const TRACKED_ASSERT_METHODS = [
|
|
129
|
+
'equal',
|
|
130
|
+
'strictEqual',
|
|
131
|
+
'deepEqual',
|
|
132
|
+
'deepStrictEqual',
|
|
133
|
+
'notEqual',
|
|
134
|
+
'notStrictEqual',
|
|
135
|
+
'notDeepEqual',
|
|
136
|
+
'notDeepStrictEqual',
|
|
137
|
+
'ok',
|
|
138
|
+
'fail',
|
|
139
|
+
'throws',
|
|
140
|
+
'doesNotThrow',
|
|
141
|
+
'rejects',
|
|
142
|
+
'doesNotReject',
|
|
143
|
+
'match',
|
|
144
|
+
'doesNotMatch'
|
|
145
|
+
];
|
|
146
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,aAAa;IACb,YAAY;IACZ,iBAAiB;IACjB,aAAa;IACb,SAAS;IACT,UAAU;IACV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,SAAS;IACT,MAAM;IACN,OAAO;IACP,iBAAiB;IACjB,sBAAsB;IACtB,sBAAsB;IACtB,IAAI;IACJ,MAAM;IACN,aAA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;IACjB,UAAU;IACV,gBAAgB;IAChB,cAAc;IACd,oBAAoB;IACpB,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,cAAc;IACd,SAAS;IACT,eAAe;IACf,OAAO;IACP,cAAc;CACN,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DriverOriginals, DriverPatcherHooks, ElementOriginals } from './types.js';
|
|
2
|
+
export declare function getDriverOriginals(): DriverOriginals;
|
|
3
|
+
export declare function getElementOriginals(): ElementOriginals;
|
|
4
|
+
export declare function patchSelenium(hooks: DriverPatcherHooks): boolean;
|