@zhiweiliu/playwright-generator 1.0.3 → 1.0.5

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
@@ -110,6 +110,8 @@ The installed module will have amazing features to facilitate your day-to-day te
110
110
  project-root/
111
111
  ├── tests/ # Natural language test cases
112
112
  │ └── *.test.md
113
+ ├── samples/ # Sample test cases for reference
114
+ │ └── *.test.md
113
115
  ├── generated/ # Generated Playwright test code
114
116
  │ └── generated.test.ts
115
117
  ├── page-objects/ # Page Object Models (optional)
@@ -133,7 +135,7 @@ project-root/
133
135
  # AI Model Configuration
134
136
  AI_MODEL=copilot # Options: copilot, claude
135
137
  COPILOT_API_KEY=your_key_here # Required if using Copilot
136
- CLAUDE_API_KEY=your_key_here # Required if using Claude
138
+ CLAUDE_API_KEY=sk-ant-... # Required if using Claude (starts with sk-ant-)
137
139
 
138
140
  # Playwright Configuration
139
141
  BROWSER=chromium # Options: chromium, firefox, webkit
@@ -168,6 +170,24 @@ And clicks the login button
168
170
  Then the user should be redirected to the dashboard
169
171
  ```
170
172
 
173
+ ### Sample Test Cases
174
+
175
+ For reference and testing purposes, sample test cases are provided in the `samples/` folder:
176
+
177
+ - `samples/saucedemo-samples.test.md`: Comprehensive test cases for the SauceDemo e-commerce website (https://saucedemo.com), including complete purchase flow and product browsing scenarios with detailed step-by-step descriptions.
178
+
179
+ You can use these samples to:
180
+
181
+ 1. Test the generator with real-world e-commerce scenarios
182
+ 2. Understand the level of detail needed in natural language descriptions
183
+ 3. Generate Playwright code for immediate use and validation
184
+
185
+ To generate code from a sample test case:
186
+
187
+ ```bash
188
+ npx playwright-generator generate --tc TC-SAMPLE-0001
189
+ ```
190
+
171
191
  ### Generation
172
192
 
173
193
  Playwright test automation code is generated by running a command, with generated code placed in the `generated/` folder under the project root.
@@ -290,13 +310,14 @@ Workflow file location: `.github/workflows/playwright-tests.yml`
290
310
 
291
311
  **Common Issues**:
292
312
 
293
- | Issue | Solution |
294
- | ----------------------------------- | ------------------------------------------------------------------------------------- |
295
- | `API key not found` | Verify `.env` file exists and `COPILOT_API_KEY` or `CLAUDE_API_KEY` is set |
296
- | `Tests timing out` | Increase `TIMEOUT` in `.env` or use explicit waits in test cases |
297
- | `Generated code doesn't compile` | Review the natural language description for clarity; regenerate with a refined prompt |
298
- | `Tests pass locally but fail in CI` | Check `BASE_URL` environment variable and add debugging with screenshots |
299
- | `Selector not found` | Ensure selectors are unique and reference current UI state |
313
+ | Issue | Solution |
314
+ | ----------------------------------- | --------------------------------------------------------------------------------------------------- |
315
+ | `API key not found` | Verify `.env` file exists and `COPILOT_API_KEY` or `CLAUDE_API_KEY` is set |
316
+ | `Claude API connection failed` | Check `CLAUDE_API_KEY` is valid and account has Claude API access; ensure key starts with `sk-ant-` |
317
+ | `Tests timing out` | Increase `TIMEOUT` in `.env` or use explicit waits in test cases |
318
+ | `Generated code doesn't compile` | Review the natural language description for clarity; regenerate with a refined prompt |
319
+ | `Tests pass locally but fail in CI` | Check `BASE_URL` environment variable and add debugging with screenshots |
320
+ | `Selector not found` | Ensure selectors are unique and reference current UI state |
300
321
 
301
322
  ### GitHub Integration
302
323
 
