@empiricalrun/test-gen 0.8.0 → 0.8.2

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,17 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b8681d5: fix: update the action for locator
8
+
9
+ ## 0.8.1
10
+
11
+ ### Patch Changes
12
+
13
+ - a7e8c1c: fix: locator issues while generating tests
14
+
3
15
  ## 0.8.0
4
16
 
5
17
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"assertTextVisibility.d.ts","sourceRoot":"","sources":["../../src/actions/assertTextVisibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,yBAoCjD,CAAC"}
1
+ {"version":3,"file":"assertTextVisibility.d.ts","sourceRoot":"","sources":["../../src/actions/assertTextVisibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,yBA0CjD,CAAC"}
@@ -6,31 +6,36 @@ const assertTextVisibilityActionGenerator = (page) => {
6
6
  return {
7
7
  execute: async (args) => {
8
8
  await page
9
- .getByText(args.text, { exact: true })
9
+ .locator(args.css_selector)
10
+ .filter({ hasText: args.text })
10
11
  .first()
11
12
  .isVisible({ timeout: 3000 });
12
13
  },
13
14
  // TODO: args transformer to be kept at a single place
14
- template: (args) => `await expect(page.getByText("${args.text}", { exact: true }).first()).toBeVisible();`,
15
+ template: (args) => `await expect(page.locator("${args.css_selector}").filter({ hasText: "${args.text}"}).first()).toBeVisible();`,
15
16
  name: exports.PLAYWRIGHT_ASSERT_TEXT_VISIBILITY_ACTION_NAME,
16
17
  schema: {
17
18
  type: "function",
18
19
  function: {
19
20
  name: exports.PLAYWRIGHT_ASSERT_TEXT_VISIBILITY_ACTION_NAME,
20
- description: "assert whether the given text is visible",
21
+ description: "assert whether the given element on the page is visible",
21
22
  parameters: {
22
23
  type: "object",
23
24
  properties: {
24
25
  text: {
25
26
  type: "string",
26
- description: "the text which needs to be visible on the screen",
27
+ description: "text to be asserted",
28
+ },
29
+ css_selector: {
30
+ type: "string",
31
+ description: "CSS selector to identify the element uniquely and click it. When creating CSS selectors, ensure they are unique and specific enough to select only one element, even if there are multiple elements of the same type (like multiple h1 elements)",
27
32
  },
28
33
  reason: {
29
34
  type: "string",
30
35
  description: "reason for calling this function",
31
36
  },
32
37
  },
33
- required: ["text", "reason"],
38
+ required: ["css_selector", "text", "reason"],
34
39
  },
35
40
  },
36
41
  },
@@ -1 +1 @@
1
- {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/actions/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,4BAA4B,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,EAAE,yBAmClC,CAAC"}
1
+ {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/actions/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,4BAA4B,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,EAAE,yBAoClC,CAAC"}
@@ -9,6 +9,7 @@ const clickActionGenerator = (page) => {
9
9
  .locator(args.css_selector.split(" ")[0].replaceAll("\\", ""))
10
10
  .first()
11
11
  .click({ timeout: 3000 });
12
+ await page.waitForTimeout(3000);
12
13
  },
13
14
  // TODO: args transformer to be kept at a single place
14
15
  template: (args) => `await page.locator("${args.css_selector.split(" ")[0].replaceAll("\\", "")}").first().click();`,
package/dist/bin/index.js CHANGED
@@ -133,33 +133,23 @@ async function generateTest(scenarios, file, isUpdate) {
133
133
  return generatedScenarios;
134
134
  }
135
135
  async function generateTestsUsingBrowsingAgent() {
136
- let resolve = null;
137
- // let reject: any = null;
138
136
  const testFilePath = process.argv[2];
139
137
  if (!testFilePath) {
140
138
  console.error("test file path is required");
141
139
  process.exit(1);
142
140
  }
143
- const promise = new Promise((res) => {
144
- resolve = res;
145
- // reject = rej;
146
- });
147
141
  const port = await (0, detect_port_1.default)(3030);
148
142
  const fileService = new server_1.FileService({ port });
149
143
  await fileService.startFileService();
150
144
  try {
151
145
  fileService.setFilePath(testFilePath);
152
146
  //TODO: change this to per test
153
- (0, exec_1.cmd)([`npx`, `playwright`, `test`, testFilePath], {
147
+ await (0, exec_1.cmd)([`npx`, `playwright`, `test`, testFilePath, "--headed"], {
154
148
  env: {
155
149
  APP_PORT: port.toString(),
156
150
  PW_TEST_HTML_REPORT_OPEN: "never",
157
151
  },
158
- }).then(() => {
159
- //@ts-ignore
160
- resolve?.();
161
152
  });
162
- await promise;
163
153
  process.exit(0);
164
154
  }
165
155
  catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/utils/html.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,QAClB,MAAM,YACF;IACP,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,WAmBF,CAAC"}
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/utils/html.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,QAClB,MAAM,YACF;IACP,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,WAuBF,CAAC"}
@@ -14,6 +14,10 @@ const sanitizeHtml = (str, options = {}) => {
14
14
  "input",
15
15
  "select",
16
16
  "textarea",
17
+ "div",
18
+ "h1",
19
+ "h2",
20
+ "h3",
17
21
  ]),
18
22
  allowedAttributes: false,
19
23
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"