playwright-qase-reporter 2.0.15 → 2.0.17

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 CHANGED
@@ -155,7 +155,7 @@ https://app.qase.io/run/QASE_PROJECT_CODE
155
155
  ```
156
156
 
157
157
  <p align="center">
158
- <img src="./screenshots/demo.gif">
158
+ <img width="85%" src="./screenshots/test-run.gif">
159
159
  </p>
160
160
 
161
161
  ## Configuration
@@ -165,11 +165,8 @@ Reporter options (\* - required):
165
165
  - `mode` - `testops`/`off` Enables reporter, default - `off`
166
166
  - `debug` - Enables debug logging, default - `false`
167
167
  - `environment` - To execute with the sending of the environment information
168
- - *`testops.api.token` - Token for API access, you can find more information
169
- [here](https://developers.qase.io/#authentication)
170
- - *`testops.project` - Code of your project (can be extracted from main
171
- page of your project: `https://app.qase.io/project/DEMOTR` -
172
- `DEMOTR` is project code here)
168
+ - *`testops.api.token` - Token for API access, you can generate it [here](https://developers.qase.io/#authentication).
169
+ - *`testops.project` - [Your project's code](https://help.qase.io/en/articles/9787250-how-do-i-find-my-project-code)
173
170
  - `testops.uploadAttachments` - Permission to send screenshots to Qase TMS
174
171
  - `testops.run.id` - Pass Run ID
175
172
  - `testops.run.title` - Set custom Run name, when new run is created
package/changelog.md CHANGED
@@ -1,3 +1,15 @@
1
+ # playwright-qase-reporter@2.0.17
2
+
3
+ ## What's new
4
+
5
+ Introduced the ability to specify expected results and data for each step, improving step validation and customization.
6
+
7
+ # playwright-qase-reporter@2.0.16
8
+
9
+ ## What's new
10
+
11
+ Improve excluding default steps, like `Worker Cleanup`, `Before Hook`, and `After Hook`.
12
+
1
13
  # playwright-qase-reporter@2.0.15
2
14
 
3
15
  ## What's new
@@ -128,4 +128,17 @@ export declare const qase: {
128
128
  * });
129
129
  */
130
130
  comment(value: string): any;
131
+ /**
132
+ * Set a expected result and data for the test step
133
+ * @param action
134
+ * @param expectedResult
135
+ * @param data
136
+ * @example
137
+ * test('test', async ({ page }) => {
138
+ * await test.step(qase.step('action', 'expected result', 'data'), async () => {
139
+ * await page.goto('https://example.com');
140
+ * });
141
+ * });
142
+ */
143
+ step(action: string, expectedResult: string | undefined, data: string | undefined): string;
131
144
  };
@@ -231,6 +231,21 @@ exports.qase.comment = function (value) {
231
231
  });
232
232
  return this;
233
233
  };
