testit-adapter-playwright 2.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/README.md +151 -0
- package/dist/converter.d.ts +20 -0
- package/dist/converter.js +67 -0
- package/dist/labels.d.ts +56 -0
- package/dist/labels.js +119 -0
- package/dist/reporter.d.ts +29 -0
- package/dist/reporter.js +122 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Test IT TMS adapters for Playwright
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
## Getting Started
|
|
5
|
+
|
|
6
|
+
### Installation
|
|
7
|
+
```
|
|
8
|
+
npm install testit-adapter-playwright
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Configuration
|
|
14
|
+
|
|
15
|
+
| Description | Property | Environment variable | CLI argument |
|
|
16
|
+
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|-----------------------------------|-------------------------------|
|
|
17
|
+
| Location of the TMS instance | url | TMS_URL | tmsUrl |
|
|
18
|
+
| API secret key [How to getting API secret key?](https://github.com/testit-tms/.github/tree/main/configuration#privatetoken) | privateToken | TMS_PRIVATE_TOKEN | tmsPrivateToken |
|
|
19
|
+
| ID of project in TMS instance [How to getting project ID?](https://github.com/testit-tms/.github/tree/main/configuration#projectid) | projectId | TMS_PROJECT_ID | tmsProjectId |
|
|
20
|
+
| ID of configuration in TMS instance [How to getting configuration ID?](https://github.com/testit-tms/.github/tree/main/configuration#configurationid) | configurationId | TMS_CONFIGURATION_ID | tmsConfigurationId |
|
|
21
|
+
| ID of the created test run in TMS instance.<br/>It's necessary for **adapterMode** 0 or 1 | testRunId | TMS_TEST_RUN_ID | tmsTestRunId |
|
|
22
|
+
| Parameter for specifying the name of test run in TMS instance (**It's optional**). If it is not provided, it is created automatically | testRunName | TMS_TEST_RUN_NAME | tmsTestRunName |
|
|
23
|
+
| Adapter mode. Default value - 0. The adapter supports following modes:<br/>0 - in this mode, the adapter filters tests by test run ID and configuration ID, and sends the results to the test run<br/>1 - in this mode, the adapter sends all results to the test run without filtering<br/>2 - in this mode, the adapter creates a new test run and sends results to the new test run | adapterMode | TMS_ADAPTER_MODE | tmsAdapterMode |
|
|
24
|
+
| It enables/disables certificate validation (**It's optional**). Default value - true | certValidation | TMS_CERT_VALIDATION | tmsCertValidation |
|
|
25
|
+
| Mode of automatic creation test cases (**It's optional**). Default value - false. The adapter supports following modes:<br/>true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest)<br/>false - in this mode, the adapter will not create a test case | automaticCreationTestCases | TMS_AUTOMATIC_CREATION_TEST_CASES | tmsAutomaticCreationTestCases |
|
|
26
|
+
|
|
27
|
+
Add Adapter to Playwright file configuration:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { PlaywrightTestConfig } from '@playwright/test';
|
|
31
|
+
|
|
32
|
+
const config: PlaywrightTestConfig = {
|
|
33
|
+
reporter: [
|
|
34
|
+
['testit-adapter-playwright']
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default config;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### File
|
|
42
|
+
|
|
43
|
+
Create .env config or file config with default name tms.config.json in the root directory of the project
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"url": "URL",
|
|
48
|
+
"privateToken": "USER_PRIVATE_TOKEN",
|
|
49
|
+
"projectId": "PROJECT_ID",
|
|
50
|
+
"configurationId": "CONFIGURATION_ID",
|
|
51
|
+
"testRunId": "TEST_RUN_ID",
|
|
52
|
+
"testRunName": "TEST_RUN_NAME",
|
|
53
|
+
"adapterMode": "ADAPTER_MODE",
|
|
54
|
+
"automaticCreationTestCases": "AUTOMATIC_CREATION_TEST_CASES"
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Parallel run
|
|
59
|
+
To create and complete TestRun you can use the Test IT CLI:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
$ export TMS_TOKEN=<YOUR_TOKEN>
|
|
63
|
+
$ testit \
|
|
64
|
+
--mode create
|
|
65
|
+
--url https://tms.testit.software \
|
|
66
|
+
--project-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
|
|
67
|
+
--testrun-name "New test run" \
|
|
68
|
+
--output tmp/output.txt
|
|
69
|
+
|
|
70
|
+
$ export TMS_TEST_RUN_ID=$(cat output.txt)
|
|
71
|
+
|
|
72
|
+
$ npx playwright test
|
|
73
|
+
|
|
74
|
+
$ testit \
|
|
75
|
+
--mode finish
|
|
76
|
+
--url https://tms.testit.software \
|
|
77
|
+
--testrun-id $(cat tmp/output.txt)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Methods
|
|
81
|
+
|
|
82
|
+
Methods can be used to specify information about autotest.
|
|
83
|
+
|
|
84
|
+
Description of metadata methods:
|
|
85
|
+
- `testit.workItemIds` - linking an autotest to a test case
|
|
86
|
+
- `testit.displayName` - name of the autotest in the Test IT system (can be replaced with documentation strings)
|
|
87
|
+
- `testit.externalId` - ID of the autotest within the project in the Test IT System
|
|
88
|
+
- `testit.title` - title in the autotest card
|
|
89
|
+
- `testit.description` - description in the autotest card
|
|
90
|
+
- `testit.labels` - tags in the work item
|
|
91
|
+
- `testit.links` - links in the autotest card
|
|
92
|
+
- `testit.namespace` - directory in the TMS system (default - directory's name of test)
|
|
93
|
+
- `testit.classname` - subdirectory in the TMS system (default - file's name of test)
|
|
94
|
+
|
|
95
|
+
Description of methods:
|
|
96
|
+
- `testit.addLinks` - links in the autotest result
|
|
97
|
+
- `testit.addAttachments` - uploading files in the autotest result
|
|
98
|
+
- `testit.addMessage` - information about autotest in the autotest result
|
|
99
|
+
|
|
100
|
+
### Examples
|
|
101
|
+
|
|
102
|
+
#### Simple test
|
|
103
|
+
```js
|
|
104
|
+
import { test } from "@playwright/test";
|
|
105
|
+
import { testit } from "testit-adapter-playwright";
|
|
106
|
+
|
|
107
|
+
test('All annotations', async () => {
|
|
108
|
+
testit.externalId('all_annotations');
|
|
109
|
+
testit.displayName('All annotations');
|
|
110
|
+
testit.title('All annotations title');
|
|
111
|
+
testit.description('Test with all annotations');
|
|
112
|
+
testit.labels(['label1', 'label2']);
|
|
113
|
+
|
|
114
|
+
testit.addMessage('This is a message');
|
|
115
|
+
testit.addLinks([
|
|
116
|
+
{
|
|
117
|
+
url: 'https://www.google.com',
|
|
118
|
+
title: 'Google',
|
|
119
|
+
description: 'This is a link to Google',
|
|
120
|
+
type: 'Related',
|
|
121
|
+
},
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
testit.addAttachment('file01.txt', 'Content', {contentType: "text/markdown",});
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Parameterized test
|
|
129
|
+
```js
|
|
130
|
+
const people = ['Alice', 'Bob'];
|
|
131
|
+
for (const name of people) {
|
|
132
|
+
test(`testing with ${name}`, async () => {
|
|
133
|
+
testit.params(people);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# Contributing
|
|
140
|
+
|
|
141
|
+
You can help to develop the project. Any contributions are **greatly appreciated**.
|
|
142
|
+
|
|
143
|
+
* If you have suggestions for adding or removing projects, feel free to [open an issue](https://github.com/testit-tms/adapters-js/issues/new) to discuss it, or directly create a pull request after you edit the *README.md* file with necessary changes.
|
|
144
|
+
* Please make sure you check your spelling and grammar.
|
|
145
|
+
* Create individual PR for each suggestion.
|
|
146
|
+
* Please also read through the [Code Of Conduct](https://github.com/testit-tms/adapters-js/blob/master/CODE_OF_CONDUCT.md) before posting your first idea as well.
|
|
147
|
+
|
|
148
|
+
# License
|
|
149
|
+
|
|
150
|
+
Distributed under the Apache-2.0 License. See [LICENSE](https://github.com/testit-tms/adapters-js/blob/master/LICENSE.md) for more information.
|
|
151
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TestCase, TestResult } from "@playwright/test/reporter";
|
|
2
|
+
import { TestStatus } from "@playwright/test";
|
|
3
|
+
import { AutotestPost, AutotestResult } from "testit-js-commons";
|
|
4
|
+
import { MetadataMessage } from "./labels";
|
|
5
|
+
declare enum Status {
|
|
6
|
+
PASSED = "Passed",
|
|
7
|
+
FAILED = "Failed",
|
|
8
|
+
SKIPPED = "Skipped"
|
|
9
|
+
}
|
|
10
|
+
export declare class Converter {
|
|
11
|
+
static convertTestCaseToAutotestPost(autotestData: MetadataMessage): AutotestPost;
|
|
12
|
+
static convertAutotestPostToAutotestResult(autotestData: MetadataMessage, test: TestCase, result: TestResult): AutotestResult;
|
|
13
|
+
static convertStatus(status: TestStatus, expectedStatus: TestStatus): Status;
|
|
14
|
+
}
|
|
15
|
+
export type StatusDetails = {
|
|
16
|
+
message?: string;
|
|
17
|
+
trace?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const stripAscii: (str: string) => string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripAscii = exports.Converter = void 0;
|
|
4
|
+
var Status;
|
|
5
|
+
(function (Status) {
|
|
6
|
+
Status["PASSED"] = "Passed";
|
|
7
|
+
Status["FAILED"] = "Failed";
|
|
8
|
+
Status["SKIPPED"] = "Skipped";
|
|
9
|
+
})(Status || (Status = {}));
|
|
10
|
+
class Converter {
|
|
11
|
+
static convertTestCaseToAutotestPost(autotestData) {
|
|
12
|
+
return {
|
|
13
|
+
externalId: autotestData.externalId,
|
|
14
|
+
name: autotestData.displayName,
|
|
15
|
+
title: autotestData.title,
|
|
16
|
+
description: autotestData.description,
|
|
17
|
+
labels: autotestData.labels,
|
|
18
|
+
links: autotestData.links,
|
|
19
|
+
namespace: autotestData.namespace,
|
|
20
|
+
classname: autotestData.classname,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
static convertAutotestPostToAutotestResult(autotestData, test, result) {
|
|
24
|
+
const autotestResult = {
|
|
25
|
+
autoTestExternalId: autotestData.externalId,
|
|
26
|
+
outcome: this.convertStatus(result.status, test.expectedStatus),
|
|
27
|
+
links: autotestData.addLinks,
|
|
28
|
+
duration: result.duration,
|
|
29
|
+
parameters: autotestData.params,
|
|
30
|
+
attachments: autotestData.addAttachments,
|
|
31
|
+
message: autotestData.addMessage,
|
|
32
|
+
};
|
|
33
|
+
if (result.error) {
|
|
34
|
+
const status = getStatusDetails(result.error);
|
|
35
|
+
autotestResult.message = status.message;
|
|
36
|
+
autotestResult.traces = status.trace;
|
|
37
|
+
}
|
|
38
|
+
return autotestResult;
|
|
39
|
+
}
|
|
40
|
+
static convertStatus(status, expectedStatus) {
|
|
41
|
+
if (status === "skipped") {
|
|
42
|
+
return Status.SKIPPED;
|
|
43
|
+
}
|
|
44
|
+
if (status === expectedStatus) {
|
|
45
|
+
return Status.PASSED;
|
|
46
|
+
}
|
|
47
|
+
return Status.FAILED;
|
|
48
|
+
}
|
|
49
|
+
;
|
|
50
|
+
}
|
|
51
|
+
exports.Converter = Converter;
|
|
52
|
+
const getStatusDetails = (error) => {
|
|
53
|
+
const message = error.message && (0, exports.stripAscii)(error.message);
|
|
54
|
+
let trace = error.stack && (0, exports.stripAscii)(error.stack);
|
|
55
|
+
if (trace && message && trace.startsWith(`Error: ${message}`)) {
|
|
56
|
+
trace = trace.substr(message.length + "Error: ".length);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
message: message,
|
|
60
|
+
trace: trace,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const stripAscii = (str) => {
|
|
64
|
+
return str.replace(asciiRegex, "");
|
|
65
|
+
};
|
|
66
|
+
exports.stripAscii = stripAscii;
|
|
67
|
+
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/labels.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Link, Label, Attachment } from "testit-js-commons";
|
|
3
|
+
export interface MetadataMessage {
|
|
4
|
+
workItemIds?: string[];
|
|
5
|
+
displayName?: string;
|
|
6
|
+
externalId?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
labels?: Label[];
|
|
10
|
+
links?: Link[];
|
|
11
|
+
namespace?: string;
|
|
12
|
+
classname?: string;
|
|
13
|
+
addLinks?: Link[];
|
|
14
|
+
addAttachments?: Attachment[];
|
|
15
|
+
addMessage?: string;
|
|
16
|
+
params?: Parameters;
|
|
17
|
+
}
|
|
18
|
+
interface AttachmentOptions {
|
|
19
|
+
contentType: ContentType | string;
|
|
20
|
+
fileExtension?: string;
|
|
21
|
+
}
|
|
22
|
+
declare enum ContentType {
|
|
23
|
+
TEXT = "text/plain",
|
|
24
|
+
XML = "application/xml",
|
|
25
|
+
HTML = "text/html",
|
|
26
|
+
CSV = "text/csv",
|
|
27
|
+
TSV = "text/tab-separated-values",
|
|
28
|
+
CSS = "text/css",
|
|
29
|
+
URI = "text/uri-list",
|
|
30
|
+
SVG = "image/svg+xml",
|
|
31
|
+
PNG = "image/png",
|
|
32
|
+
JSON = "application/json",
|
|
33
|
+
ZIP = "application/zip",
|
|
34
|
+
WEBM = "video/webm",
|
|
35
|
+
JPEG = "image/jpeg",
|
|
36
|
+
MP4 = "video/mp4"
|
|
37
|
+
}
|
|
38
|
+
type Parameters = Record<string, string>;
|
|
39
|
+
export declare class testit {
|
|
40
|
+
static addAttachment(name: string, content: Buffer | string, options: ContentType | string | Pick<AttachmentOptions, "contentType">): Promise<void>;
|
|
41
|
+
private static addMetadataAttachment;
|
|
42
|
+
private static mapParams;
|
|
43
|
+
static workItemIds(value: string[]): Promise<void>;
|
|
44
|
+
static displayName(value: string): Promise<void>;
|
|
45
|
+
static externalId(value: string): Promise<void>;
|
|
46
|
+
static title(value: string): Promise<void>;
|
|
47
|
+
static description(value: string): Promise<void>;
|
|
48
|
+
static labels(value: string[]): Promise<void>;
|
|
49
|
+
static links(value: Link[]): Promise<void>;
|
|
50
|
+
static namespace(value: string): Promise<void>;
|
|
51
|
+
static classname(value: string): Promise<void>;
|
|
52
|
+
static addLinks(value: Link[]): Promise<void>;
|
|
53
|
+
static addMessage(value: string): Promise<void>;
|
|
54
|
+
static params(value: any): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.testit = void 0;
|
|
7
|
+
const test_1 = __importDefault(require("@playwright/test"));
|
|
8
|
+
var ContentType;
|
|
9
|
+
(function (ContentType) {
|
|
10
|
+
ContentType["TEXT"] = "text/plain";
|
|
11
|
+
ContentType["XML"] = "application/xml";
|
|
12
|
+
ContentType["HTML"] = "text/html";
|
|
13
|
+
ContentType["CSV"] = "text/csv";
|
|
14
|
+
ContentType["TSV"] = "text/tab-separated-values";
|
|
15
|
+
ContentType["CSS"] = "text/css";
|
|
16
|
+
ContentType["URI"] = "text/uri-list";
|
|
17
|
+
ContentType["SVG"] = "image/svg+xml";
|
|
18
|
+
ContentType["PNG"] = "image/png";
|
|
19
|
+
ContentType["JSON"] = "application/json";
|
|
20
|
+
ContentType["ZIP"] = "application/zip";
|
|
21
|
+
ContentType["WEBM"] = "video/webm";
|
|
22
|
+
ContentType["JPEG"] = "image/jpeg";
|
|
23
|
+
ContentType["MP4"] = "video/mp4";
|
|
24
|
+
})(ContentType || (ContentType = {}));
|
|
25
|
+
class testit {
|
|
26
|
+
static async addAttachment(name, content, options) {
|
|
27
|
+
const contentType = typeof options === "string" ? options : options.contentType;
|
|
28
|
+
await test_1.default.info().attach(name, {
|
|
29
|
+
body: content,
|
|
30
|
+
contentType,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static async addMetadataAttachment(metadata) {
|
|
34
|
+
await test_1.default.info().attach("tms-metadata.json", {
|
|
35
|
+
contentType: "application/vnd.tms.metadata+json",
|
|
36
|
+
body: Buffer.from(JSON.stringify(metadata), "utf8"),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static async mapParams(params) {
|
|
40
|
+
switch (typeof params) {
|
|
41
|
+
case 'string':
|
|
42
|
+
case 'bigint':
|
|
43
|
+
case 'number':
|
|
44
|
+
case 'boolean':
|
|
45
|
+
return { value: params.toString() };
|
|
46
|
+
case 'object':
|
|
47
|
+
if (params === null) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
return Object.keys(params).reduce((acc, key) => {
|
|
51
|
+
acc[key] = params[key].toString();
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
default:
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static async workItemIds(value) {
|
|
59
|
+
await this.addMetadataAttachment({
|
|
60
|
+
workItemIds: value,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
static async displayName(value) {
|
|
64
|
+
await this.addMetadataAttachment({
|
|
65
|
+
displayName: value,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
static async externalId(value) {
|
|
69
|
+
await this.addMetadataAttachment({
|
|
70
|
+
externalId: value,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
static async title(value) {
|
|
74
|
+
await this.addMetadataAttachment({
|
|
75
|
+
title: value,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
static async description(value) {
|
|
79
|
+
await this.addMetadataAttachment({
|
|
80
|
+
description: value,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
static async labels(value) {
|
|
84
|
+
await this.addMetadataAttachment({
|
|
85
|
+
labels: value.map((label) => ({ name: label })),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static async links(value) {
|
|
89
|
+
await this.addMetadataAttachment({
|
|
90
|
+
links: value,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
static async namespace(value) {
|
|
94
|
+
await this.addMetadataAttachment({
|
|
95
|
+
namespace: value,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static async classname(value) {
|
|
99
|
+
await this.addMetadataAttachment({
|
|
100
|
+
classname: value,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static async addLinks(value) {
|
|
104
|
+
await this.addMetadataAttachment({
|
|
105
|
+
addLinks: value,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
static async addMessage(value) {
|
|
109
|
+
await this.addMetadataAttachment({
|
|
110
|
+
addMessage: value,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
static async params(value) {
|
|
114
|
+
await this.addMetadataAttachment({
|
|
115
|
+
params: await this.mapParams(value),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.testit = testit;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FullConfig } from "@playwright/test";
|
|
2
|
+
import { Reporter, Suite, TestCase, TestResult } from "@playwright/test/reporter";
|
|
3
|
+
import { IStrategy } from "testit-js-commons";
|
|
4
|
+
export type ReporterOptions = {
|
|
5
|
+
detail?: boolean;
|
|
6
|
+
outputFolder?: string;
|
|
7
|
+
suiteTitle?: boolean;
|
|
8
|
+
environmentInfo?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
declare class TmsReporter implements Reporter {
|
|
11
|
+
config: FullConfig;
|
|
12
|
+
suite: Suite;
|
|
13
|
+
resultsDir: string;
|
|
14
|
+
options: ReporterOptions;
|
|
15
|
+
strategy: IStrategy;
|
|
16
|
+
private readonly additions;
|
|
17
|
+
private testCache;
|
|
18
|
+
private globalStartTime;
|
|
19
|
+
constructor(options: ReporterOptions);
|
|
20
|
+
onBegin(config: FullConfig, suite: Suite): void;
|
|
21
|
+
onTestBegin(test: TestCase): void;
|
|
22
|
+
onTestEnd(test: TestCase, result: TestResult): Promise<void>;
|
|
23
|
+
onEnd(): void;
|
|
24
|
+
addSkippedResults(): void;
|
|
25
|
+
printsToStdio(): boolean;
|
|
26
|
+
private getAutotestData;
|
|
27
|
+
}
|
|
28
|
+
export default TmsReporter;
|
|
29
|
+
export * from "./labels";
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const testit_js_commons_1 = require("testit-js-commons");
|
|
18
|
+
const converter_1 = require("./converter");
|
|
19
|
+
class TmsReporter {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.testCache = new Array();
|
|
22
|
+
this.globalStartTime = new Date();
|
|
23
|
+
this.options = { suiteTitle: true, detail: true, ...options };
|
|
24
|
+
const config = new testit_js_commons_1.ConfigComposer().compose();
|
|
25
|
+
const client = new testit_js_commons_1.Client(config);
|
|
26
|
+
this.strategy = testit_js_commons_1.StrategyFactory.create(client, config);
|
|
27
|
+
this.additions = new testit_js_commons_1.Additions(client);
|
|
28
|
+
}
|
|
29
|
+
onBegin(config, suite) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.suite = suite;
|
|
32
|
+
}
|
|
33
|
+
onTestBegin(test) {
|
|
34
|
+
this.testCache.push(test);
|
|
35
|
+
}
|
|
36
|
+
async onTestEnd(test, result) {
|
|
37
|
+
const autotest = converter_1.Converter.convertTestCaseToAutotestPost(await this.getAutotestData(test, result));
|
|
38
|
+
await this.strategy.loadAutotest(autotest, converter_1.Converter.convertStatus(result.status, test.expectedStatus) == "Passed");
|
|
39
|
+
await this.strategy.loadTestRun([converter_1.Converter.convertAutotestPostToAutotestResult(await this.getAutotestData(test, result), test, result)]);
|
|
40
|
+
}
|
|
41
|
+
onEnd() {
|
|
42
|
+
this.addSkippedResults();
|
|
43
|
+
}
|
|
44
|
+
addSkippedResults() {
|
|
45
|
+
const unprocessedCases = this.suite
|
|
46
|
+
.allTests()
|
|
47
|
+
.filter((testCase) => !this.testCache.includes(testCase));
|
|
48
|
+
unprocessedCases.forEach((testCase) => {
|
|
49
|
+
this.onTestEnd(testCase, {
|
|
50
|
+
status: "skipped",
|
|
51
|
+
attachments: [],
|
|
52
|
+
duration: 0,
|
|
53
|
+
errors: [],
|
|
54
|
+
parallelIndex: 0,
|
|
55
|
+
workerIndex: 0,
|
|
56
|
+
retry: 0,
|
|
57
|
+
steps: [],
|
|
58
|
+
stderr: [],
|
|
59
|
+
stdout: [],
|
|
60
|
+
startTime: this.globalStartTime,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
printsToStdio() {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
async getAutotestData(test, result) {
|
|
68
|
+
const autotestData = {
|
|
69
|
+
externalId: testit_js_commons_1.Utils.getHash(test.title),
|
|
70
|
+
displayName: test.title,
|
|
71
|
+
addAttachments: []
|
|
72
|
+
};
|
|
73
|
+
for (const attachment of result.attachments) {
|
|
74
|
+
if (!attachment.body || !attachment.path) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (attachment.contentType === "application/vnd.tms.metadata+json") {
|
|
78
|
+
const metadata = JSON.parse(attachment.body.toString());
|
|
79
|
+
if (metadata.externalId) {
|
|
80
|
+
autotestData.externalId = metadata.externalId;
|
|
81
|
+
}
|
|
82
|
+
if (metadata.displayName) {
|
|
83
|
+
autotestData.displayName = metadata.displayName;
|
|
84
|
+
}
|
|
85
|
+
if (metadata.title) {
|
|
86
|
+
autotestData.title = metadata.title;
|
|
87
|
+
}
|
|
88
|
+
if (metadata.description) {
|
|
89
|
+
autotestData.description = metadata.description;
|
|
90
|
+
}
|
|
91
|
+
if (metadata.labels) {
|
|
92
|
+
autotestData.labels = metadata.labels;
|
|
93
|
+
}
|
|
94
|
+
if (metadata.links) {
|
|
95
|
+
autotestData.links = metadata.links;
|
|
96
|
+
}
|
|
97
|
+
if (metadata.namespace) {
|
|
98
|
+
autotestData.namespace = metadata.namespace;
|
|
99
|
+
}
|
|
100
|
+
if (metadata.classname) {
|
|
101
|
+
autotestData.classname = metadata.classname;
|
|
102
|
+
}
|
|
103
|
+
if (metadata.addLinks) {
|
|
104
|
+
autotestData.addLinks = metadata.addLinks;
|
|
105
|
+
}
|
|
106
|
+
if (metadata.addMessage) {
|
|
107
|
+
autotestData.classname = metadata.addMessage;
|
|
108
|
+
}
|
|
109
|
+
if (metadata.params) {
|
|
110
|
+
autotestData.params = metadata.params;
|
|
111
|
+
}
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
await this.additions.addAttachments(attachment.body.toString(), attachment.name).then((ids) => {
|
|
115
|
+
autotestData.addAttachments?.push(...ids);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return autotestData;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.default = TmsReporter;
|
|
122
|
+
__exportStar(require("./labels"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "testit-adapter-playwright",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Playwright adapter for Test IT",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Integration team",
|
|
8
|
+
"email": "integrations@testit.software"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/testit-tms/adapters-js.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"main": "./dist/reporter.js",
|
|
16
|
+
"types": "./dist/reporter.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clean": "rimraf ./dist ./out",
|
|
19
|
+
"build": "tsc -p tsconfig.json"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@playwright/test": "^1.34.1",
|
|
23
|
+
"@types/eslint": "^8",
|
|
24
|
+
"@types/node": "^20.6.3",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
26
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
27
|
+
"eslint": "^8.49.0",
|
|
28
|
+
"eslint-config-prettier": "^9.0.0",
|
|
29
|
+
"eslint-plugin-import": "^2.28.1",
|
|
30
|
+
"eslint-plugin-jsdoc": "^46.6.0",
|
|
31
|
+
"eslint-plugin-no-null": "^1.0.2",
|
|
32
|
+
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
33
|
+
"properties": "^1.2.1",
|
|
34
|
+
"rimraf": "^5.0.1",
|
|
35
|
+
"typescript": "^5.2.2",
|
|
36
|
+
"@types/debug": "^4.1.7",
|
|
37
|
+
"@types/request": "^2.48.8",
|
|
38
|
+
"jest": "^29.5.0",
|
|
39
|
+
"prettier": "^3.0.1"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"testit-js-commons": "^2.0.1"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
]
|
|
47
|
+
}
|