playwright 1.45.1 → 1.45.2
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/lib/common/globals.js +0 -9
- package/lib/index.js +61 -101
- package/lib/worker/testInfo.js +1 -0
- package/lib/worker/workerMain.js +9 -13
- package/package.json +2 -2
package/lib/common/globals.js
CHANGED
|
@@ -9,8 +9,6 @@ exports.isWorkerProcess = isWorkerProcess;
|
|
|
9
9
|
exports.setCurrentTestInfo = setCurrentTestInfo;
|
|
10
10
|
exports.setCurrentlyLoadingFileSuite = setCurrentlyLoadingFileSuite;
|
|
11
11
|
exports.setIsWorkerProcess = setIsWorkerProcess;
|
|
12
|
-
exports.setTestLifecycleInstrumentation = setTestLifecycleInstrumentation;
|
|
13
|
-
exports.testLifecycleInstrumentation = testLifecycleInstrumentation;
|
|
14
12
|
/**
|
|
15
13
|
* Copyright Microsoft Corporation. All rights reserved.
|
|
16
14
|
*
|
|
@@ -47,11 +45,4 @@ function setIsWorkerProcess() {
|
|
|
47
45
|
}
|
|
48
46
|
function isWorkerProcess() {
|
|
49
47
|
return _isWorkerProcess;
|
|
50
|
-
}
|
|
51
|
-
let _testLifecycleInstrumentation;
|
|
52
|
-
function setTestLifecycleInstrumentation(instrumentation) {
|
|
53
|
-
_testLifecycleInstrumentation = instrumentation;
|
|
54
|
-
}
|
|
55
|
-
function testLifecycleInstrumentation() {
|
|
56
|
-
return _testLifecycleInstrumentation;
|
|
57
48
|
}
|
package/lib/index.js
CHANGED
|
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "mergeTests", {
|
|
|
31
31
|
exports.test = void 0;
|
|
32
32
|
var fs = _interopRequireWildcard(require("fs"));
|
|
33
33
|
var path = _interopRequireWildcard(require("path"));
|
|
34
|
+
var playwrightLibrary = _interopRequireWildcard(require("playwright-core"));
|
|
34
35
|
var _utils = require("playwright-core/lib/utils");
|
|
35
36
|
var _testType = require("./common/testType");
|
|
36
37
|
var _globals = require("./common/globals");
|
|
@@ -78,16 +79,8 @@ const playwrightFixtures = {
|
|
|
78
79
|
scope: 'worker',
|
|
79
80
|
option: true
|
|
80
81
|
}],
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}],
|
|
84
|
-
playwright: [async ({
|
|
85
|
-
_playwrightImpl,
|
|
86
|
-
screenshot
|
|
87
|
-
}, use) => {
|
|
88
|
-
await connector.setPlaywright(_playwrightImpl, screenshot);
|
|
89
|
-
await use(_playwrightImpl);
|
|
90
|
-
await connector.setPlaywright(undefined, screenshot);
|
|
82
|
+
playwright: [async ({}, use) => {
|
|
83
|
+
await use(require('playwright-core'));
|
|
91
84
|
}, {
|
|
92
85
|
scope: 'worker',
|
|
93
86
|
_hideStep: true
|
|
@@ -397,7 +390,7 @@ const playwrightFixtures = {
|
|
|
397
390
|
navigationTimeout,
|
|
398
391
|
testIdAttribute
|
|
399
392
|
}, use, testInfo) => {
|
|
400
|
-
if (testIdAttribute)
|
|
393
|
+
if (testIdAttribute) playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
|
|
401
394
|
testInfo.snapshotSuffix = process.platform;
|
|
402
395
|
if ((0, _utils.debugMode)()) testInfo.setTimeout(0);
|
|
403
396
|
for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit]) {
|
|
@@ -421,6 +414,62 @@ const playwrightFixtures = {
|
|
|
421
414
|
auto: 'all-hooks-included',
|
|
422
415
|
_title: 'context configuration'
|
|
423
416
|
}],
|
|
417
|
+
_setupArtifacts: [async ({
|
|
418
|
+
playwright,
|
|
419
|
+
screenshot
|
|
420
|
+
}, use, testInfo) => {
|
|
421
|
+
const artifactsRecorder = new ArtifactsRecorder(playwright, tracing().artifactsDir(), screenshot);
|
|
422
|
+
await artifactsRecorder.willStartTest(testInfo);
|
|
423
|
+
const csiListener = {
|
|
424
|
+
onApiCallBegin: (apiName, params, frames, userData, out) => {
|
|
425
|
+
const testInfo = (0, _globals.currentTestInfo)();
|
|
426
|
+
if (!testInfo || apiName.includes('setTestIdAttribute')) return {
|
|
427
|
+
userObject: null
|
|
428
|
+
};
|
|
429
|
+
const step = testInfo._addStep({
|
|
430
|
+
location: frames[0],
|
|
431
|
+
category: 'pw:api',
|
|
432
|
+
title: renderApiCall(apiName, params),
|
|
433
|
+
apiName,
|
|
434
|
+
params
|
|
435
|
+
});
|
|
436
|
+
userData.userObject = step;
|
|
437
|
+
out.stepId = step.stepId;
|
|
438
|
+
},
|
|
439
|
+
onApiCallEnd: (userData, error) => {
|
|
440
|
+
const step = userData.userObject;
|
|
441
|
+
step === null || step === void 0 || step.complete({
|
|
442
|
+
error
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
onWillPause: () => {
|
|
446
|
+
var _currentTestInfo;
|
|
447
|
+
(_currentTestInfo = (0, _globals.currentTestInfo)()) === null || _currentTestInfo === void 0 || _currentTestInfo.setTimeout(0);
|
|
448
|
+
},
|
|
449
|
+
runAfterCreateBrowserContext: async context => {
|
|
450
|
+
await (artifactsRecorder === null || artifactsRecorder === void 0 ? void 0 : artifactsRecorder.didCreateBrowserContext(context));
|
|
451
|
+
const testInfo = (0, _globals.currentTestInfo)();
|
|
452
|
+
if (testInfo) attachConnectedHeaderIfNeeded(testInfo, context.browser());
|
|
453
|
+
},
|
|
454
|
+
runAfterCreateRequestContext: async context => {
|
|
455
|
+
await (artifactsRecorder === null || artifactsRecorder === void 0 ? void 0 : artifactsRecorder.didCreateRequestContext(context));
|
|
456
|
+
},
|
|
457
|
+
runBeforeCloseBrowserContext: async context => {
|
|
458
|
+
await (artifactsRecorder === null || artifactsRecorder === void 0 ? void 0 : artifactsRecorder.willCloseBrowserContext(context));
|
|
459
|
+
},
|
|
460
|
+
runBeforeCloseRequestContext: async context => {
|
|
461
|
+
await (artifactsRecorder === null || artifactsRecorder === void 0 ? void 0 : artifactsRecorder.willCloseRequestContext(context));
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
const clientInstrumentation = playwright._instrumentation;
|
|
465
|
+
clientInstrumentation.addListener(csiListener);
|
|
466
|
+
await use();
|
|
467
|
+
clientInstrumentation.removeListener(csiListener);
|
|
468
|
+
await artifactsRecorder.didFinishTest();
|
|
469
|
+
}, {
|
|
470
|
+
auto: 'all-hooks-included',
|
|
471
|
+
_title: 'trace recording'
|
|
472
|
+
}],
|
|
424
473
|
_contextFactory: [async ({
|
|
425
474
|
browser,
|
|
426
475
|
video,
|
|
@@ -621,6 +670,7 @@ class ArtifactsRecorder {
|
|
|
621
670
|
}
|
|
622
671
|
async willStartTest(testInfo) {
|
|
623
672
|
this._testInfo = testInfo;
|
|
673
|
+
testInfo._onDidFinishTestFunction = () => this.didFinishTestFunction();
|
|
624
674
|
|
|
625
675
|
// Since beforeAll(s), test and afterAll(s) reuse the same TestInfo, make sure we do not
|
|
626
676
|
// overwrite previous screenshots.
|
|
@@ -787,94 +837,4 @@ function renderApiCall(apiName, params) {
|
|
|
787
837
|
function tracing() {
|
|
788
838
|
return test.info()._tracing;
|
|
789
839
|
}
|
|
790
|
-
class InstrumentationConnector {
|
|
791
|
-
constructor() {
|
|
792
|
-
this._playwright = void 0;
|
|
793
|
-
this._screenshot = 'off';
|
|
794
|
-
this._artifactsRecorder = void 0;
|
|
795
|
-
this._testIsRunning = false;
|
|
796
|
-
(0, _globals.setTestLifecycleInstrumentation)(this);
|
|
797
|
-
}
|
|
798
|
-
async setPlaywright(playwright, screenshot) {
|
|
799
|
-
if (this._playwright) {
|
|
800
|
-
if (this._testIsRunning) {
|
|
801
|
-
// When "playwright" is destroyed during a test, collect artifacts immediately.
|
|
802
|
-
await this.onTestEnd();
|
|
803
|
-
}
|
|
804
|
-
const clientInstrumentation = this._playwright._instrumentation;
|
|
805
|
-
clientInstrumentation.removeListener(this);
|
|
806
|
-
}
|
|
807
|
-
this._playwright = playwright;
|
|
808
|
-
this._screenshot = screenshot;
|
|
809
|
-
if (this._playwright) {
|
|
810
|
-
const clientInstrumentation = this._playwright._instrumentation;
|
|
811
|
-
clientInstrumentation.addListener(this);
|
|
812
|
-
if (this._testIsRunning) {
|
|
813
|
-
// When "playwright" is created during a test, wire it up immediately.
|
|
814
|
-
await this.onTestBegin();
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
async onTestBegin() {
|
|
819
|
-
this._testIsRunning = true;
|
|
820
|
-
if (this._playwright) {
|
|
821
|
-
this._artifactsRecorder = new ArtifactsRecorder(this._playwright, tracing().artifactsDir(), this._screenshot);
|
|
822
|
-
await this._artifactsRecorder.willStartTest((0, _globals.currentTestInfo)());
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
async onTestFunctionEnd() {
|
|
826
|
-
var _this$_artifactsRecor;
|
|
827
|
-
await ((_this$_artifactsRecor = this._artifactsRecorder) === null || _this$_artifactsRecor === void 0 ? void 0 : _this$_artifactsRecor.didFinishTestFunction());
|
|
828
|
-
}
|
|
829
|
-
async onTestEnd() {
|
|
830
|
-
var _this$_artifactsRecor2;
|
|
831
|
-
await ((_this$_artifactsRecor2 = this._artifactsRecorder) === null || _this$_artifactsRecor2 === void 0 ? void 0 : _this$_artifactsRecor2.didFinishTest());
|
|
832
|
-
this._artifactsRecorder = undefined;
|
|
833
|
-
this._testIsRunning = false;
|
|
834
|
-
}
|
|
835
|
-
onApiCallBegin(apiName, params, frames, userData, out) {
|
|
836
|
-
const testInfo = (0, _globals.currentTestInfo)();
|
|
837
|
-
if (!testInfo || apiName.includes('setTestIdAttribute')) return {
|
|
838
|
-
userObject: null
|
|
839
|
-
};
|
|
840
|
-
const step = testInfo._addStep({
|
|
841
|
-
location: frames[0],
|
|
842
|
-
category: 'pw:api',
|
|
843
|
-
title: renderApiCall(apiName, params),
|
|
844
|
-
apiName,
|
|
845
|
-
params
|
|
846
|
-
});
|
|
847
|
-
userData.userObject = step;
|
|
848
|
-
out.stepId = step.stepId;
|
|
849
|
-
}
|
|
850
|
-
onApiCallEnd(userData, error) {
|
|
851
|
-
const step = userData.userObject;
|
|
852
|
-
step === null || step === void 0 || step.complete({
|
|
853
|
-
error
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
onWillPause() {
|
|
857
|
-
var _currentTestInfo;
|
|
858
|
-
(_currentTestInfo = (0, _globals.currentTestInfo)()) === null || _currentTestInfo === void 0 || _currentTestInfo.setTimeout(0);
|
|
859
|
-
}
|
|
860
|
-
async runAfterCreateBrowserContext(context) {
|
|
861
|
-
var _this$_artifactsRecor3;
|
|
862
|
-
await ((_this$_artifactsRecor3 = this._artifactsRecorder) === null || _this$_artifactsRecor3 === void 0 ? void 0 : _this$_artifactsRecor3.didCreateBrowserContext(context));
|
|
863
|
-
const testInfo = (0, _globals.currentTestInfo)();
|
|
864
|
-
if (testInfo) attachConnectedHeaderIfNeeded(testInfo, context.browser());
|
|
865
|
-
}
|
|
866
|
-
async runAfterCreateRequestContext(context) {
|
|
867
|
-
var _this$_artifactsRecor4;
|
|
868
|
-
await ((_this$_artifactsRecor4 = this._artifactsRecorder) === null || _this$_artifactsRecor4 === void 0 ? void 0 : _this$_artifactsRecor4.didCreateRequestContext(context));
|
|
869
|
-
}
|
|
870
|
-
async runBeforeCloseBrowserContext(context) {
|
|
871
|
-
var _this$_artifactsRecor5;
|
|
872
|
-
await ((_this$_artifactsRecor5 = this._artifactsRecorder) === null || _this$_artifactsRecor5 === void 0 ? void 0 : _this$_artifactsRecor5.willCloseBrowserContext(context));
|
|
873
|
-
}
|
|
874
|
-
async runBeforeCloseRequestContext(context) {
|
|
875
|
-
var _this$_artifactsRecor6;
|
|
876
|
-
await ((_this$_artifactsRecor6 = this._artifactsRecorder) === null || _this$_artifactsRecor6 === void 0 ? void 0 : _this$_artifactsRecor6.willCloseRequestContext(context));
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
const connector = new InstrumentationConnector();
|
|
880
840
|
const test = exports.test = _baseTest.extend(playwrightFixtures);
|
package/lib/worker/testInfo.js
CHANGED
package/lib/worker/workerMain.js
CHANGED
|
@@ -277,10 +277,6 @@ class WorkerMain extends _process.ProcessRunner {
|
|
|
277
277
|
this._lastRunningTests.push(test);
|
|
278
278
|
if (this._lastRunningTests.length > 10) this._lastRunningTests.shift();
|
|
279
279
|
let shouldRunAfterEachHooks = false;
|
|
280
|
-
const tracingSlot = {
|
|
281
|
-
timeout: this._project.project.timeout,
|
|
282
|
-
elapsed: 0
|
|
283
|
-
};
|
|
284
280
|
testInfo._allowSkips = true;
|
|
285
281
|
await testInfo._runAsStage({
|
|
286
282
|
title: 'setup and test'
|
|
@@ -288,11 +284,9 @@ class WorkerMain extends _process.ProcessRunner {
|
|
|
288
284
|
await testInfo._runAsStage({
|
|
289
285
|
title: 'start tracing',
|
|
290
286
|
runnable: {
|
|
291
|
-
type: 'test'
|
|
292
|
-
slot: tracingSlot
|
|
287
|
+
type: 'test'
|
|
293
288
|
}
|
|
294
289
|
}, async () => {
|
|
295
|
-
var _testLifecycleInstrum, _testLifecycleInstrum2;
|
|
296
290
|
// Ideally, "trace" would be an config-level option belonging to the
|
|
297
291
|
// test runner instead of a fixture belonging to Playwright.
|
|
298
292
|
// However, for backwards compatibility, we have to read it from a fixture today.
|
|
@@ -301,7 +295,6 @@ class WorkerMain extends _process.ProcessRunner {
|
|
|
301
295
|
if (!traceFixtureRegistration) return;
|
|
302
296
|
if (typeof traceFixtureRegistration.fn === 'function') throw new Error(`"trace" option cannot be a function`);
|
|
303
297
|
await testInfo._tracing.startIfNeeded(traceFixtureRegistration.fn);
|
|
304
|
-
await ((_testLifecycleInstrum = (0, _globals.testLifecycleInstrumentation)()) === null || _testLifecycleInstrum === void 0 || (_testLifecycleInstrum2 = _testLifecycleInstrum.onTestBegin) === null || _testLifecycleInstrum2 === void 0 ? void 0 : _testLifecycleInstrum2.call(_testLifecycleInstrum));
|
|
305
298
|
});
|
|
306
299
|
if (this._isStopped || isSkipped) {
|
|
307
300
|
// Two reasons to get here:
|
|
@@ -373,14 +366,15 @@ class WorkerMain extends _process.ProcessRunner {
|
|
|
373
366
|
title: 'on-test-function-finish',
|
|
374
367
|
runnable: {
|
|
375
368
|
type: 'test',
|
|
376
|
-
slot:
|
|
369
|
+
slot: afterHooksSlot
|
|
377
370
|
}
|
|
378
371
|
}, async () => {
|
|
379
|
-
var
|
|
380
|
-
|
|
372
|
+
var _testInfo$_onDidFinis;
|
|
373
|
+
return (_testInfo$_onDidFinis = testInfo._onDidFinishTestFunction) === null || _testInfo$_onDidFinis === void 0 ? void 0 : _testInfo$_onDidFinis.call(testInfo);
|
|
381
374
|
});
|
|
382
375
|
} catch (error) {
|
|
383
376
|
var _firstAfterHooksError;
|
|
377
|
+
if (error instanceof _timeoutManager.TimeoutManagerError) didTimeoutInAfterHooks = true;
|
|
384
378
|
firstAfterHooksError = (_firstAfterHooksError = firstAfterHooksError) !== null && _firstAfterHooksError !== void 0 ? _firstAfterHooksError : error;
|
|
385
379
|
}
|
|
386
380
|
try {
|
|
@@ -472,6 +466,10 @@ class WorkerMain extends _process.ProcessRunner {
|
|
|
472
466
|
if (firstWorkerCleanupError) throw firstWorkerCleanupError;
|
|
473
467
|
}).catch(() => {}); // Ignore the top-level error, it is already inside TestInfo.errors.
|
|
474
468
|
}
|
|
469
|
+
const tracingSlot = {
|
|
470
|
+
timeout: this._project.project.timeout,
|
|
471
|
+
elapsed: 0
|
|
472
|
+
};
|
|
475
473
|
await testInfo._runAsStage({
|
|
476
474
|
title: 'stop tracing',
|
|
477
475
|
runnable: {
|
|
@@ -479,8 +477,6 @@ class WorkerMain extends _process.ProcessRunner {
|
|
|
479
477
|
slot: tracingSlot
|
|
480
478
|
}
|
|
481
479
|
}, async () => {
|
|
482
|
-
var _testLifecycleInstrum5, _testLifecycleInstrum6;
|
|
483
|
-
await ((_testLifecycleInstrum5 = (0, _globals.testLifecycleInstrumentation)()) === null || _testLifecycleInstrum5 === void 0 || (_testLifecycleInstrum6 = _testLifecycleInstrum5.onTestEnd) === null || _testLifecycleInstrum6 === void 0 ? void 0 : _testLifecycleInstrum6.call(_testLifecycleInstrum5));
|
|
484
480
|
await testInfo._tracing.stopIfNeeded();
|
|
485
481
|
}).catch(() => {}); // Ignore the top-level error, it is already inside TestInfo.errors.
|
|
486
482
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright",
|
|
3
|
-
"version": "1.45.
|
|
3
|
+
"version": "1.45.2",
|
|
4
4
|
"description": "A high-level API to automate web browsers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"license": "Apache-2.0",
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"playwright-core": "1.45.
|
|
61
|
+
"playwright-core": "1.45.2"
|
|
62
62
|
},
|
|
63
63
|
"optionalDependencies": {
|
|
64
64
|
"fsevents": "2.3.2"
|