endorphin-ai 0.1.0

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.
Files changed (35) hide show
  1. package/LICENSE.md +209 -0
  2. package/README.md +474 -0
  3. package/bin/endorphin.js +256 -0
  4. package/examples/endorphin.config.js +22 -0
  5. package/examples/tests/QE-001-basic-login-test.js +18 -0
  6. package/examples/tests/sample-test.js +9 -0
  7. package/examples/tools/.gitkeep +0 -0
  8. package/framework/config/agent-config.js +53 -0
  9. package/framework/config/browser-config.js +53 -0
  10. package/framework/config/paths.js +40 -0
  11. package/framework/core/agent-setup.js +75 -0
  12. package/framework/core/browser-framework.js +766 -0
  13. package/framework/core/config-loader.js +309 -0
  14. package/framework/core/test-discovery.js +402 -0
  15. package/framework/core/test-manager.js +343 -0
  16. package/framework/core/test-recorder.js +302 -0
  17. package/framework/core/test-runner.js +133 -0
  18. package/framework/core/test-session.js +98 -0
  19. package/framework/index.js +44 -0
  20. package/framework/interactive/enhanced-interactive-recorder.js +223 -0
  21. package/framework/interactive/index.js +18 -0
  22. package/framework/interactive/interactive-test-clean.js +33 -0
  23. package/framework/interactive/interactive-test.js +33 -0
  24. package/framework/test-framework.js +29 -0
  25. package/framework/testing/index.js +15 -0
  26. package/framework/testing/test-interactive-recorder.js +83 -0
  27. package/framework/testing/test-modular-framework.js +47 -0
  28. package/framework/testing/verify-test-format.js +58 -0
  29. package/framework/tools/content.js +67 -0
  30. package/framework/tools/index.js +52 -0
  31. package/framework/tools/interaction.js +180 -0
  32. package/framework/tools/navigation.js +43 -0
  33. package/framework/tools/utilities.js +99 -0
  34. package/framework/tools/verification.js +84 -0
  35. package/package.json +84 -0
