@trailguide/playwright 0.1.1 → 0.1.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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@playwright/test");async function u(c,o,l={}){if(o.mode==="tour")return;const{baseUrl:n="",timeout:a=8e3}=l;for(const e of o.steps){if(e.url){const r=e.url.startsWith("http")?e.url:`${n}${e.url}`;c.url().endsWith(e.url)||await c.goto(r)}const t=c.locator(e.target);if(e.action)switch(await t.waitFor({state:"visible",timeout:a}),e.action){case"click":await t.click();break;case"fill":await t.fill(e.value??"");break;case"select":await t.selectOption(e.value??"");break;case"check":await t.check();break;case"hover":await t.hover();break}if(e.assert){const{type:r,expected:s=""}=e.assert;switch(r){case"visible":await i.expect(t).toBeVisible({timeout:a});break;case"hidden":await i.expect(t).toBeHidden({timeout:a});break;case"text":await i.expect(t).toHaveText(s,{timeout:a});break;case"value":await i.expect(t).toHaveValue(s,{timeout:a});break;case"url":await i.expect(c).toHaveURL(s,{timeout:a});break}}else!e.action&&!e.optional&&await t.waitFor({state:"attached",timeout:a})}}exports.runTrail=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@playwright/test");async function p(r,b,u={}){if(b.mode==="tour")return;const{baseUrl:k="",timeout:i=8e3}=u;let t=r;for(const e of b.steps){if(e.tabContext==="main")t=r;else if(e.tabContext==="new"){const s=r.context().pages();s.length>1&&(t=s[s.length-1])}if(e.url){const s=e.url.startsWith("http")?e.url:`${k}${e.url}`;t.url().endsWith(e.url)||await t.goto(s)}const a=t.locator(e.target);if(e.action)if(["evaluate","scroll","goto"].includes(e.action)||await a.waitFor({state:"visible",timeout:i}),e.opensNewTab&&e.action==="click"){const[c]=await Promise.all([r.context().waitForEvent("page"),a.click()]);await c.waitForLoadState(),t=c}else switch(e.action){case"click":await a.click();break;case"rightClick":await a.click({button:"right"});break;case"dblclick":await a.dblclick();break;case"fill":await a.fill(e.value??"");break;case"type":await a.pressSequentially(e.value??"");break;case"select":await a.selectOption(e.value??"");break;case"check":await a.check();break;case"uncheck":await a.uncheck();break;case"hover":await a.hover();break;case"focus":await a.focus();break;case"press":await a.press(e.value??"");break;case"dragTo":await a.dragTo(t.locator(e.value??""));break;case"setInputFiles":await a.setInputFiles(e.value??"");break;case"goto":await t.goto(e.value??"");break;case"scroll":{const[c,l]=(e.value??"0,0").split(",").map(Number);e.target==="body"||e.target==="html"?await t.evaluate(([n,w])=>globalThis.scrollBy(n,w),[c,l]):await a.evaluate((n,[w,d])=>n.scrollBy(w,d),[c,l]);break}case"evaluate":await t.evaluate(e.value??"");break}if(e.wait)switch(e.wait.type){case"networkIdle":await t.waitForLoadState("networkidle");break;case"load":await t.waitForLoadState("load");break;case"domcontentloaded":await t.waitForLoadState("domcontentloaded");break;case"selector":await t.waitForSelector(e.wait.value,{timeout:i});break;case"timeout":await t.waitForTimeout(parseInt(e.wait.value??"1000"));break}if(e.assert){const{type:s,expected:c="",attribute:l}=e.assert;switch(s){case"visible":await o.expect(a).toBeVisible({timeout:i});break;case"hidden":await o.expect(a).toBeHidden({timeout:i});break;case"enabled":await o.expect(a).toBeEnabled({timeout:i});break;case"disabled":await o.expect(a).toBeDisabled({timeout:i});break;case"checked":await o.expect(a).toBeChecked({timeout:i});break;case"empty":await o.expect(a).toBeEmpty({timeout:i});break;case"text":await o.expect(a).toHaveText(c,{timeout:i});break;case"containsText":await o.expect(a).toContainText(c,{timeout:i});break;case"value":await o.expect(a).toHaveValue(c,{timeout:i});break;case"url":await o.expect(t).toHaveURL(c,{timeout:i});break;case"title":await o.expect(t).toHaveTitle(c,{timeout:i});break;case"attribute":await o.expect(a).toHaveAttribute(l,c,{timeout:i});break;case"hasClass":await o.expect(a).toHaveClass(c,{timeout:i});break;case"count":await o.expect(a).toHaveCount(parseInt(c),{timeout:i});break;case"screenshot":await o.expect(t).toHaveScreenshot(e.id+".png");break;case"custom":{if(!await t.evaluate(c))throw new Error(`Custom assertion failed: ${c}`);break}}}else!e.action&&!e.optional&&await a.waitFor({state:"attached",timeout:i})}}exports.runTrail=p;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwCrG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgHrG"}
package/dist/index.js CHANGED
@@ -1,53 +1,154 @@
1
- import { expect as i } from "@playwright/test";
2
- async function u(c, o, l = {}) {
3
- if (o.mode === "tour") return;
4
- const { baseUrl: n = "", timeout: e = 8e3 } = l;
5
- for (const a of o.steps) {
1
+ import { expect as s } from "@playwright/test";
2
+ async function p(r, b, u = {}) {
3
+ if (b.mode === "tour") return;
4
+ const { baseUrl: k = "", timeout: i = 8e3 } = u;
5
+ let t = r;
6
+ for (const a of b.steps) {
7
+ if (a.tabContext === "main")
8
+ t = r;
9
+ else if (a.tabContext === "new") {
10
+ const c = r.context().pages();
11
+ c.length > 1 && (t = c[c.length - 1]);
12
+ }
6
13
  if (a.url) {
7
- const r = a.url.startsWith("http") ? a.url : `${n}${a.url}`;
8
- c.url().endsWith(a.url) || await c.goto(r);
14
+ const c = a.url.startsWith("http") ? a.url : `${k}${a.url}`;
15
+ t.url().endsWith(a.url) || await t.goto(c);
9
16
  }
10
- const t = c.locator(a.target);
17
+ const e = t.locator(a.target);
11
18
  if (a.action)
12
- switch (await t.waitFor({ state: "visible", timeout: e }), a.action) {
13
- case "click":
14
- await t.click();
19
+ if (["evaluate", "scroll", "goto"].includes(a.action) || await e.waitFor({ state: "visible", timeout: i }), a.opensNewTab && a.action === "click") {
20
+ const [o] = await Promise.all([
21
+ r.context().waitForEvent("page"),
22
+ e.click()
23
+ ]);
24
+ await o.waitForLoadState(), t = o;
25
+ } else
26
+ switch (a.action) {
27
+ case "click":
28
+ await e.click();
29
+ break;
30
+ case "rightClick":
31
+ await e.click({ button: "right" });
32
+ break;
33
+ case "dblclick":
34
+ await e.dblclick();
35
+ break;
36
+ case "fill":
37
+ await e.fill(a.value ?? "");
38
+ break;
39
+ case "type":
40
+ await e.pressSequentially(a.value ?? "");
41
+ break;
42
+ case "select":
43
+ await e.selectOption(a.value ?? "");
44
+ break;
45
+ case "check":
46
+ await e.check();
47
+ break;
48
+ case "uncheck":
49
+ await e.uncheck();
50
+ break;
51
+ case "hover":
52
+ await e.hover();
53
+ break;
54
+ case "focus":
55
+ await e.focus();
56
+ break;
57
+ case "press":
58
+ await e.press(a.value ?? "");
59
+ break;
60
+ case "dragTo":
61
+ await e.dragTo(t.locator(a.value ?? ""));
62
+ break;
63
+ case "setInputFiles":
64
+ await e.setInputFiles(a.value ?? "");
65
+ break;
66
+ case "goto":
67
+ await t.goto(a.value ?? "");
68
+ break;
69
+ case "scroll": {
70
+ const [o, l] = (a.value ?? "0,0").split(",").map(Number);
71
+ a.target === "body" || a.target === "html" ? await t.evaluate(([n, w]) => globalThis.scrollBy(n, w), [o, l]) : await e.evaluate((n, [w, d]) => n.scrollBy(w, d), [o, l]);
72
+ break;
73
+ }
74
+ case "evaluate":
75
+ await t.evaluate(a.value ?? "");
76
+ break;
77
+ }
78
+ if (a.wait)
79
+ switch (a.wait.type) {
80
+ case "networkIdle":
81
+ await t.waitForLoadState("networkidle");
15
82
  break;
16
- case "fill":
17
- await t.fill(a.value ?? "");
83
+ case "load":
84
+ await t.waitForLoadState("load");
18
85
  break;
19
- case "select":
20
- await t.selectOption(a.value ?? "");
86
+ case "domcontentloaded":
87
+ await t.waitForLoadState("domcontentloaded");
21
88
  break;
22
- case "check":
23
- await t.check();
89
+ case "selector":
90
+ await t.waitForSelector(a.wait.value, { timeout: i });
24
91
  break;
25
- case "hover":
26
- await t.hover();
92
+ case "timeout":
93
+ await t.waitForTimeout(parseInt(a.wait.value ?? "1000"));
27
94
  break;
28
95
  }
29
96
  if (a.assert) {
30
- const { type: r, expected: s = "" } = a.assert;
31
- switch (r) {
97
+ const { type: c, expected: o = "", attribute: l } = a.assert;
98
+ switch (c) {
32
99
  case "visible":
33
- await i(t).toBeVisible({ timeout: e });
100
+ await s(e).toBeVisible({ timeout: i });
34
101
  break;
35
102
  case "hidden":
36
- await i(t).toBeHidden({ timeout: e });
103
+ await s(e).toBeHidden({ timeout: i });
104
+ break;
105
+ case "enabled":
106
+ await s(e).toBeEnabled({ timeout: i });
107
+ break;
108
+ case "disabled":
109
+ await s(e).toBeDisabled({ timeout: i });
110
+ break;
111
+ case "checked":
112
+ await s(e).toBeChecked({ timeout: i });
113
+ break;
114
+ case "empty":
115
+ await s(e).toBeEmpty({ timeout: i });
37
116
  break;
38
117
  case "text":
39
- await i(t).toHaveText(s, { timeout: e });
118
+ await s(e).toHaveText(o, { timeout: i });
119
+ break;
120
+ case "containsText":
121
+ await s(e).toContainText(o, { timeout: i });
40
122
  break;
41
123
  case "value":
42
- await i(t).toHaveValue(s, { timeout: e });
124
+ await s(e).toHaveValue(o, { timeout: i });
43
125
  break;
44
126
  case "url":
45
- await i(c).toHaveURL(s, { timeout: e });
127
+ await s(t).toHaveURL(o, { timeout: i });
128
+ break;
129
+ case "title":
130
+ await s(t).toHaveTitle(o, { timeout: i });
131
+ break;
132
+ case "attribute":
133
+ await s(e).toHaveAttribute(l, o, { timeout: i });
134
+ break;
135
+ case "hasClass":
136
+ await s(e).toHaveClass(o, { timeout: i });
137
+ break;
138
+ case "count":
139
+ await s(e).toHaveCount(parseInt(o), { timeout: i });
140
+ break;
141
+ case "screenshot":
142
+ await s(t).toHaveScreenshot(a.id + ".png");
143
+ break;
144
+ case "custom": {
145
+ if (!await t.evaluate(o)) throw new Error(`Custom assertion failed: ${o}`);
46
146
  break;
147
+ }
47
148
  }
48
- } else !a.action && !a.optional && await t.waitFor({ state: "attached", timeout: e });
149
+ } else !a.action && !a.optional && await e.waitFor({ state: "attached", timeout: i });
49
150
  }
50
151
  }
51
152
  export {
52
- u as runTrail
153
+ p as runTrail
53
154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trailguide/playwright",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Run Trailguide trails as Playwright tests",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",