testit-adapter-playwright 2.2.3 → 2.2.5
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/README.md +37 -0
- package/dist/converter.d.ts +5 -7
- package/dist/converter.js +17 -25
- package/dist/reporter.d.ts +3 -2
- package/dist/reporter.js +34 -17
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +32 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -77,6 +77,26 @@ $ testit testrun complete
|
|
|
77
77
|
--testrun-id $(cat tmp/output.txt)
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
#### Launch using GitLab repository
|
|
81
|
+
To run your Playwright test's from GitLab to TestIT or in reverse order using "testit-adapter-playwright", you can take this .gitlab-ci.yml file example:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
image: node:latest
|
|
85
|
+
|
|
86
|
+
stages:
|
|
87
|
+
- run
|
|
88
|
+
|
|
89
|
+
first-job:
|
|
90
|
+
stage: run
|
|
91
|
+
script:
|
|
92
|
+
- npm install
|
|
93
|
+
- npx playwright test
|
|
94
|
+
artifacts:
|
|
95
|
+
paths:
|
|
96
|
+
- node_modules/
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
80
100
|
### Methods
|
|
81
101
|
|
|
82
102
|
Methods can be used to specify information about autotest.
|
|
@@ -139,6 +159,23 @@ for (const name of people) {
|
|
|
139
159
|
}
|
|
140
160
|
```
|
|
141
161
|
|
|
162
|
+
#### Content types
|
|
163
|
+
```
|
|
164
|
+
TEXT = "text/plain",
|
|
165
|
+
XML = "application/xml",
|
|
166
|
+
HTML = "text/html",
|
|
167
|
+
CSV = "text/csv",
|
|
168
|
+
TSV = "text/tab-separated-values",
|
|
169
|
+
CSS = "text/css",
|
|
170
|
+
URI = "text/uri-list",
|
|
171
|
+
SVG = "image/svg+xml",
|
|
172
|
+
PNG = "image/png",
|
|
173
|
+
JSON = "application/json",
|
|
174
|
+
ZIP = "application/zip",
|
|
175
|
+
WEBM = "video/webm",
|
|
176
|
+
JPEG = "image/jpeg",
|
|
177
|
+
MP4 = "video/mp4",
|
|
178
|
+
```
|
|
142
179
|
|
|
143
180
|
# Contributing
|
|
144
181
|
|
package/dist/converter.d.ts
CHANGED
|
@@ -2,11 +2,15 @@ import { TestCase, TestStep, TestResult } from "@playwright/test/reporter";
|
|
|
2
2
|
import { TestStatus } from "@playwright/test";
|
|
3
3
|
import { AutotestPost, AutotestResult, ShortStep, Step, Attachment } from "testit-js-commons";
|
|
4
4
|
import { MetadataMessage } from "./labels";
|
|
5
|
-
declare enum Status {
|
|
5
|
+
export declare enum Status {
|
|
6
6
|
PASSED = "Passed",
|
|
7
7
|
FAILED = "Failed",
|
|
8
8
|
SKIPPED = "Skipped"
|
|
9
9
|
}
|
|
10
|
+
export type StatusDetails = {
|
|
11
|
+
message?: string;
|
|
12
|
+
trace?: string;
|
|
13
|
+
};
|
|
10
14
|
export declare class Converter {
|
|
11
15
|
static convertTestCaseToAutotestPost(autotestData: MetadataMessage): AutotestPost;
|
|
12
16
|
static convertAutotestPostToAutotestResult(autotestData: MetadataMessage, test: TestCase, result: TestResult): AutotestResult;
|
|
@@ -16,9 +20,3 @@ export declare class Converter {
|
|
|
16
20
|
static convertTestStepToStep(step: TestStep, attachmentsMap: Map<Attachment, TestStep>): Step;
|
|
17
21
|
static convertStatus(status: TestStatus, expectedStatus: TestStatus): Status;
|
|
18
22
|
}
|
|
19
|
-
export type StatusDetails = {
|
|
20
|
-
message?: string;
|
|
21
|
-
trace?: string;
|
|
22
|
-
};
|
|
23
|
-
export declare const stripAscii: (str: string) => string;
|
|
24
|
-
export {};
|
package/dist/converter.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Converter = exports.Status = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
4
5
|
var Status;
|
|
5
6
|
(function (Status) {
|
|
6
7
|
Status["PASSED"] = "Passed";
|
|
7
8
|
Status["FAILED"] = "Failed";
|
|
8
9
|
Status["SKIPPED"] = "Skipped";
|
|
9
|
-
})(Status || (Status = {}));
|
|
10
|
+
})(Status || (exports.Status = Status = {}));
|
|
10
11
|
class Converter {
|
|
11
12
|
static convertTestCaseToAutotestPost(autotestData) {
|
|
12
13
|
return {
|
|
@@ -29,32 +30,39 @@ class Converter {
|
|
|
29
30
|
duration: result.duration,
|
|
30
31
|
parameters: autotestData.params,
|
|
31
32
|
attachments: autotestData.addAttachments,
|
|
32
|
-
message: autotestData.addMessage,
|
|
33
33
|
};
|
|
34
34
|
if (result.error) {
|
|
35
|
-
const status = getStatusDetails(result.error);
|
|
35
|
+
const status = (0, utils_1.getStatusDetails)(result.error);
|
|
36
36
|
autotestResult.message = status.message;
|
|
37
37
|
autotestResult.traces = status.trace;
|
|
38
38
|
}
|
|
39
|
+
if (autotestData.addMessage) {
|
|
40
|
+
autotestResult.message = autotestData.addMessage;
|
|
41
|
+
}
|
|
39
42
|
return autotestResult;
|
|
40
43
|
}
|
|
41
44
|
static convertTestStepsToShortSteps(steps) {
|
|
42
|
-
return steps
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
return steps
|
|
46
|
+
.filter((step) => (0, utils_1.isStep)(step))
|
|
47
|
+
.map(step => this.convertTestStepToShortStep(step));
|
|
45
48
|
}
|
|
46
49
|
static convertTestStepToShortStep(step) {
|
|
47
50
|
return {
|
|
48
51
|
title: step.title,
|
|
52
|
+
steps: step.steps.length !== 0 ? this.convertTestStepsToShortSteps(step.steps) : [],
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
55
|
static convertTestStepsToSteps(steps, attachmentsMap) {
|
|
52
|
-
return steps
|
|
56
|
+
return steps
|
|
57
|
+
.filter((step) => (0, utils_1.isStep)(step))
|
|
58
|
+
.map(step => this.convertTestStepToStep(step, attachmentsMap));
|
|
53
59
|
}
|
|
54
60
|
static convertTestStepToStep(step, attachmentsMap) {
|
|
61
|
+
const steps = step.steps.length !== 0 ? this.convertTestStepsToSteps(step.steps, attachmentsMap) : [];
|
|
55
62
|
return {
|
|
56
63
|
title: step.title,
|
|
57
|
-
outcome: step.error ? Status.FAILED : Status.PASSED,
|
|
64
|
+
outcome: step.error || !(0, utils_1.isAllStepsWithPassedOutcome)(steps) ? Status.FAILED : Status.PASSED,
|
|
65
|
+
steps: steps,
|
|
58
66
|
attachments: [...attachmentsMap.keys()].filter((attachmentId) => attachmentsMap.get(attachmentId) === step),
|
|
59
67
|
};
|
|
60
68
|
}
|
|
@@ -70,19 +78,3 @@ class Converter {
|
|
|
70
78
|
;
|
|
71
79
|
}
|
|
72
80
|
exports.Converter = Converter;
|
|
73
|
-
const getStatusDetails = (error) => {
|
|
74
|
-
const message = error.message && (0, exports.stripAscii)(error.message);
|
|
75
|
-
let trace = error.stack && (0, exports.stripAscii)(error.stack);
|
|
76
|
-
if (trace && message && trace.startsWith(`Error: ${message}`)) {
|
|
77
|
-
trace = trace.substr(message.length + "Error: ".length);
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
message: message,
|
|
81
|
-
trace: trace,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
const stripAscii = (str) => {
|
|
85
|
-
return str.replace(asciiRegex, "");
|
|
86
|
-
};
|
|
87
|
-
exports.stripAscii = stripAscii;
|
|
88
|
-
const asciiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|
package/dist/reporter.d.ts
CHANGED
|
@@ -15,8 +15,9 @@ declare class TmsReporter implements Reporter {
|
|
|
15
15
|
strategy: IStrategy;
|
|
16
16
|
private readonly additions;
|
|
17
17
|
private testCache;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
18
|
+
private stepsMap;
|
|
19
|
+
private attachmentStepsCache;
|
|
20
|
+
private attachmentsMap;
|
|
20
21
|
private globalStartTime;
|
|
21
22
|
private loadTestPromises;
|
|
22
23
|
constructor(options: ReporterOptions);
|
package/dist/reporter.js
CHANGED
|
@@ -16,12 +16,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
const testit_js_commons_1 = require("testit-js-commons");
|
|
18
18
|
const converter_1 = require("./converter");
|
|
19
|
-
const
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
20
|
class TmsReporter {
|
|
21
21
|
constructor(options) {
|
|
22
22
|
this.testCache = new Array();
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
23
|
+
this.stepsMap = new Map();
|
|
24
|
+
this.attachmentStepsCache = new Array();
|
|
25
|
+
this.attachmentsMap = new Map();
|
|
25
26
|
this.globalStartTime = new Date();
|
|
26
27
|
this.loadTestPromises = new Array();
|
|
27
28
|
this.options = { suiteTitle: true, detail: true, ...options };
|
|
@@ -44,13 +45,20 @@ class TmsReporter {
|
|
|
44
45
|
if (!this.testCache.includes(test)) {
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
48
|
+
if (step.title.match(utils_1.stepAttachRegexp)) {
|
|
49
|
+
this.attachmentStepsCache.push(step);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
47
52
|
if (step.category !== "test.step") {
|
|
48
53
|
return;
|
|
49
54
|
}
|
|
50
|
-
if (
|
|
55
|
+
if (step.parent) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (this.stepsMap.get(step)) {
|
|
51
59
|
return;
|
|
52
60
|
}
|
|
53
|
-
this.
|
|
61
|
+
this.stepsMap.set(step, test);
|
|
54
62
|
}
|
|
55
63
|
async onEnd() {
|
|
56
64
|
await Promise.all(this.loadTestPromises);
|
|
@@ -87,6 +95,13 @@ class TmsReporter {
|
|
|
87
95
|
};
|
|
88
96
|
for (const attachment of result.attachments) {
|
|
89
97
|
if (!attachment.body) {
|
|
98
|
+
if (attachment.path && attachment.name !== "screenshot") {
|
|
99
|
+
const content = testit_js_commons_1.Utils.readBuffer(attachment.path);
|
|
100
|
+
await this.additions.addAttachments(content, attachment.name)
|
|
101
|
+
.then((ids) => {
|
|
102
|
+
autotestData.addAttachments?.push(...ids);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
90
105
|
continue;
|
|
91
106
|
}
|
|
92
107
|
if (attachment.contentType === "application/vnd.tms.metadata+json") {
|
|
@@ -129,14 +144,11 @@ class TmsReporter {
|
|
|
129
144
|
}
|
|
130
145
|
continue;
|
|
131
146
|
}
|
|
132
|
-
if (attachment.name.match(stepAttachRegexp)) {
|
|
133
|
-
const step =
|
|
134
|
-
|
|
135
|
-
this.stepCache.delete(step);
|
|
136
|
-
}
|
|
137
|
-
await this.additions.addAttachments(attachment.body.toString(), attachment.name.replace(stepAttachRegexp, "")).then((ids) => {
|
|
147
|
+
if (attachment.name.match(utils_1.stepAttachRegexp)) {
|
|
148
|
+
const step = this.attachmentStepsCache.find((step) => step.title === attachment.name);
|
|
149
|
+
await this.additions.addAttachments(attachment.body, attachment.name.replace(utils_1.stepAttachRegexp, "")).then((ids) => {
|
|
138
150
|
if (step?.parent) {
|
|
139
|
-
this.
|
|
151
|
+
this.attachmentsMap.set(ids[0], step.parent);
|
|
140
152
|
return;
|
|
141
153
|
}
|
|
142
154
|
autotestData.addAttachments?.push(...ids);
|
|
@@ -146,12 +158,17 @@ class TmsReporter {
|
|
|
146
158
|
return autotestData;
|
|
147
159
|
}
|
|
148
160
|
async loadTest(test, result) {
|
|
149
|
-
const
|
|
150
|
-
const
|
|
161
|
+
const autotestData = await this.getAutotestData(test, result);
|
|
162
|
+
const autotest = converter_1.Converter.convertTestCaseToAutotestPost(autotestData);
|
|
163
|
+
const steps = [...this.stepsMap.keys()].filter((step) => this.stepsMap.get(step) === test);
|
|
164
|
+
const stepResults = converter_1.Converter.convertTestStepsToSteps(steps, this.attachmentsMap);
|
|
165
|
+
if (!(0, utils_1.isAllStepsWithPassedOutcome)(stepResults)) {
|
|
166
|
+
result.status = "failed";
|
|
167
|
+
}
|
|
151
168
|
autotest.steps = converter_1.Converter.convertTestStepsToShortSteps(steps);
|
|
152
|
-
await this.strategy.loadAutotest(autotest, converter_1.Converter.convertStatus(result.status, test.expectedStatus) ==
|
|
153
|
-
const autotestResult = converter_1.Converter.convertAutotestPostToAutotestResult(
|
|
154
|
-
autotestResult.stepResults =
|
|
169
|
+
await this.strategy.loadAutotest(autotest, converter_1.Converter.convertStatus(result.status, test.expectedStatus) == converter_1.Status.PASSED);
|
|
170
|
+
const autotestResult = converter_1.Converter.convertAutotestPostToAutotestResult(autotestData, test, result);
|
|
171
|
+
autotestResult.stepResults = stepResults;
|
|
155
172
|
await this.strategy.loadTestRun([autotestResult]);
|
|
156
173
|
}
|
|
157
174
|
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TestError, TestStep } from "@playwright/test/reporter";
|
|
2
|
+
import { Step } from "testit-js-commons";
|
|
3
|
+
export type StatusDetails = {
|
|
4
|
+
message?: string;
|
|
5
|
+
trace?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function getStatusDetails(error: TestError): StatusDetails;
|
|
8
|
+
export declare function isAllStepsWithPassedOutcome(steps: Step[]): boolean;
|
|
9
|
+
export declare function isStep(step: TestStep): boolean;
|
|
10
|
+
export declare function stripAscii(str: string): string;
|
|
11
|
+
export declare const stepAttachRegexp: RegExp;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stepAttachRegexp = void 0;
|
|
4
|
+
exports.getStatusDetails = getStatusDetails;
|
|
5
|
+
exports.isAllStepsWithPassedOutcome = isAllStepsWithPassedOutcome;
|
|
6
|
+
exports.isStep = isStep;
|
|
7
|
+
exports.stripAscii = stripAscii;
|
|
8
|
+
const converter_1 = require("./converter");
|
|
9
|
+
function getStatusDetails(error) {
|
|
10
|
+
const message = error.message && stripAscii(error.message);
|
|
11
|
+
let trace = error.stack && stripAscii(error.stack);
|
|
12
|
+
if (trace && message && trace.startsWith(`Error: ${message}`)) {
|
|
13
|
+
trace = trace.substr(message.length + "Error: ".length);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
message: message,
|
|
17
|
+
trace: trace,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
;
|
|
21
|
+
function isAllStepsWithPassedOutcome(steps) {
|
|
22
|
+
return !steps.find((step) => step.outcome === converter_1.Status.FAILED);
|
|
23
|
+
}
|
|
24
|
+
function isStep(step) {
|
|
25
|
+
return step.category === "test.step" && !step.title.match(exports.stepAttachRegexp);
|
|
26
|
+
}
|
|
27
|
+
function stripAscii(str) {
|
|
28
|
+
return str.replace(asciiRegex, "");
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
exports.stepAttachRegexp = /^stepattach_(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})_/i;
|
|
32
|
+
const asciiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testit-adapter-playwright",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "Playwright adapter for Test IT",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"prettier": "^3.0.1"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"testit-js-commons": "~2.2.
|
|
43
|
+
"testit-js-commons": "~2.2.5"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist"
|