234
+ /**
235
+ * Set a expected result and data for the test step
236
+ * @param action
237
+ * @param expectedResult
238
+ * @param data
239
+ * @example
240
+ * test('test', async ({ page }) => {
241
+ * await test.step(qase.step('action', 'expected result', 'data'), async () => {
242
+ * await page.goto('https://example.com');
243
+ * });
244
+ * });
245
+ */
246
+ exports.qase.step = function (action, expectedResult, data) {
247
+ return `${action} QaseExpRes:${expectedResult ? `: ${expectedResult}` : ''} QaseData:${data ? `: ${data}` : ''}`;
248
+ };
234
249
  const addMetadata = (metadata) => {
235
250
  test_1.default.info().attach('qase-metadata.json', {
236
251
  contentType: exports.ReporterContentType,
@@ -103,4 +103,11 @@ export declare class PlaywrightQaseReporter implements Reporter {
103
103
  * @private
104
104
  */
105
105
  private extractQaseIdsFromAnnotation;
106
+ /**
107
+ * @param {TestStep[]} steps
108
+ * @returns {boolean}
109
+ * @private
110
+ */
111
+ private checkChildrenSteps;
112
+ private extractAndCleanStep;
106
113
  }
package/dist/reporter.js CHANGED
@@ -36,6 +36,21 @@ const defaultSteps = ['Before Hooks', 'After Hooks', 'Worker Cleanup'];
36
36
  * @implements Reporter
37
37
  */
38
38
  class PlaywrightQaseReporter {
39
+ /**
40
+ * @type {Record<TestStatus, TestStatusEnum>}
41
+ */
42
+ static statusMap = {
43
+ passed: qase_javascript_commons_1.TestStatusEnum.passed,
44
+ failed: qase_javascript_commons_1.TestStatusEnum.failed,
45
+ skipped: qase_javascript_commons_1.TestStatusEnum.skipped,
46
+ timedOut: qase_javascript_commons_1.TestStatusEnum.failed,
47
+ interrupted: qase_javascript_commons_1.TestStatusEnum.failed,
48
+ };
49
+ /**
50
+ * @type {Map<string, number[]>}
51
+ * @private
52
+ */
53
+ static qaseIds = new Map();
39
54
  /**
40
55
  * @param {TestCase} test
41
56
  * @returns {string[]}
@@ -44,6 +59,16 @@ class PlaywrightQaseReporter {
44
59
  static transformSuiteTitle(test) {
45
60
  return test.titlePath().filter(Boolean);
46
61
  }
62
+ /**
63
+ * @type {Map<TestStep, TestCase>}
64
+ * @private
65
+ */
66
+ stepCache = new Map();
67
+ /**
68
+ * @type {Map<string, TestStep>}
69
+ * @private
70
+ */
71
+ stepAttachments = new Map();
47
72
  /**
48
73
  * @param {ArrayItemType<TestResult['attachments']>[]} testAttachments
49
74
  * @returns {TestCaseMetadata}
@@ -184,17 +209,19 @@ class PlaywrightQaseReporter {
184
209
  || testStep.title.match(stepAttachRegexp)) {
185
210
  continue;
186
211
  }
187
- if (defaultSteps.includes(testStep.title) && testStep.steps.length === 0) {
212
+ if (defaultSteps.includes(testStep.title) && this.checkChildrenSteps(testStep.steps)) {
188
213
  continue;
189
214
  }
190
215
  const attachments = this.stepAttachments.get(testStep);
216
+ const stepData = this.extractAndCleanStep(testStep.title);
191
217
  const id = (0, uuid_1.v4)();
192
218
  const step = {
193
219
  id: id,
194
220
  step_type: qase_javascript_commons_1.StepType.TEXT,
195
221
  data: {
196
- action: testStep.title,
197
- expected_result: null,
222
+ action: stepData.cleanedString,
223
+ expected_result: stepData.expectedResult,
224
+ data: stepData.data,
198
225
  },
199
226
  parent_id: parentId,
200
227
  execution: {
@@ -210,21 +237,16 @@ class PlaywrightQaseReporter {
210
237
  }
211
238
  return steps;
212
239
  }
240
+ /**
241
+ * @type {ReporterInterface}
242
+ * @private
243
+ */
244
+ reporter;
213
245
  /**
214
246
  * @param {PlaywrightQaseOptionsType} options
215
247
  * @param {ConfigLoaderInterface} configLoader
216
248
  */
217
249
  constructor(options, configLoader = new qase_javascript_commons_1.ConfigLoader()) {
218
- /**
219
- * @type {Map<TestStep, TestCase>}
220
- * @private
221
- */
222
- this.stepCache = new Map();
223
- /**
224
- * @type {Map<string, TestStep>}
225
- * @private
226
- */
227
- this.stepAttachments = new Map();
228
250
  const config = configLoader.load();
229
251
  this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
230
252
  ...(0, qase_javascript_commons_1.composeOptions)(options, config),
@@ -411,20 +433,41 @@ class PlaywrightQaseReporter {
411
433
  }
412
434
  return ids;
413
435
  }
436
+ /**
437
+ * @param {TestStep[]} steps
438
+ * @returns {boolean}
439
+ * @private
440
+ */
441
+ checkChildrenSteps(steps) {
442
+ if (steps.length === 0) {
443
+ return true;
444
+ }
445
+ for (const step of steps) {
446
+ if (step.category === 'test.step' || step.category === 'hook') {
447
+ return false;
448
+ }
449
+ }
450
+ return true;
451
+ }
452
+ extractAndCleanStep(input) {
453
+ let expectedResult = null;
454
+ let data = null;
455
+ let cleanedString = input;
456
+ const hasExpectedResult = /QaseExpRes:/.test(input);
457
+ const hasData = /QaseData:/.test(input);
458
+ if (hasExpectedResult || hasData) {
459
+ const regex = /QaseExpRes:\s*:?\s*(.*?)\s*(?=QaseData:|$)QaseData:\s*:?\s*(.*)?/;
460
+ const match = input.match(regex);
461
+ if (match) {
462
+ expectedResult = match[1]?.trim() || null;
463
+ data = match[2]?.trim() || null;
464
+ cleanedString = input
465
+ .replace(/QaseExpRes:\s*:?\s*.*?(?=QaseData:|$)/, '')
466
+ .replace(/QaseData:\s*:?\s*.*/, '')
467
+ .trim();
468
+ }
469
+ }
470
+ return { expectedResult, data, cleanedString };
471
+ }
414
472
  }
415
473
  exports.PlaywrightQaseReporter = PlaywrightQaseReporter;
416
- /**
417
- * @type {Record<TestStatus, TestStatusEnum>}
418
- */
419
- PlaywrightQaseReporter.statusMap = {
420
- passed: qase_javascript_commons_1.TestStatusEnum.passed,
421
- failed: qase_javascript_commons_1.TestStatusEnum.failed,
422
- skipped: qase_javascript_commons_1.TestStatusEnum.skipped,
423
- timedOut: qase_javascript_commons_1.TestStatusEnum.failed,
424
- interrupted: qase_javascript_commons_1.TestStatusEnum.failed,
425
- };
426
- /**
427
- * @type {Map<string, number[]>}
428
- * @private
429
- */
430
- PlaywrightQaseReporter.qaseIds = new Map();
package/docs/usage.md ADDED
@@ -0,0 +1,265 @@
1
+ # Qase Syntax
2
+
3
+ > [**Click here**](../../examples/playwright/test/) to view Example tests for the following syntax.
4
+
5
+ Here is the complete list of syntax options available for the reporter:
6
+ - [Qase Id](#qase-id)
7
+ - [Qase Title](#qase-title)
8
+ - [Steps](#steps)
9
+ - [Fields](#fields)
10
+ - [Suite](#suite)
11
+ - [Parameters](#parameters)
12
+ - [Comment](#comment)
13
+ - [Attach](#attach)
14
+ - [Ignore](#ignore)
15
+
16
+ If you do not use any Qase syntax, the reporter uses the title from the `describe` and `test` functions as the Suite and Test case title respectively, when publishing results.
17
+
18
+ <br>
19
+
20
+ ### Import Statement
21
+ ---
22
+ Add the following statement at the beginning of your spec file, before any tests.
23
+
24
+ ```javascript
25
+ import { qase } from 'playwright-qase-reporter';
26
+ ```
27
+ <br>
28
+
29
+ ### Example Spec file
30
+ ---
31
+ ```javascript
32
+ import { qase } from 'playwright-qase-reporter';
33
+
34
+ describe('Suite title', () => {
35
+
36
+ test(qase(1, "This is the test name"), () => {
37
+ qase.title("This overrides the test name");
38
+ qase.suite("Suite name");
39
+ qase.fields({ 'severity': 'high', 'priority': 'medium' });
40
+ qase.attach({ paths: './tests/examples/attachments/test-file.txt' });
41
+ qase.comment("A comment for this result");
42
+ qase.ignore(); // doesn't report his result to Qase.
43
+ qase.parameters({ Username: "@test" });
44
+ qase.groupParameters({ Username: username, Password: "123" });
45
+ await test.step('Test step title', async () => // step logic });
46
+ });
47
+
48
+ ```
49
+ <br>
50
+
51
+ ### Qase ID
52
+ ---
53
+
54
+ Qase IDs can be defined using two different methods. It is best to select one method and consistently use it throughout your tests. The first method is recommended.
55
+
56
+ Only one Qase Id can be linked to a test.
57
+
58
+ **Inline with the `test` Function**:
59
+
60
+ ```javascript
61
+ test(qase(1, 'A simple test'), () => {
62
+ ..
63
+ ```
64
+
65
+ **Inside the `test` Body**:
66
+
67
+ ```javascript
68
+ test('A simple test', () => {
69
+ qase.id(1);
70
+ // Test logic here
71
+ });
72
+ ```
73
+
74
+ **In the test's annotations**:
75
+
76
+ ```js
77
+ test('A simple test',
78
+ {
79
+ annotation: { type: 'QaseID', description: '1' },
80
+ },
81
+ async () => {
82
+ // Test logic here
83
+ });
84
+ ```
85
+ <br>
86
+
87
+ ### Qase Title
88
+ ---
89
+
90
+ The `qase.title()` method is used to set the title of a test case, both when creating a new test case from the result, and when updating the title of an existing test case - *if used with `qase.id()`.*
91
+
92
+ ```javascript
93
+ test("This won't appear in Qase", () => {
94
+ qase.title("This text will be the title of the test, in Qase");
95
+ // Test logic here
96
+ });
97
+ ```
98
+
99
+ If you don’t explicitly set a title using this method, the title specified in the `test(..)` function will be used for creating new test cases. However, if this method is defined, it always takes precedence and overrides the title from the `test(..)` function.
100
+
101
+ <br>
102
+
103
+ ### Steps
104
+ ---
105
+
106
+ The reporter uses the title from the `test.step` function as the step title. By providing clear and descriptive step names, you make it easier to understand the test’s flow when reviewing the test case.
107
+
108
+ Additionally, these steps get their own result in the Qase Test run, offering a well-organized summary of the test flow. This helps quickly identify the cause of any failures.
109
+
110
+ ```javascript
111
+ test('A Test case with steps, updated from code', async () => {
112
+ await test.step('Initialize the environment', async () => {
113
+ // Set up test environment
114
+ });
115
+ await test.step('Test Core Functionality of the app', async () => {
116
+ // Exercise core functionality
117
+ });
118
+
119
+ await test.step('Verify Expected Behavior of the app', async () => {
120
+ // Assert expected behavior
121
+ });
122
+ });
123
+ ```
124
+
125
+ You also can use the `qase.step()` method to set the expected result and data of the step, which will be used in the Qase report.
126
+
127
+ ```javascript
128
+ test('A Test case with steps, updated from code', async () => {
129
+ await test.step(qase.step('Initialize the environment'), async () => {
130
+ // Set up test environment
131
+ });
132
+ await test.step(qase.step('Test Core Functionality of the app', 'expected result'), async () => {
133
+ // Exercise core functionality
134
+ });
135
+
136
+ await test.step(qase.step('Verify Expected Behavior of the app', 'expected result', 'data'), async () => {
137
+ // Assert expected behavior
138
+ });
139
+ });
140
+ ```
141
+
142
+ <br>
143
+
144
+ ### Fields
145
+ ---
146
+
147
+ You can define the `description`, `pre-conditions`, `post-conditions`, and fields such as `severity`, `priority`, and `layer` using this method, which enables you to specify and maintain the context of the case directly within your code.
148
+
149
+ ```javascript
150
+ test('Maintain your test meta-data from code', async () => {
151
+ qase.fields({
152
+ severity: 'high',
153
+ priority: 'medium',
154
+ layer: 'api',
155
+ precondition: 'add your precondition'
156
+ postcondition: 'add your postcondition'
157
+ description: `Code it quick, fix it slow,
158
+ Tech debt grows where shortcuts go,
159
+ Refactor later? Ha! We know.`
160
+ })
161
+ // test logic here
162
+ });
163
+ ```
164
+
165
+ <br>
166
+
167
+
168
+ ### Suite
169
+ ---
170
+
171
+ You can use this method to nest the resulting test cases in a particular suite. There's something to note here – suites, unlike test cases, are not identified uniquely by the Reporter. Therefore, when defining an existing suite - the title of the suite is used for matching.
172
+
173
+ ```js
174
+ test("Test with a defined suite", () => {
175
+ qase.suite("Suite defined with qase.suite()");
176
+ /*
177
+ * Or, nest multiple levels of suites.
178
+ * `\t` is used for dividing each suite name.
179
+ */
180
+
181
+ test("Test with a nested suite", () => {
182
+ qase.suite("Application\tAuthentication\tLogin\tEdge_case");
183
+ // test logic here
184
+ });
185
+ ```
186
+ <br>
187
+
188
+ ### Parameters
189
+ ---
190
+ Parameters are a great way to make your tests more dynamic, reusable, and data-driven. By defining parameters in this method, you can ensure only one test case with all the parameters is created in your Qase project, avoiding duplication.
191
+
192
+
193
+ ```javascript
194
+ const testCases = [
195
+ { browser: "Chromium", username: "@alice", password: "123" },
196
+ { browser: "Firefox", username: "@bob", password: "456" },
197
+ { browser: "Webkit", username: "@charlie", password: "789" },
198
+ ];
199
+
200
+ testCases.forEach(({ browser, username, password, }) => {
201
+ test(`Test login with ${browser}`, async () => {
202
+ qase.title("Verify if page loads on all browsers");
203
+
204
+ qase.parameters({ Browser: browser }); // Single parameter
205
+ // test logic
206
+
207
+ testCases.forEach(({ username, password }) => {
208
+ test(`Test login with ${username} using qase.groupParameters`, () => {
209
+ qase.title("Verify if user is able to login with their username.");
210
+
211
+ qase.groupParameters({ // Group parameters
212
+ Username: username,
213
+ Password: password,
214
+ });
215
+ // test logic
216
+ ```
217
+ <br>
218
+
219
+ ### Comment
220
+ ---
221
+ In addition to `test.step()`, this method can be used to provide any additional context to your test, it helps maintiain the code by clarifying the expected result of the test.
222
+
223
+ ```js
224
+ test("A test case with qase.comment()", () => {
225
+ /*
226
+ * Please note, this comment is added to a Result, not to the Test case.
227
+ */
228
+ qase.comment("This comment is added to the result");
229
+ // test logic here
230
+ });
231
+ ```
232
+ <br>
233
+
234
+ ### Attach
235
+ ---
236
+ This method can help attach one, or more files to the test's result. You can also add the file's contents directly from code. For example:
237
+
238
+ ```js
239
+ test('Test result with attachment', async () => {
240
+
241
+ // To attach a single file
242
+ qase.attach({
243
+ paths: "./tests/examples/attachments/test-file.txt",
244
+ });
245
+
246
+ // Add multiple attachments.
247
+ qase.attach({ paths: ['/path/to/file', '/path/to/another/file'] });
248
+
249
+
250
+ // Upload file's contents directly from code.
251
+ qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
252
+ // test logic here
253
+ });
254
+ ```
255
+ <br>
256
+
257
+ ### Ignore
258
+ ---
259
+ If this method is added, the reporter will exclude the test’s result from the report sent to Qase. While the test will still executed by Playwright, its result will not be considered by the reporter.
260
+
261
+ ```js
262
+ test("This test is executed using Playwright; however, it is NOT reported to Qase", () => {
263
+ qase.ignore();
264
+ // test logic here
265
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-qase-reporter",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "Qase TMS Playwright Reporter",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "license": "Apache-2.0",
45
45
  "dependencies": {
46
46
  "chalk": "^4.1.2",
47
- "qase-javascript-commons": "~2.2.0",
47
+ "qase-javascript-commons": "~2.2.14",
48
48
  "uuid": "^9.0.0"
49
49
  },
50
50
  "peerDependencies": {
Binary file