@azure/microsoft-playwright-testing 1.0.0-alpha.20241126.2 → 1.0.0-alpha.20241128.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/microsoft-playwright-testing",
3
- "version": "1.0.0-alpha.20241126.2",
3
+ "version": "1.0.0-alpha.20241128.1",
4
4
  "description": "Package to integrate your Playwright test suite with Microsoft Playwright Testing service",
5
5
  "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/playwrighttesting/microsoft-playwright-testing/README.md",
6
6
  "sdk-type": "client",
@@ -1,114 +1,162 @@
1
1
  /**
2
- * Microsoft Playwright Testing's Reporting
3
- * feature to publish test results and related artifacts and
4
- * view them in the service portal for faster and easier troubleshooting.
2
+ * Library for integrating Microsoft Playwright Testing with existing playwright projects.
5
3
  *
6
4
  * @packageDocumentation
7
5
  */
8
6
 
9
- import type { FullConfig } from '@playwright/test/reporter';
10
- import type { FullResult } from '@playwright/test/reporter';
11
- import type { Reporter } from '@playwright/test/reporter';
12
- import type { Suite } from '@playwright/test/reporter';
13
- import type { TestCase } from '@playwright/test/reporter';
14
- import type { TestResult } from '@playwright/test/reporter';
7
+ import type { TokenCredential } from '@azure/identity';
15
8
 
16
9
  /**
17
10
  * @public
18
11
  *
19
- * Extends Playwright's Reporter class to enable Microsoft Playwright Testing's Reporting
20
- * feature to publish test results and related artifacts and
21
- * view them in the service portal for faster and easier troubleshooting.
12
+ * Authentication types supported by Microsoft Playwright Testing.
13
+ */
14
+ export declare type AuthenticationType = (typeof ServiceAuth)[keyof typeof ServiceAuth];
15
+
16
+ /**
17
+ * @public
22
18
  *
23
- * @example
19
+ * Browser connect options for the service. This includes endpoint options and connect options.
24
20
  *
21
+ * @example
25
22
  * ```
26
- * import { defineConfig } from "@playwright/test";
23
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
24
+ * import { getConnectOptions, BrowserConnectOptions } from "@azure/microsoft-playwright-testing";
27
25
  *
28
- * export default defineConfig({
29
- * reporter: [["@azure/microsoft-playwright-testing/reporter"]]
26
+ * test("has title", async ({ browserName }) => {
27
+ * const { wsEndpoint, options } : BrowserConnectOptions = await getConnectOptions();
28
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
29
+ * const context = await browser.newContext();
30
+ * const page = await context.newPage();
31
+ *
32
+ * await page.goto("https://playwright.dev/");
33
+ * await expect(page).toHaveTitle(/Playwright/);
34
+ *
35
+ * await page.close();
36
+ * await context.close();
37
+ * await browser.close();
30
38
  * });
31
39
  * ```
32
40
  */
