@sridharkikkeri/playwright-common 1.0.40 → 1.0.42

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.
@@ -7,130 +7,332 @@ const { execSync } = require('child_process');
7
7
  const projectName = process.argv[2] || 'my-healthedge-tests';
8
8
  const projectPath = path.join(process.cwd(), projectName);
9
9
 
10
- console.log(`\nšŸš€ Creating HealthEdge Playwright project (v1.0.39): ${projectName}\n`);
11
-
12
- // Recursive Copy Helper
13
- function copyRecursiveSync(src, dest) {
14
- if (!fs.existsSync(src)) return;
15
- const stats = fs.statSync(src);
16
- if (stats.isDirectory()) {
17
- if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
18
- fs.readdirSync(src).forEach((child) => {
19
- copyRecursiveSync(path.join(src, child), path.join(dest, child));
20
- });
21
- } else {
22
- fs.copyFileSync(src, dest);
23
- }
10
+ console.log(`\nšŸš€ Creating HealthEdge Playwright project: ${projectName}\n`);
11
+
12
+ // Helper to copy directory recursively
13
+ function copyDir(src, dest) {
14
+ if (!fs.existsSync(src)) return;
15
+ fs.mkdirSync(dest, { recursive: true });
16
+ const entries = fs.readdirSync(src, { withFileTypes: true });
17
+ for (const entry of entries) {
18
+ const srcPath = path.join(src, entry.name);
19
+ const destPath = path.join(dest, entry.name);
20
+ if (entry.isDirectory()) {
21
+ copyDir(srcPath, destPath);
22
+ } else {
23
+ fs.copyFileSync(srcPath, destPath);
24
+ }
25
+ }
24
26
  }
25
27
 
26
- // 1. Create Clean Directory Structure
27
- const baseDirs = [
28
- 'src/core',
29
- 'src/tests/pages',
30
- 'src/fixtures',
31
- 'src/i18n',
32
- 'src/utils',
33
- 'api-docs'
28
+ // Create project structure matching smokeTest
29
+ const dirs = [
30
+ 'src/main/pages',
31
+ 'src/main/api/auth',
32
+ 'src/main/builders',
33
+ 'src/main/config',
34
+ 'src/main/fixtures',
35
+ 'src/main/i18n',
36
+ 'src/main/reporting',
37
+ 'src/main/selfhealing',
38
+ 'src/main/utils',
39
+ 'src/main/visual',
40
+ 'src/main/workflows',
41
+ 'src/main/wrappers',
42
+ 'src/tests/specs',
43
+ 'src/tests/data',
44
+ 'config',
45
+ 'allure-results',
46
+ 'allure-report'
34
47
  ];
35
48
 
36
- baseDirs.forEach(d => {
37
- const fullPath = path.join(projectPath, d);
38
- if (!fs.existsSync(fullPath)) {
39
- fs.mkdirSync(fullPath, { recursive: true });
40
- }
49
+ dirs.forEach(dir => {
50
+ fs.mkdirSync(path.join(projectPath, dir), { recursive: true });
41
51
  });
42
52
 
43
- // 2. High-Fidelity Replication ("As It Is")
44
- const frameworkRootDir = __dirname;
45
- const frameworkSrc = path.join(frameworkRootDir, 'src');
46
- const frameworkApiDocs = path.join(frameworkRootDir, 'api-docs');
53
+ // package.json
54
+ const packageJson = {
55
+ name: projectName,
56
+ version: '1.0.0',
57
+ scripts: {
58
+ 'test': 'playwright test',
59
+ 'test:dev': 'TEST_ENV=dev playwright test',
60
+ 'test:qa': 'TEST_ENV=qa playwright test',
61
+ 'test:auto': 'TEST_ENV=auto playwright test',
62
+ 'test:staging': 'TEST_ENV=staging playwright test',
63
+ 'test:prod': 'TEST_ENV=prod playwright test',
64
+ 'report': 'allure generate allure-results --clean -o allure-report && allure open allure-report',
65
+ 'lint': 'eslint .',
66
+ 'lint:fix': 'eslint . --fix'
67
+ },
68
+ dependencies: {
69
+ '@sridharkikkeri/playwright-common': 'latest',
70
+ '@playwright/test': '^1.42.0',
71
+ 'allure-playwright': '^3.4.5'
72
+ },
73
+ devDependencies: {
74
+ '@typescript-eslint/eslint-plugin': '^8.55.0',
75
+ '@typescript-eslint/parser': '^8.55.0',
76
+ 'eslint': '^8.57.1',
77
+ 'typescript': '^5.3.0'
78
+ }
79
+ };
47
80
 
48
- // Copy Source Code
49
- if (fs.existsSync(frameworkSrc)) {
50
- console.log('šŸ“„ Copying framework source logic...');
51
- copyRecursiveSync(path.join(frameworkSrc, 'core'), path.join(projectPath, 'src/core'));
52
- copyRecursiveSync(path.join(frameworkSrc, 'fixtures'), path.join(projectPath, 'src/fixtures'));
81
+ fs.writeFileSync(
82
+ path.join(projectPath, 'package.json'),
83
+ JSON.stringify(packageJson, null, 2)
84
+ );
85
+
86
+ // playwright.config.ts
87
+ const playwrightConfig = `import { defineConfig } from '@playwright/test';
88
+
89
+ export default defineConfig({
90
+ testDir: './src/tests/specs',
91
+ timeout: 30000,
92
+ retries: process.env.CI ? 2 : 0,
93
+ workers: process.env.CI ? 1 : undefined,
94
+ reporter: [
95
+ ['html'],
96
+ ['allure-playwright', { outputFolder: 'allure-results' }]
97
+ ],
98
+ use: {
99
+ baseURL: process.env.BASE_URL || 'https://example.com',
100
+ trace: 'on-first-retry',
101
+ screenshot: 'only-on-failure',
102
+ },
103
+ });
104
+ `;
53
105
 
54
- // Copy Sample Tests (including Pages)
55
- if (fs.existsSync(path.join(frameworkSrc, 'tests'))) {
56
- copyRecursiveSync(path.join(frameworkSrc, 'tests'), path.join(projectPath, 'src/tests'));
106
+ fs.writeFileSync(path.join(projectPath, 'playwright.config.ts'), playwrightConfig);
107
+
108
+ // Create all environment configs
109
+ const envConfigs = {
110
+ dev: {
111
+ healingEnabled: true,
112
+ environment: 'dev',
113
+ baseUrl: 'https://dev.example.com',
114
+ apiUrl: 'https://api-dev.example.com',
115
+ timeout: 30000,
116
+ retries: 2
117
+ },
118
+ qa: {
119
+ healingEnabled: true,
120
+ environment: 'qa',
121
+ baseUrl: 'https://qa.example.com',
122
+ apiUrl: 'https://api-qa.example.com',
123
+ timeout: 30000,
124
+ retries: 2
125
+ },
126
+ auto: {
127
+ healingEnabled: true,
128
+ environment: 'auto',
129
+ baseUrl: 'https://auto.example.com',
130
+ apiUrl: 'https://api-auto.example.com',
131
+ timeout: 30000,
132
+ retries: 2
133
+ },
134
+ staging: {
135
+ healingEnabled: true,
136
+ environment: 'staging',
137
+ baseUrl: 'https://staging.example.com',
138
+ apiUrl: 'https://api-staging.example.com',
139
+ timeout: 30000,
140
+ retries: 1
141
+ },
142
+ prod: {
143
+ healingEnabled: false,
144
+ environment: 'prod',
145
+ baseUrl: 'https://example.com',
146
+ apiUrl: 'https://api.example.com',
147
+ timeout: 60000,
148
+ retries: 0
149
+ }
150
+ };
151
+
152
+ Object.entries(envConfigs).forEach(([env, config]) => {
153
+ fs.writeFileSync(
154
+ path.join(projectPath, 'config', `${env}.json`),
155
+ JSON.stringify(config, null, 2)
156
+ );
157
+ });
158
+
159
+ // Sample Page Object
160
+ const samplePage = `import { Page } from '@playwright/test';
161
+ import { BasePage } from '@sridharkikkeri/playwright-common';
162
+
163
+ export class HomePage extends BasePage {
164
+ constructor(page: Page) {
165
+ super(page, 'HomePage');
57
166
  }
58
- }
59
167
 
60
- // Copy Documentation Portal
61
- if (fs.existsSync(frameworkApiDocs)) {
62
- console.log('šŸ“š Copying enterprise API documentation...');
63
- copyRecursiveSync(frameworkApiDocs, path.join(projectPath, 'api-docs'));
168
+ private readonly searchInput = this.element('[data-testid="search"]');
169
+ private readonly searchBtn = this.element('button[type="submit"]');
170
+
171
+ async search(query: string) {
172
+ await this.searchInput.fill(query, 'Enter search query');
173
+ await this.searchBtn.click('Click search button');
174
+ }
64
175
  }
176
+ `;
65
177
 
66
- // Copy Core Strategy Documents
67
- const strategyFiles = [
68
- 'HEALING_CACHE_STRATEGY.md',
69
- 'VISUAL_TESTING.md',
70
- 'README.md'
71
- ];
178
+ fs.writeFileSync(path.join(projectPath, 'src/main/pages/HomePage.ts'), samplePage);
72
179
 
73
- strategyFiles.forEach(file => {
74
- const src = path.join(frameworkRootDir, file);
75
- if (fs.existsSync(src)) {
76
- console.log(`šŸ“Ž Including ${file}...`);
77
- fs.copyFileSync(src, path.join(projectPath, file));
78
- }
180
+ // Sample Test
181
+ const sampleTest = `import { test } from '@sridharkikkeri/playwright-common';
182
+ import { HomePage } from '../../main/pages/HomePage';
183
+
184
+ test.describe('Sample Tests', () => {
185
+ test('Search functionality', async ({ page }) => {
186
+ const homePage = new HomePage(page);
187
+ await page.goto('/');
188
+ await homePage.search('playwright');
189
+ });
79
190
  });
191
+ `;
80
192
 
81
- // 3. Project Configuration
82
- const packageJson = {
83
- name: projectName,
84
- version: '1.0.0',
85
- description: 'HealthEdge Enterprise Test Project',
86
- scripts: {
87
- 'test': 'playwright test',
88
- 'test:dev': 'TEST_ENV=dev playwright test',
89
- 'lint': 'eslint . --ext .ts'
90
- },
91
- dependencies: {
92
- '@playwright/test': '^1.42.0',
93
- 'allure-playwright': '^3.4.5'
94
- },
95
- devDependencies: {
96
- '@typescript-eslint/eslint-plugin': '^8.55.0',
97
- '@typescript-eslint/parser': '^8.55.0',
98
- 'eslint': '^8.57.1',
99
- 'typescript': '^5.3.0'
100
- }
101
- };
102
- fs.writeFileSync(path.join(projectPath, 'package.json'), JSON.stringify(packageJson, null, 2));
193
+ fs.writeFileSync(path.join(projectPath, 'src/tests/specs/sample.spec.ts'), sampleTest);
103
194
 
104
- // Single Framework Config
105
- const config = { healingEnabled: true, environment: 'dev', baseUrl: 'https://example.com', apiUrl: 'https://api.example.com', timeout: 30000 };
106
- fs.writeFileSync(path.join(projectPath, 'framework.config.json'), JSON.stringify(config, null, 2));
195
+ // Test data
196
+ const testData = {
197
+ users: [
198
+ { username: 'testuser1', password: 'password123' },
199
+ { username: 'testuser2', password: 'password456' }
200
+ ]
201
+ };
107
202
 
108
- const playwrightConfig = `import { defineConfig } from '@playwright/test';
109
- export default defineConfig({
110
- testDir: './src/tests',
111
- timeout: 30000,
112
- reporter: [['html'], ['allure-playwright', { outputFolder: 'allure-results' }]],
113
- use: { trace: 'on-first-retry', screenshot: 'only-on-failure' }
114
- });`;
115
- fs.writeFileSync(path.join(projectPath, 'playwright.config.ts'), playwrightConfig);
203
+ fs.writeFileSync(
204
+ path.join(projectPath, 'src/tests/data/testdata.json'),
205
+ JSON.stringify(testData, null, 2)
206
+ );
116
207
 
208
+ // tsconfig.json
117
209
  const tsConfig = {
118
- compilerOptions: { target: 'ES2020', module: 'commonjs', lib: ['ES2020', 'DOM'], strict: true, esModuleInterop: true, skipLibCheck: true, resolveJsonModule: true },
119
- include: ['src/**/*']
210
+ compilerOptions: {
211
+ target: 'ES2020',
212
+ module: 'commonjs',
213
+ lib: ['ES2020'],
214
+ strict: true,
215
+ esModuleInterop: true,
216
+ skipLibCheck: true,
217
+ forceConsistentCasingInFileNames: true,
218
+ resolveJsonModule: true,
219
+ baseUrl: '.',
220
+ paths: {
221
+ '@main/*': ['src/main/*'],
222
+ '@tests/*': ['src/tests/*']
223
+ }
224
+ },
225
+ include: ['src/**/*']
120
226
  };
121
- fs.writeFileSync(path.join(projectPath, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
122
227
 
123
- const gitignore = `node_modules/\nallure-results/\nallure-report/\n.env\n*.log\n`;
228
+ fs.writeFileSync(
229
+ path.join(projectPath, 'tsconfig.json'),
230
+ JSON.stringify(tsConfig, null, 2)
231
+ );
232
+
233
+ // .gitignore
234
+ const gitignore = `node_modules/
235
+ allure-results/
236
+ allure-report/
237
+ test-results/
238
+ playwright-report/
239
+ .env
240
+ *.log
241
+ `;
242
+
124
243
  fs.writeFileSync(path.join(projectPath, '.gitignore'), gitignore);
125
244
 
126
- console.log('\nāœ… Enterprise Project Created (Clean & Stable)');
127
- console.log('šŸ“¦ Installing dependencies...\n');
245
+ // README
246
+ const readme = `# ${projectName}
247
+
248
+ Generated with \`npx create-healthedge-tests\`
249
+
250
+ ## Project Structure
251
+
252
+ \`\`\`
253
+ ${projectName}/
254
+ ā”œā”€ā”€ config/ # Environment configs (dev, qa, auto, staging, prod)
255
+ ā”œā”€ā”€ src/
256
+ │ ā”œā”€ā”€ main/ # Framework code
257
+ │ │ ā”œā”€ā”€ pages/ # Page Object Models
258
+ │ │ ā”œā”€ā”€ api/ # API client & auth
259
+ │ │ ā”œā”€ā”€ builders/ # Test data builders
260
+ │ │ ā”œā”€ā”€ workflows/ # Reusable workflows
261
+ │ │ └── ... # Other framework modules
262
+ │ └── tests/
263
+ │ ā”œā”€ā”€ specs/ # Test specifications
264
+ │ └── data/ # Test data
265
+ ā”œā”€ā”€ allure-results/ # Test reports
266
+ └── playwright.config.ts
267
+ \`\`\`
268
+
269
+ ## Quick Start
270
+
271
+ \`\`\`bash
272
+ npm install
273
+ npm run test:dev
274
+ npm run report
275
+ \`\`\`
276
+
277
+ ## Environment-Specific Tests
278
+
279
+ \`\`\`bash
280
+ npm run test:dev # Uses config/dev.json
281
+ npm run test:qa # Uses config/qa.json
282
+ npm run test:auto # Uses config/auto.json
283
+ npm run test:staging # Uses config/staging.json
284
+ npm run test:prod # Uses config/prod.json
285
+ \`\`\`
286
+
287
+ ## Features
288
+
289
+ āœ… AI-Powered Self-Healing
290
+ āœ… Visual Regression Testing
291
+ āœ… API Testing Support
292
+ āœ… Allure Reporting
293
+ āœ… Multi-Environment Configs
294
+ āœ… Page Object Pattern
295
+ āœ… Test Data Builders
296
+ āœ… Reusable Workflows
297
+
298
+ ## Documentation
299
+
300
+ - [Framework Package](https://www.npmjs.com/package/@sridharkikkeri/playwright-common)
301
+ - [Clean Imports Guide](https://github.com/healthedge/playwright-framework/blob/main/CLEAN_IMPORTS.md)
302
+ - [Visual Testing](https://github.com/healthedge/playwright-framework/blob/main/VISUAL_TESTING.md)
303
+ `;
304
+
305
+ fs.writeFileSync(path.join(projectPath, 'README.md'), readme);
306
+
307
+ // Copy framework source files from package
308
+ const frameworkSrc = path.join(__dirname, 'src', 'com', 'healthedge', 'common');
309
+ if (fs.existsSync(frameworkSrc)) {
310
+ console.log('\nšŸ“‹ Copying framework source files...\n');
311
+
312
+ // Copy core modules to src/main/
313
+ const modules = ['api', 'config', 'fixtures', 'i18n', 'pages', 'reporting', 'selfhealing', 'utils', 'visual', 'wrappers'];
314
+ modules.forEach(module => {
315
+ const src = path.join(frameworkSrc, 'core', module);
316
+ const dest = path.join(projectPath, 'src', 'main', module);
317
+ if (fs.existsSync(src)) {
318
+ copyDir(src, dest);
319
+ console.log(` āœ“ Copied ${module}`);
320
+ }
321
+ });
322
+
323
+ console.log('\nāœ… Framework files copied');
324
+ }
325
+
326
+ console.log('\nāœ… Project structure created');
327
+ console.log('\nšŸ“¦ Installing dependencies...\n');
128
328
 
129
329
  try {
130
- execSync('npm install', { cwd: projectPath, stdio: 'inherit' });
131
- console.log('\nāœ… Dependencies installed');
330
+ execSync('npm install', { cwd: projectPath, stdio: 'inherit' });
331
+ console.log('\nāœ… Dependencies installed');
132
332
  } catch (error) {
133
- console.log('\nāš ļø npm install failed. Run manually.');
333
+ console.log('\nāš ļø Run "npm install" manually in the project directory');
134
334
  }
135
335
 
136
- console.log(`\nšŸŽ‰ cd ${projectName} && npm run test\n`);
336
+ console.log(`\nšŸŽ‰ Project ready! Next steps:\n`);
337
+ console.log(` cd ${projectName}`);
338
+ console.log(` npm run test:dev\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sridharkikkeri/playwright-common",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Production-grade Playwright framework with AI-powered self-healing, visual regression, and enterprise features",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",