@empiricalrun/playwright-utils 0.16.0 → 0.16.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f1ab4f3: feat: added custom context page provider
8
+
3
9
  ## 0.16.0
4
10
 
5
11
  ### Minor Changes
@@ -1,8 +1,14 @@
1
- import type { PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
1
+ import type { BrowserContext, BrowserContextOptions, Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
2
2
  import { injectLocatorHighlightScripts } from "./scripts";
3
3
  import { HighlighterOpts } from "./types";
4
- export declare const baseTestFixture: (testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: HighlighterOpts) => TestType<PlaywrightTestArgs & PlaywrightTestOptions & {
5
- [key: string]: any;
6
- }, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
4
+ type TestOptions = {
5
+ page: Page;
6
+ customContextPageProvider: (options?: BrowserContextOptions) => Promise<{
7
+ context: BrowserContext;
8
+ page: Page;
9
+ }>;
10
+ saveVideos: void;
11
+ };
12
+ export declare const baseTestFixture: (testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: HighlighterOpts) => TestType<PlaywrightTestArgs & PlaywrightTestOptions & TestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
7
13
  export { injectLocatorHighlightScripts };
8
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,eAAe,WAClB,SACN,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,YACQ,eAAe;;kDAYzB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,IAAI,EACJ,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,yBAAyB,EAAE,CACzB,OAAO,CAAC,EAAE,qBAAqB,KAC5B,OAAO,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;IACtD,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAIF,eAAO,MAAM,eAAe,WAClB,SACN,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,YACQ,eAAe,uHA2DzB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.injectLocatorHighlightScripts = exports.baseTestFixture = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const rimraf_1 = require("rimraf");
4
10
  const scripts_1 = require("./scripts");
5
11
  Object.defineProperty(exports, "injectLocatorHighlightScripts", { enumerable: true, get: function () { return scripts_1.injectLocatorHighlightScripts; } });
12
+ const videoStore = "videos-store";
6
13
  const baseTestFixture = function (testFn, options = {
7
14
  mousePointerHighlighter: true,
8
15
  locatorHighlighter: true,
@@ -13,6 +20,45 @@ const baseTestFixture = function (testFn, options = {
13
20
  (0, scripts_1.injectLocatorHighlightScripts)(page, options);
14
21
  await use(page);
15
22
  },
23
+ customContextPageProvider: async ({ page }, use, testInfo) => {
24
+ const contexts = [];
25
+ async function createContext(options = {}) {
26
+ const pageContext = await page
27
+ .context()
28
+ .browser()
29
+ .newContext({
30
+ ...options,
31
+ recordVideo: {
32
+ dir: path_1.default.join(testInfo.project.outputDir, videoStore, testInfo.testId),
33
+ },
34
+ });
35
+ contexts.push(pageContext);
36
+ const customPage = await pageContext.newPage();
37
+ (0, scripts_1.injectLocatorHighlightScripts)(customPage);
38
+ return { context: pageContext, page: customPage };
39
+ }
40
+ await use(createContext);
41
+ for (const context of contexts) {
42
+ await context.close();
43
+ }
44
+ },
45
+ saveVideos: [
46
+ // eslint-disable-next-line no-empty-pattern
47
+ async ({}, use, testInfo) => {
48
+ await use();
49
+ const pathToTestVideos = path_1.default.join(testInfo.project.outputDir, "videos-store", testInfo.testId);
50
+ if (fs_1.default.existsSync(pathToTestVideos)) {
51
+ for (let name of fs_1.default.readdirSync(pathToTestVideos)) {
52
+ await testInfo.attach("video", {
53
+ path: path_1.default.join(pathToTestVideos, name),
54
+ contentType: "video/webm",
55
+ });
56
+ }
57
+ (0, rimraf_1.rimrafSync)(pathToTestVideos);
58
+ }
59
+ },
60
+ { auto: true },
61
+ ],
16
62
  });
17
63
  };
18
64
  exports.baseTestFixture = baseTestFixture;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -40,6 +40,7 @@
40
40
  "playwright-core": "1.47.1",
41
41
  "playwright-extra": "^4.3.6",
42
42
  "puppeteer-extra-plugin-recaptcha": "^3.6.8",
43
+ "rimraf": "^6.0.1",
43
44
  "@empiricalrun/llm": "^0.9.27",
44
45
  "@empiricalrun/r2-uploader": "^0.3.7"
45
46
  },