33
- declare class MPTReporter implements Reporter {
34
- private isTokenValid;
35
- private enableGitHubSummary;
36
- private isRegionValid;
37
- private shard;
38
- private isTestRunStartSuccess;
39
- private ciInfo;
40
- private serviceClient;
41
- private storageClient;
42
- private reporterUtils;
43
- private envVariables;
44
- private testRawResults;
45
- private promiseOnBegin;
46
- private _testEndPromises;
47
- private testResultBatch;
48
- private errorMessages;
49
- private informationalMessages;
50
- private processedErrorMessageKeys;
51
- private sasUri;
52
- private uploadMetadata;
53
- private numWorkers;
54
- private testRunUrl;
55
- private enableResultPublish;
56
- constructor(config: Partial<MPTReporterConfig>);
57
- private _addError;
58
- private _addInformationalMessage;
59
- private _addKeyToInformationMessage;
60
- private _isInformationMessagePresent;
61
- private _reporterFailureHandler;
41
+ export declare type BrowserConnectOptions = EndpointOptions & {
42
+ options: ConnectOptions;
43
+ };
44
+
45
+ /**
46
+ * @public
47
+ *
48
+ * Connect options for the service.
49
+ */
50
+ export declare type ConnectOptions = {
51
+ /**
52
+ * @public
53
+ *
54
+ * Additional HTTP headers to be sent with web socket connect request.
55
+ */
56
+ headers?: {
57
+ [key: string]: string;
58
+ };
62
59
  /**
63
60
  * @public
64
61
  *
65
- * Called once before running tests.
62
+ * Exposes network available on the connecting client to the browser being connected to.
66
63
  *
67
- * @param config - Resolved configuration.
68
- * @param suite - The root suite that contains all projects, files and test cases.
64
+ * @defaultValue `<loopback>`
69
65
  */
70
- onBegin(config: FullConfig, suite: Suite): void;
66
+ exposeNetwork?: string;
71
67
  /**
72
68
  * @public
73
69
  *
74
- * Called after a test has been finished in the worker process.
70
+ * Maximum time in milliseconds to wait for the connection to be established.
75
71
  *
76
- * @param test - Test that has been finished.
77
- * @param result - Result of the test run.
72
+ * @defaultValue `30000`
78
73
  */
79
- onTestEnd(test: TestCase, result: TestResult): void;
74
+ timeout?: number;
80
75
  /**
81
76
  * @public
82
77
  *
83
- * Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise]
84
- * and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the
85
- * test runner.
78
+ * Slows down Playwright operations by the specified amount of milliseconds.
86
79
  *
87
- * @param result - Result of the full test run, `status` can be one of:
88
- * - `'passed'` - Everything went as expected.
89
- * - `'failed'` - Any test has failed.
90
- * - `'timedout'` - The
91
- * {@link https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout | testConfig.globalTimeout} has
92
- * been reached.
93
- * - `'interrupted'` - Interrupted by the user.
80
+ * @defaultValue `0`
94
81
  */
95
- onEnd(result: FullResult): Promise<void>;
96
- private _onBegin;
97
- private _onTestEnd;
98
- private _onEnd;
99
- private _uploadTestResultAttachments;
100
- private initializeMPTReporter;
101
- private displayAdditionalInformation;
102
- private processTestResult;
82
+ slowMo?: number;
83
+ };
84
+
85
+ /**
86
+ * @public
87
+ *
88
+ * Endpoint options for the service.
89
+ */
90
+ export declare type EndpointOptions = {
103
91
  /**
104
92
  * @public
105
93
  *
106
- * Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance
107
- * user experience. If your reporter does not print to the terminal, it is strongly recommended to return `false`.
94
+ * A browser websocket endpoint to connect to.
108
95
  */
109
- printsToStdio(): boolean;
110
- }
111
- export default MPTReporter;
96
+ wsEndpoint: string;
97
+ };
98
+
99
+ /**
100
+ * @public
101
+ *
102
+ * Get connect options required to connect to Microsoft Playwright Testing's cloud hosted browsers.
103
+ *
104
+ * @param options - additional options for the service
105
+ * @returns BrowserConnectOptions
106
+ *
107
+ * @example
108
+ * ```
109
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
110
+ * import { getConnectOptions } from "@azure/microsoft-playwright-testing";
111
+ *
112
+ * test('has title', async ({ browserName }) => {
113
+ * const { wsEndpoint, options } = await getConnectOptions();
114
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
115
+ * const context = await browser.newContext();
116
+ * const page = await context.newPage();
117
+ *
118
+ * await page.goto('https://playwright.dev/');
119
+ * await expect(page).toHaveTitle(/Playwright/);
120
+ *
121
+ * await page.close();
122
+ * await context.close();
123
+ * await browser.close();
124
+ * });
125
+ * ```
126
+ */
127
+ export declare const getConnectOptions: (options?: Omit<PlaywrightServiceAdditionalOptions, "serviceAuthType">) => Promise<BrowserConnectOptions>;
128
+
129
+ /**
130
+ * @public
131
+ *
132
+ * Generate playwright configuration integrated with Microsoft Playwright Testing.
133
+ *
134
+ * @param config - base playwright configuration
135
+ * @param options - additional options for the service
136
+ * @returns PlaywrightConfig
137
+ *
138
+ * @example
139
+ * ```
140
+ * import { defineConfig } from "playwright/test";
141
+ * import { getServiceConfig } from "@azure/microsoft-playwright-testing";
142
+ * import playwrightConfig from "./playwright.config";
143
+ *
144
+ * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig));
145
+ * ```
146
+ *
147
+ * @example
148
+ * ```
149
+ * import { defineConfig } from "playwright/test";
150
+ * import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
151
+ * import playwrightConfig from "./playwright.config";
152
+ *
153
+ * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig, {
154
+ * runId: "custom run id",
155
+ * os: ServiceOS.WINDOWS
156
+ * }));
157
+ * ```
158
+ */
159
+ export declare const getServiceConfig: (config: PlaywrightConfigInput, options?: PlaywrightServiceAdditionalOptions) => PlaywrightConfig;
112
160
 