package/README.md ADDED
@@ -0,0 +1,474 @@
1
+ <div align="center">
2
+ <img src="./doc/images/endorphin.jpg" alt="Endorphin Logo" width="200" />
3
+
4
+ <h1 style="font-size: 4rem; font-weight: bold; margin: 30px 0 10px 0; color: #8A2BE2;">ENDORPHIN</h1>
5
+
6
+ <h2 style="font-size: 1.5rem; margin: 10px 0 30px 0;">E2E Testing Reinvented with AI</h2>
7
+ </div>
8
+
9
+ Write tests in plain English. Let AI generate, validate, and fix them automatically.
10
+
11
+ A powerful, modular browser automation framework using AI-powered testing with LangChain, OpenAI GPT-4o, and Playwright. Provides intelligent browser automation with automatic element detection, visual validation, and comprehensive test management.
12
+
13
+ ## ๐Ÿš€ Quick Start
14
+
15
+ ### Installation
16
+ ```bash
17
+ npm install -g endorphin-ai
18
+ ```
19
+
20
+ ### Setup
21
+ 1. Create your project directory:
22
+ ```bash
23
+ mkdir my-test-project && cd my-test-project
24
+ ```
25
+
26
+ 2. Set up your `.env` file with your OpenAI API key:
27
+ ```env
28
+ OPENAI_API_KEY=your_api_key_here
29
+ ```
30
+
31
+ 3. Create tests directory:
32
+ ```bash
33
+ mkdir tests
34
+ ```
35
+
36
+ 4. Create your first test file `tests/login-test.js`:
37
+ ```javascript
38
+ export const QE001 = {
39
+ id: "QE-001",
40
+ name: "Basic Login Test",
41
+ description: "Test the login functionality with valid credentials",
42
+ priority: "High",
43
+ tags: ["authentication", "login", "smoke"],
44
+ site: "https://qafromla.herokuapp.com/",
45
+ testData: {
46
+ originalEmail: "papapin888@gmail.com",
47
+ originalPassword: "lalalend"
48
+ },
49
+ task: `Navigate to https://qafromla.herokuapp.com/.
50
+ Click on "Log In" button. Wait 2 seconds for page load.
51
+ Fill email field with "papapin888@gmail.com".
52
+ Fill password field with "lalalend".
53
+ Click "Sign In" button. Wait 3 seconds for page load.
54
+ Verify login was successful by checking page content.`
55
+ };
56
+ ```
57
+
58
+ ### Usage Commands
59
+
60
+ #### ๐Ÿงช Run Specific Test
61
+ ```bash
62
+ endorphin run test QE-001
63
+ ```
64
+
65
+ #### ๐Ÿท๏ธ Run Tests by Category
66
+ ```bash
67
+ # Authentication tests
68
+ endorphin run test --tag authentication
69
+
70
+ # High priority tests
71
+ endorphin run test --priority High
72
+
73
+ # Smoke tests
74
+ endorphin run test --tag smoke
75
+ ```
76
+
77
+ #### ๐ŸŽฏ Run All Tests
78
+ ```bash
79
+ endorphin run test all
80
+ ```
81
+
82
+ #### ๐ŸŽฌ Test Recorder Mode
83
+ ```bash
84
+ # Interactive test creation
85
+ endorphin run test-recorder
86
+ ```
87
+
88
+ ## ๐Ÿ—๏ธ Framework Architecture
89
+
90
+ ### Modular Structure
91
+ ```
92
+ framework/
93
+ โ”œโ”€โ”€ test-framework.js # Main entry point
94
+ โ”œโ”€โ”€ index.js # Modular exports
95
+ โ”œโ”€โ”€ config/ # Configuration files
96
+ โ”‚ โ”œโ”€โ”€ agent-config.js # AI agent settings
97
+ โ”‚ โ”œโ”€โ”€ browser-config.js # Browser configuration
98
+ โ”‚ โ””โ”€โ”€ paths.js # Directory paths
99
+ โ”œโ”€โ”€ core/ # Core components
100
+ โ”‚ โ”œโ”€โ”€ browser-framework.js # Main framework class
101
+ โ”‚ โ”œโ”€โ”€ config-loader.js # Configuration management
102
+ โ”‚ โ”œโ”€โ”€ test-discovery.js # Test discovery & execution
103
+ โ”‚ โ”œโ”€โ”€ test-manager.js # Test management
104
+ โ”‚ โ”œโ”€โ”€ test-runner.js # Test execution
105
+ โ”‚ โ””โ”€โ”€ test-session.js # Session tracking
106
+ โ”œโ”€โ”€ tools/ # Browser automation tools
107
+ โ”‚ โ”œโ”€โ”€ navigation.js # Page navigation
108
+ โ”‚ โ”œโ”€โ”€ interaction.js # Clicks, form filling
109
+ โ”‚ โ”œโ”€โ”€ verification.js # Element verification
110
+ โ”‚ โ”œโ”€โ”€ content.js # Page content analysis
111
+ โ”‚ โ””โ”€โ”€ utilities.js # Screenshots, waits
112
+ โ”œโ”€โ”€ demos/ # Framework demonstrations
113
+ โ”œโ”€โ”€ interactive/ # Interactive testing tools
114
+ โ””โ”€โ”€ testing/ # Testing utilities
115
+ ```
116
+
117
+ ## โš™๏ธ Configuration
118
+
119
+ ### Default Configuration
120
+ Endorphin AI works out of the box with sensible defaults, but you can customize it by creating an `endorphin.config.js` file in your project root:
121
+
122
+ ```javascript
123
+ // endorphin.config.js
124
+ export default {
125
+ // Browser configuration
126
+ browser: {
127
+ type: 'chromium', // chromium, firefox, webkit
128
+ headless: true, // Run browser in headless mode
129
+ viewport: { // Browser viewport size
130
+ width: 1280,
131
+ height: 720
132
+ },
133
+ timeout: 30000 // Default timeout in milliseconds
134
+ },
135
+
136
+ // AI configuration
137
+ ai: {
138
+ model: 'gpt-4o-mini', // OpenAI model to use
139
+ temperature: 0.1, // AI creativity (0-1)
140
+ maxRetries: 3 // Max retries for AI calls
141
+ },
142
+
143
+ // Test execution configuration
144
+ execution: {
145
+ timeout: 60000, // Test timeout in milliseconds
146
+ parallel: 1, // Number of parallel tests
147
+ screenshots: true, // Take screenshots on failure
148
+ testsDirectory: './tests', // Directory containing test files
149
+ dataDirectory: './data' // Directory containing test data
150
+ },
151
+
152
+ // Environment-specific settings
153
+ environments: {
154
+ development: {
155
+ baseUrl: 'http://localhost:3000'
156
+ },
157
+ staging: {
158
+ baseUrl: 'https://staging.example.com'
159
+ },
160
+ production: {
161
+ baseUrl: 'https://example.com'
162
+ }
163
+ }
164
+ };
165
+ ```
166
+
167
+ ### CLI Options
168
+ You can override configuration with CLI flags:
169
+
170
+ ```bash
171
+ # Run with different browser
172
+ endorphin run test all --browser firefox
173
+
174
+ # Run in non-headless mode
175
+ endorphin run test QE-001 --no-headless
176
+
177
+ # Set custom viewport
178
+ endorphin run test all --viewport 1920x1080
179
+
180
+ # Run tests in parallel
181
+ endorphin run test all --parallel 3
182
+
183
+ # Use different AI model
184
+ endorphin run test all --model gpt-4
185
+
186
+ # Set environment
187
+ endorphin run test all --env staging
188
+ ```
189
+
190
+ ## ๐Ÿ“ Test Categories
191
+
192
+ You can organize your tests using tags and priorities:
193
+
194
+ ### Common Tags
195
+ - `authentication` - Login, logout, registration tests
196
+ - `smoke` - Critical path tests that must pass
197
+ - `navigation` - Menu, links, page routing tests
198
+ - `forms` - Form filling and validation tests
199
+ - `checkout` - E-commerce purchase flow tests
200
+ - `search` - Search functionality tests
201
+ - `responsive` - Mobile/tablet/desktop tests
202
+
203
+ ### Priority Levels
204
+ - `High` - Critical functionality, run on every build
205
+ - `Medium` - Important features, run daily
206
+ - `Low` - Nice-to-have features, run weekly
207
+
208
+ ### Example Test Organization
209
+ ```javascript
210
+ // tests/auth-tests.js
211
+ export const LOGIN_TEST = {
212
+ id: "AUTH-001",
213
+ tags: ["authentication", "smoke"],
214
+ priority: "High",
215
+ // ...
216
+ };
217
+
218
+ export const LOGOUT_TEST = {
219
+ id: "AUTH-002",
220
+ tags: ["authentication"],
221
+ priority: "Medium",
222
+ // ...
223
+ };
224
+ ```
225
+
226
+ ## ๐Ÿ“ Project Structure
227
+
228
+ Your project should look like this:
229
+
230
+ ```
231
+ my-test-project/
232
+ โ”œโ”€โ”€ .env # OpenAI API key
233
+ โ”œโ”€โ”€ tests/ # Your test files
234
+ โ”‚ โ”œโ”€โ”€ login-test.js # Authentication tests
235
+ โ”‚ โ”œโ”€โ”€ checkout-test.js # E-commerce tests
236
+ โ”‚ โ””โ”€โ”€ navigation-test.js # UI/Navigation tests
237
+ โ”œโ”€โ”€ endorphin.config.js # Optional configuration
238
+ โ””โ”€โ”€ package.json # Project config
239
+ ```
240
+
241
+ ## ๐Ÿ“ Test File Format
242
+
243
+ Each test file should export test objects with this structure:
244
+
245
+ ```javascript
246
+ export const QE001 = {
247
+ id: "QE-001", // Unique test identifier
248
+ name: "Basic Login Test", // Human readable name
249
+ description: "Test login functionality with valid credentials",
250
+ priority: "High", // High, Medium, Low
251
+ tags: ["authentication", "login", "smoke"], // Categories
252
+ site: "https://example.com/", // Target website
253
+ testData: { // Test data (optional)
254
+ email: "test@example.com",
255
+ password: "password123"
256
+ },
257
+ task: `Your test instructions in plain English...`
258
+ };
259
+
260
+ // Multiple tests per file
261
+ export const QE002 = {
262
+ id: "QE-002",
263
+ name: "Registration Test",
264
+ // ... more test config
265
+ };
266
+ ```
267
+
268
+ ## โš™๏ธ Configuration
269
+
270
+ ### Optional: endorphin.config.js
271
+ ```javascript
272
+ export default {
273
+ // Global test settings
274
+ defaultTimeout: 30000,
275
+ headless: false,
276
+ viewport: { width: 1280, height: 720 },
277
+
278
+ // Default test data
279
+ testData: {
280
+ baseUrl: "https://staging.example.com",
281
+ adminEmail: "admin@example.com"
282
+ },
283
+
284
+ // Result settings
285
+ screenshots: true,
286
+ recordVideo: false
287
+ };
288
+ ```
289
+
290
+ ## ๐Ÿ”ง Configuration
291
+
292
+ ### Browser Configuration (`framework/config/browser-config.js`)
293
+ - Browser launch options (headless mode, viewport size)
294
+ - Timeouts and delays
295
+ - Screenshot settings
296
+ - Page loading options
297
+
298
+ ### AI Agent Configuration (`framework/config/agent-config.js`)
299
+ - OpenAI API settings
300
+ - Model selection (GPT-4o)
301
+ - Recursion limits and timeouts
302
+ - Stop phrases for test completion
303
+ - Execution timing settings
304
+
305
+ ### Path Configuration (`framework/config/paths.js`)
306
+ - Test result directories
307
+ - Recording locations
308
+ - Screenshot storage
309
+
310
+ ## ๐Ÿ“Š Test Results
311
+
312
+ Each test execution creates:
313
+ - **๐Ÿ“ Session Directory**: `test-result/[test-id]_[timestamp]/`
314
+ - **๐Ÿ“ Session Data**: `test-session.json` with complete execution details
315
+ - **๐Ÿ“Š Summary**: `summary.json` with test outcomes
316
+ - **๐Ÿ“ธ Screenshots**: Automatic visual documentation
317
+ - **๐Ÿ”„ Step Logs**: Detailed execution tracking
318
+
319
+ ### Example Test Output
320
+ ```
321
+ ๐ŸŽฏ Running Task: QE-001 - Basic Login Test
322
+ ๐Ÿ“ Task: Test the login functionality with valid credentials
323
+ โฐ Started at: 2025-06-19T05:36:37.705Z
324
+
325
+ ๐Ÿ“ Created test session: qe-001_2025-06-19T05-36-37-706Z
326
+ ๐ŸŒ Navigate to: https://qafromla.herokuapp.com
327
+ ๐Ÿ“ธ Screenshot taken: step-1-navigation.png
328
+ ๐Ÿ” Found login elements
329
+ ๐Ÿ“ Filling login form...
330
+ โœ… Login successful - test completed!
331
+
332
+ ๐Ÿ“Š Result: PASSED
333
+ ๐Ÿ“ Results: test-result/qe-001_2025-06-19T05-36-37-706Z
334
+ ```
335
+
336
+ ## ๐ŸŽฎ Interactive Features
337
+
338
+ ### Custom Test Creation
339
+ ```bash
340
+ npm run interactive
341
+ ```
342
+ Create tests on-the-fly with guided prompts:
343
+ - Custom navigation tasks
344
+ - Form filling scenarios
345
+ - Login test automation
346
+ - Content verification
347
+
348
+ ### Framework Demonstration
349
+ ```bash
350
+ npm run interactive-demo
351
+ ```
352
+ Runs pre-built demonstration tests showcasing:
353
+ - Navigation capabilities
354
+ - Form interaction
355
+ - Content analysis
356
+ - Result tracking
357
+
358
+ ## ๐Ÿ” Browser Automation Tools
359
+
360
+ The framework includes intelligent tools powered by AI:
361
+
362
+ ### Navigation Tools
363
+ - **navigate**: Smart URL navigation with wait conditions
364
+ - **getPageContent**: Intelligent HTML analysis for element detection
365
+
366
+ ### Interaction Tools
367
+ - **click**: AI-powered element clicking with automatic waiting
368
+ - **fill**: Smart form filling with focus management
369
+ - **clearField**: Intelligent field clearing before input
370
+
371
+ ### Verification Tools
372
+ - **verifyElement**: Element visibility and interaction verification
373
+ - **getElementInfo**: Detailed element analysis and properties
374
+
375
+ ### Utility Tools
376
+ - **wait**: Configurable delays and timing control
377
+ - **screenshot**: High-quality visual documentation
378
+
379
+ ## ๐ŸŽฎ Command Examples
380
+
381
+ ### Basic Commands
382
+ ```bash
383
+ # Run specific test
384
+ endorphin run test QE-001
385
+
386
+ # Run all tests
387
+ endorphin run test all
388
+
389
+ # Run by priority
390
+ endorphin run test --priority High
391
+ endorphin run test --priority Medium
392
+
393
+ # Run by tags
394
+ endorphin run test --tag authentication
395
+ endorphin run test --tag smoke
396
+ endorphin run test --tag checkout
397
+
398
+ # Interactive test creation
399
+ endorphin run test-recorder
400
+ ```
401
+
402
+ ### Multiple Tag Support
403
+ ```bash
404
+ # Run tests matching any of these tags
405
+ endorphin run test --tag "authentication,smoke"
406
+
407
+ # Run high priority authentication tests
408
+ endorphin run test --priority High --tag authentication
409
+ ```
410
+
411
+ ## ๐Ÿš€ Getting Started Examples
412
+
413
+ ### Quick Smoke Test
414
+ ```bash
415
+ endorphin run test --tag smoke
416
+ ```
417
+
418
+ ### Authentication Testing
419
+ ```bash
420
+ endorphin run test --tag authentication
421
+ ```
422
+
423
+ ### Complete Test Suite
424
+ ```bash
425
+ endorphin run test all
426
+ ```
427
+
428
+ ### Create Custom Test
429
+ ```bash
430
+ endorphin run test-recorder
431
+ # Follow prompts to create your own test
432
+ ```
433
+
434
+ ### Example Test File
435
+ Create `tests/my-first-test.js`:
436
+ ```javascript
437
+ export const QE001 = {
438
+ id: "QE-001",
439
+ name: "Homepage Navigation Test",
440
+ description: "Verify main navigation works correctly",
441
+ priority: "High",
442
+ tags: ["navigation", "smoke"],
443
+ site: "https://example.com/",
444
+ task: `Navigate to https://example.com/.
445
+ Click on "About" link in navigation.
446
+ Wait 2 seconds for page load.
447
+ Verify page title contains "About".
448
+ Take a screenshot.`
449
+ };
450
+ ```
451
+
452
+ Then run it:
453
+ ```bash
454
+ endorphin run test QE-001
455
+ ```
456
+
457
+ ## ๐ŸŽ‰ Features
458
+
459
+ โœ… **AI-Powered**: GPT-4o analyzes page structure for intelligent automation
460
+ โœ… **Visual Testing**: Automatic screenshot capture and visual validation
461
+ โœ… **Modular Design**: Clean, maintainable, extensible architecture
462
+ โœ… **Session Tracking**: Comprehensive test execution logging
463
+ โœ… **Interactive Mode**: Real-time test creation and execution
464
+ โœ… **Flexible Configuration**: Easily customizable browser and AI settings
465
+ โœ… **Comprehensive Reporting**: Detailed results with visual documentation
466
+ โœ… **Error Handling**: Robust retry mechanisms and failure recovery
467
+
468
+ The framework is production-ready and provides a solid foundation for scalable browser automation testing!
469
+
470
+ ## License
471
+
472
+ Endorphin is licensed under the GNU Affero General Public License, Version 3 (AGPLv3). The full license text is available in the `LICENSE` file.
473
+
474
+ For organizations that cannot use AGPLv3-licensed software, commercial licenses are available. Please contact us at [iam@andrewnovykov.com] for more information.