@@ -1 +1 @@
1
- {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/llm/claude.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnE,qBAAa,cAAe,SAAQ,WAAW;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA2C;gBAE9C,MAAM,EAAE,MAAM;IAQpB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IA8BtC,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC;CA4ClE"}
1
+ {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/llm/claude.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnE,qBAAa,cAAe,SAAQ,WAAW;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA2C;gBAE9C,MAAM,EAAE,MAAM;IAapB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAsCtC,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC;CA8ClE"}
@@ -13,12 +13,15 @@ class ClaudeProvider extends provider_1.LLMProvider {
13
13
  if (!apiKey) {
14
14
  throw new Error("Claude API key is required");
15
15
  }
16
+ if (!apiKey.startsWith("sk-ant-")) {
17
+ throw new Error("Claude API key should start with 'sk-ant-'. Please check your Anthropic API key.");
18
+ }
16
19
  this.apiKey = apiKey;
17
20
  }
18
21
  async validateConnection() {
19
22
  try {
20
23
  const response = await axios_1.default.post(this.baseUrl, {
21
- model: "claude-3-sonnet-20240229",
24
+ model: "claude-3-5-sonnet-20241022",
22
25
  max_tokens: 100,
23
26
  messages: [
24
27
  {
@@ -30,6 +33,7 @@ class ClaudeProvider extends provider_1.LLMProvider {
30
33
  headers: {
31
34
  "x-api-key": this.apiKey,
32
35
  "anthropic-version": "2023-06-01",
36
+ "anthropic-beta": "messages-2023-12-15",
33
37
  "Content-Type": "application/json",
34
38
  },
35
39
  timeout: 5000,
@@ -37,7 +41,12 @@ class ClaudeProvider extends provider_1.LLMProvider {
37
41
  return response.status === 200;
38
42
  }
39
43
  catch (error) {
40
- console.error("Claude connection validation failed:", error);
44
+ if (error.response) {
45
+ console.error(`Claude connection validation failed with status ${error.response.status}:`, error.response.data);
46
+ }
47
+ else {
48
+ console.error("Claude connection validation failed:", error.message);
49
+ }
41
50
  return false;
42
51
  }
43
52
  }
@@ -45,7 +54,7 @@ class ClaudeProvider extends provider_1.LLMProvider {
45
54
  try {
46
55
  const systemPrompt = this.buildPrompt(prompt.testCase);
47
56
  const response = await axios_1.default.post(this.baseUrl, {
48
- model: "claude-3-sonnet-20240229",
57
+ model: "claude-3-5-sonnet-20241022",
49
58
  max_tokens: 2000,
50
59
  messages: [
51
60
  {
@@ -57,6 +66,7 @@ class ClaudeProvider extends provider_1.LLMProvider {
57
66
  headers: {
58
67
  "x-api-key": this.apiKey,
59
68
  "anthropic-version": "2023-06-01",
69
+ "anthropic-beta": "messages-2023-12-15",
60
70
  "Content-Type": "application/json",
61
71
  },
62
72
  timeout: 30000,
@@ -73,7 +83,10 @@ class ClaudeProvider extends provider_1.LLMProvider {
73
83
  };
74
84
  }
75
85
  catch (error) {
76
- throw new Error(`Failed to generate code with Claude: ${error instanceof Error ? error.message : String(error)}`);
86
+ const errorMessage = error.response
87
+ ? `HTTP ${error.response.status}: ${error.response.data?.error?.message || error.response.data}`
88
+ : error.message;
89
+ throw new Error(`Failed to generate code with Claude: ${errorMessage}`);
77
90
  }
78
91
  }
79
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/llm/claude.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yCAAmE;AAEnE,MAAa,cAAe,SAAQ,sBAAW;IAI7C,YAAY,MAAc;QACxB,KAAK,EAAE,CAAC;QAHF,YAAO,GAAG,uCAAuC,CAAC;QAIxD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,IAAI,CAAC,OAAO,EACZ;gBACE,KAAK,EAAE,0BAA0B;gBACjC,UAAU,EAAE,GAAG;gBACf,QAAQ,EAAE;oBACR;wBACE,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,MAAM;qBAChB;iBACF;aACF,EACD;gBACE,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AI,IAAI,EAAE;gBACrB,KAAK,EAAE,QAAQ;gBACf,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ;gBACjC,CAAC,CAAC,QAAQ,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE;gBAChG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,EAAE,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;CACF;AArGD,wCAqGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhiweiliu/playwright-generator",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Generate Playwright test cases from natural language using LLM",
5
5
  "main": "dist/index.js",
6
6
  "bin": {