113
161
  /**
114
162
  * @public
@@ -127,7 +175,7 @@ export default MPTReporter;
127
175
  * });
128
176
  * ```
129
177
  */
130
- declare interface MPTReporterConfig {
178
+ export declare interface MPTReporterConfig {
131
179
  /**
132
180
  * @public
133
181
  *
@@ -146,4 +194,166 @@ declare interface MPTReporterConfig {
146
194
  enableResultPublish?: boolean;
147
195
  }
148
196
 
197
+ /**
198
+ * @public
199
+ *
200
+ * OS Types supported by Microsoft Playwright Testing.
201
+ */
202
+ export declare type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];
203
+
204
+ /**
205
+ * @public
206
+ *
207
+ * Playwright configuration integrated with Microsoft Playwright Testing.
208
+ *
209
+ * @remarks
210
+ *
211
+ * GlobalSetup and globalTeardown wraps around any existing global setup
212
+ * and teardown present in the base playwright configuration and runs it.
213
+ */
214
+ export declare type PlaywrightConfig = {
215
+ use?: {
216
+ connectOptions: BrowserConnectOptions;
217
+ };
218
+ globalSetup?: string | string[];
219
+ globalTeardown?: string | string[];
220
+ };
221
+
222
+ /**
223
+ * @public
224
+ *
225
+ * Base playwright configuration inputs required for generating the service config.
226
+ */
227
+ export declare type PlaywrightConfigInput = {
228
+ /**
229
+ * @public
230
+ *
231
+ * Path to the global setup file. This file will be required and run before all the tests. It must export a single
232
+ * function that takes a [`TestConfig`] argument.
233
+ *
234
+ * Learn more about {@link https://playwright.dev/docs/test-global-setup-teardown | global setup and teardown}.
235
+ */
236
+ globalSetup?: string | string[];
237
+ /**
238
+ * @public
239
+ *
240
+ * Path to the global teardown file. This file will be required and run after all the tests. It must export a single
241
+ * function. See also
242
+ * {@link https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown | testConfig.globalTeardown}.
243
+ *
244
+ * Learn more about {@link https://playwright.dev/docs/test-global-setup-teardown | global setup and teardown}.
245
+ */
246
+ globalTeardown?: string | string[];
247
+ };
248
+
249
+ /**
250
+ * @public
251
+ *
252
+ * Additional options for the service.
253
+ */
254
+ export declare type PlaywrightServiceAdditionalOptions = {
255
+ /**
256
+ * @public
257
+ *
258
+ * Authentication types supported by Microsoft Playwright Testing.
259
+ *
260
+ * @defaultValue `ENTRA_ID`
261
+ */
262
+ serviceAuthType?: AuthenticationType;
263
+ /**
264
+ * @public
265
+ *
266
+ * Operating system types supported by Microsoft Playwright Testing.
267
+ *
268
+ * @defaultValue `linux`
269
+ */
270
+ os?: OsType;
271
+ /**
272
+ * @public
273
+ *
274
+ * Run id for the test run.
275
+ *
276
+ * @defaultValue `current datetime as ISO string`
277
+ */
278
+ runId?: string;
279
+ /**
280
+ * @public
281
+ *
282
+ * Maximum time in milliseconds to wait for the connection to be established.
283
+ *
284
+ * @defaultValue `30000`
285
+ */
286
+ timeout?: number;
287
+ /**
288
+ * @public
289
+ *
290
+ * Slows down Playwright operations by the specified amount of milliseconds.
291
+ *
292
+ * @defaultValue `0`
293
+ */
294
+ slowMo?: number;
295
+ /**
296
+ * @public
297
+ *
298
+ * Exposes network available on the connecting client to the browser being connected to.
299
+ *
300
+ * @defaultValue `<loopback>`
301
+ */
302
+ exposeNetwork?: string;
303
+ /**
304
+ * @public
305
+ *
306
+ * Use cloud hosted browsers.
307
+ *
308
+ * @defaultValue `false`
309
+ */
310
+ useCloudHostedBrowsers?: boolean;
311
+ /**
312
+ * @public
313
+ *
314
+ * Custom token credential for Entra ID authentication. Learn more at {@link https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/using-azure-identity.md | Using Azure Identity}.
315
+ *
316
+ * @defaultValue `DefaultAzureCredential`
317
+ */
318
+ credential?: TokenCredential;
319
+ /**
320
+ * @public
321
+ *
322
+ * Run name for the test run.
323
+ *
324
+ * @defaultValue `guid`
325
+ */
326
+ runName?: string;
327
+ };
328
+
329
+ /** @public
330
+ *
331
+ * Authentication types supported on Microsoft Playwright Testing
332
+ */
333
+ export declare const ServiceAuth: {
334
+ readonly ENTRA_ID: "ENTRA_ID";
335
+ readonly ACCESS_TOKEN: "ACCESS_TOKEN";
336
+ };
337
+
338
+ /** @public
339
+ *
340
+ * Environment variables used by Microsoft Playwright Testing
341
+ */
342
+ export declare const ServiceEnvironmentVariable: {
343
+ PLAYWRIGHT_SERVICE_OS: string;
344
+ PLAYWRIGHT_SERVICE_EXPOSE_NETWORK_ENVIRONMENT_VARIABLE: string;
345
+ PLAYWRIGHT_SERVICE_ACCESS_TOKEN: string;
346
+ PLAYWRIGHT_SERVICE_URL: string;
347
+ PLAYWRIGHT_SERVICE_REPORTING_URL: string;
348
+ };
349
+
350
+ /** @public
351
+ *
352
+ * OS types supported on Microsoft Playwright Testing cloud hosted browsers
353
+ */
354
+ export declare const ServiceOS: {
355
+ readonly LINUX: "linux";
356
+ readonly WINDOWS: "windows";
357
+ };
358
+
149
359
  export { }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Microsoft Playwright Testing's Reporting
3
+ * feature to publish test results and related artifacts and
4
+ * view them in the service portal for faster and easier troubleshooting.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ import type { FullConfig } from '@playwright/test/reporter';
10
+ import type { FullResult } from '@playwright/test/reporter';
11
+ import type { Reporter } from '@playwright/test/reporter';
12
+ import type { Suite } from '@playwright/test/reporter';
13
+ import type { TestCase } from '@playwright/test/reporter';
14
+ import type { TestResult } from '@playwright/test/reporter';
15
+
16
+ /**
17
+ * @public
18
+ *
19
+ * Extends Playwright's Reporter class to enable Microsoft Playwright Testing's Reporting
20
+ * feature to publish test results and related artifacts and
21
+ * view them in the service portal for faster and easier troubleshooting.
22
+ *
23
+ * @example
24
+ *
25
+ * ```
26
+ * import { defineConfig } from "@playwright/test";
27
+ *
28
+ * export default defineConfig({
29
+ * reporter: [["@azure/microsoft-playwright-testing/reporter"]]
30
+ * });
31
+ * ```
32
+ */
33
+ declare class MPTReporter implements Reporter {
34
+ private isTokenValid;
35
+ private enableGitHubSummary;
36
+ private isRegionValid;
37
+ private shard;
38
+ private isTestRunStartSuccess;
39
+ private ciInfo;
40
+ private serviceClient;
41
+ private storageClient;
42
+ private reporterUtils;
43
+ private envVariables;
44
+ private testRawResults;
45
+ private promiseOnBegin;
46
+ private _testEndPromises;
47
+ private testResultBatch;
48
+ private errorMessages;
49
+ private informationalMessages;
50
+ private processedErrorMessageKeys;
51
+ private sasUri;
52
+ private uploadMetadata;
53
+ private numWorkers;
54
+ private testRunUrl;
55
+ private enableResultPublish;
56
+ constructor(config: Partial<MPTReporterConfig>);
57
+ private _addError;
58
+ private _addInformationalMessage;
59
+ private _addKeyToInformationMessage;
60
+ private _isInformationMessagePresent;
61
+ private _reporterFailureHandler;
62
+ /**
63
+ * @public
64
+ *
65
+ * Called once before running tests.
66
+ *
67
+ * @param config - Resolved configuration.
68
+ * @param suite - The root suite that contains all projects, files and test cases.
69
+ */
70
+ onBegin(config: FullConfig, suite: Suite): void;
71
+ /**
72
+ * @public
73
+ *
74
+ * Called after a test has been finished in the worker process.
75
+ *
76
+ * @param test - Test that has been finished.
77
+ * @param result - Result of the test run.
78
+ */
79
+ onTestEnd(test: TestCase, result: TestResult): void;
80
+ /**
81
+ * @public
82
+ *
83
+ * Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise]
84
+ * and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the
85
+ * test runner.
86
+ *
87
+ * @param result - Result of the full test run, `status` can be one of:
88
+ * - `'passed'` - Everything went as expected.
89
+ * - `'failed'` - Any test has failed.
90
+ * - `'timedout'` - The
91
+ * {@link https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout | testConfig.globalTimeout} has
92
+ * been reached.
93
+ * - `'interrupted'` - Interrupted by the user.
94
+ */
95
+ onEnd(result: FullResult): Promise<void>;
96
+ private _onBegin;
97
+ private _onTestEnd;
98
+ private _onEnd;
99
+ private _uploadTestResultAttachments;
100
+ private initializeMPTReporter;
101
+ private displayAdditionalInformation;
102
+ private processTestResult;
103
+ /**
104
+ * @public
105
+ *
106
+ * Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance
107
+ * user experience. If your reporter does not print to the terminal, it is strongly recommended to return `false`.
108
+ */
109
+ printsToStdio(): boolean;
110
+ }
111
+ export default MPTReporter;
112
+
113
+ /**
114
+ * @public
115
+ *
116
+ * Optional configuration for MPT Reporter.
117
+ *
118
+ * @example
119
+ *
120
+ * ```
121
+ * import { defineConfig } from "@playwright/test";
122
+ *
123
+ * export default defineConfig({
124
+ * reporter: [["@azure/microsoft-playwright-testing/reporter", {
125
+ * enableGitHubSummary: true
126
+ * }]],
127
+ * });
128
+ * ```
129
+ */
130
+ declare interface MPTReporterConfig {
131
+ /**
132
+ * @public
133
+ *
134
+ * Enable GitHub Actions annotations to diagnose test failures and deep link to MPT Portal.
135
+ *
136
+ * @defaultValue `true`
137
+ */
138
+ enableGitHubSummary?: boolean;
139
+ /**
140
+ * @public
141
+ *
142
+ * Enable result publishing for the test run. This will upload the test result and artifacts to the MPT Portal.
143
+ *
144
+ * @defaultValue `true`
145
+ */
146
+ enableResultPublish?: boolean;
147
+ }
148
+
149
+ export { }