@sridharkikkeri/playwright-common 1.0.16 → 1.0.17

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.
@@ -9,9 +9,9 @@ const projectPath = path.join(process.cwd(), projectName);
9
9
 
10
10
  console.log(`\nšŸš€ Creating HealthEdge Playwright project: ${projectName}\n`);
11
11
 
12
- // Create project structure
12
+ // Comprehensive Directory Structure
13
13
  const dirs = [
14
- 'src/core/api',
14
+ 'src/core/api/auth',
15
15
  'src/core/config',
16
16
  'src/core/i18n',
17
17
  'src/core/pages',
@@ -38,11 +38,11 @@ dirs.forEach(idr => {
38
38
  fs.mkdirSync(path.join(projectPath, idr), { recursive: true });
39
39
  });
40
40
 
41
- // package.json
41
+ // package.json for the NEW project
42
42
  const packageJson = {
43
43
  name: projectName,
44
44
  version: '1.0.0',
45
- description: 'HealthEdge Playwright Test Project',
45
+ description: 'HealthEdge Enterprise Playwright Test Project',
46
46
  scripts: {
47
47
  'test': 'playwright test',
48
48
  'test:dev': 'TEST_ENV=dev playwright test',
@@ -50,12 +50,13 @@ const packageJson = {
50
50
  'test:auto': 'TEST_ENV=auto playwright test',
51
51
  'test:staging': 'TEST_ENV=staging playwright test',
52
52
  'test:prod': 'TEST_ENV=prod playwright test',
53
+ 'test:visual': 'playwright test src/tests/visual.spec.ts',
53
54
  'report': 'allure generate allure-results --clean -o allure-report && allure open allure-report',
54
55
  'lint': 'eslint .',
55
56
  'lint:fix': 'eslint . --fix'
56
57
  },
57
58
  dependencies: {
58
- '@sridharkikkeri/playwright-common': '^1.0.16',
59
+ '@sridharkikkeri/playwright-common': '^1.0.17',
59
60
  '@playwright/test': '^1.42.0',
60
61
  'allure-playwright': '^3.4.5'
61
62
  },
@@ -69,84 +70,137 @@ const packageJson = {
69
70
 
70
71
  fs.writeFileSync(path.join(projectPath, 'package.json'), JSON.stringify(packageJson, null, 2));
71
72
 
72
- // --- PROFESSIONAL EXTENSION BOILERPLATE ---
73
+ // --- CORE EXTENSION BOILERPLATE ---
73
74
 
74
75
  const baseApiClientTs = `import { ApiClient } from '@sridharkikkeri/playwright-common';
76
+
75
77
  export class BaseApiClient extends ApiClient {
76
- constructor(baseUrl: string) { super(baseUrl); }
77
- }`;
78
+ constructor(baseUrl: string) {
79
+ super(baseUrl);
80
+ }
81
+ // Add shared project-specific headers or logic here
82
+ }
83
+ `;
78
84
  fs.writeFileSync(path.join(projectPath, 'src/core/api/BaseApiClient.ts'), baseApiClientTs);
79
85
 
86
+ const projectAuthTs = `import { CookieAuth, AuthStrategy } from '@sridharkikkeri/playwright-common';
87
+
88
+ export class ProjectAuth {
89
+ static async setupSession(auth: AuthStrategy) {
90
+ // Implement custom complex auth setup if needed
91
+ }
92
+ }
93
+ `;
94
+ fs.writeFileSync(path.join(projectPath, 'src/core/api/auth/ProjectAuth.ts'), projectAuthTs);
95
+
80
96
  const envConfigTs = `import { ConfigManager } from '@sridharkikkeri/playwright-common';
97
+
81
98
  export class ProjectConfig extends ConfigManager {
82
- static getProjectName() { return '${projectName}'; }
83
- }`;
99
+ static getClientName() { return 'HealthEdge'; }
100
+ }
101
+ `;
84
102
  fs.writeFileSync(path.join(projectPath, 'src/core/config/ProjectConfig.ts'), envConfigTs);
85
103
 
86
- const locTs = `import { Localization } from '@sridharkikkeri/playwright-common';
104
+ const localizationTs = `import { Localization } from '@sridharkikkeri/playwright-common';
105
+
87
106
  export class ProjectLocalization extends Localization {
88
- static getDefaultLocale() { return 'en'; }
89
- }`;
90
- fs.writeFileSync(path.join(projectPath, 'src/core/i18n/ProjectLocalization.ts'), locTs);
107
+ static getAvailableLocales() { return ['en', 'fr']; }
108
+ }
109
+ `;
110
+ fs.writeFileSync(path.join(projectPath, 'src/core/i18n/ProjectLocalization.ts'), localizationTs);
91
111
 
92
112
  const baseComponentTs = `import { Page } from '@playwright/test';
93
113
  import { BasePage, ActionOrchestrator } from '@sridharkikkeri/playwright-common';
114
+
94
115
  export abstract class BaseComponent extends BasePage {
95
116
  constructor(page: Page, orchestrator?: ActionOrchestrator) {
96
117
  super(page, { pageName: 'BaseComponent', orchestrator });
97
118
  }
98
- }`;
119
+ }
120
+ `;
99
121
  fs.writeFileSync(path.join(projectPath, 'src/core/pages/BaseComponent.ts'), baseComponentTs);
100
122
 
101
123
  const reporterTs = `import { AllureUtil } from '@sridharkikkeri/playwright-common';
124
+
102
125
  export class ProjectReporter {
103
- static async logStep(name: string) { console.log(\`[STEP] \${name}\`); }
104
- }`;
126
+ static async logEnterpriseStep(name: string) {
127
+ console.log(\`[ENTERPRISE] \${name}\`);
128
+ }
129
+ }
130
+ `;
105
131
  fs.writeFileSync(path.join(projectPath, 'src/core/reporting/ProjectReporter.ts'), reporterTs);
106
132
 
107
133
  const healingTs = `import { LocatorHealing } from '@sridharkikkeri/playwright-common';
134
+
108
135
  export class ProjectHealer extends LocatorHealing {
109
- // Customize project-specific healing logic here
110
- }`;
136
+ // Override framework healing logic here
137
+ }
138
+ `;
111
139
  fs.writeFileSync(path.join(projectPath, 'src/core/selfhealing/ProjectHealer.ts'), healingTs);
112
140
 
113
141
  const visualTs = `import { VisualTesting } from '@sridharkikkeri/playwright-common';
142
+
114
143
  export class ProjectVisuals extends VisualTesting {
115
- // Custom visual testing overrides
116
- }`;
144
+ // Custom exclusions or thresholds
145
+ }
146
+ `;
117
147
  fs.writeFileSync(path.join(projectPath, 'src/core/visual/ProjectVisuals.ts'), visualTs);
118
148
 
119
149
  const wrapperTs = `import { ElementWrapper } from '@sridharkikkeri/playwright-common';
150
+
120
151
  export class ProjectElement extends ElementWrapper {
121
- // Add custom interaction logic here
122
- }`;
152
+ // Extend element behaviors (e.g., custom scrolls)
153
+ }
154
+ `;
123
155
  fs.writeFileSync(path.join(projectPath, 'src/core/wrappers/ProjectElement.ts'), wrapperTs);
124
156
 
125
157
  const projectUtilsTs = `export class ProjectUtils {
126
- static async sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); }
127
- }`;
158
+ static generateRandomID() { return Math.random().toString(36).substring(7); }
159
+ }
160
+ `;
128
161
  fs.writeFileSync(path.join(projectPath, 'src/core/utils/ProjectUtils.ts'), projectUtilsTs);
129
162
 
130
- fs.writeFileSync(path.join(projectPath, 'api-docs/index.html'), `<html><body><h1>API Documentation for ${projectName}</h1><p>Run <code>npm run docs:generate</code> to populate.</p></body></html>`);
163
+ // --- UTILS & I18N POPULATION ---
164
+ const stringUtilsTs = `export class StringUtils {
165
+ static capitalize(str: string) { return str.charAt(0).toUpperCase() + str.slice(1); }
166
+ }`;
167
+ fs.writeFileSync(path.join(projectPath, 'src/utils/StringUtils.ts'), stringUtilsTs);
168
+
169
+ const dateUtilsTs = `export class DateUtils {
170
+ static now() { return new Date().toISOString(); }
171
+ }`;
172
+ fs.writeFileSync(path.join(projectPath, 'src/utils/DateUtils.ts'), dateUtilsTs);
173
+
174
+ fs.writeFileSync(path.join(projectPath, 'src/i18n/en.json'), JSON.stringify({ "welcome": "Welcome to HealthEdge" }, null, 2));
175
+ fs.writeFileSync(path.join(projectPath, 'src/i18n/fr.json'), JSON.stringify({ "welcome": "Bienvenue chez HealthEdge" }, null, 2));
131
176
 
132
- // --- Standard Project Files ---
177
+ // --- DOCUMENTATION ---
178
+ fs.writeFileSync(path.join(projectPath, 'api-docs/assets/style.css'), 'body { font-family: sans-serif; padding: 20px; }');
179
+ fs.writeFileSync(path.join(projectPath, 'api-docs/index.html'), `
180
+ <html>
181
+ <head><link rel="stylesheet" href="assets/style.css"></head>
182
+ <body>
183
+ <h1>${projectName} - API Documentation</h1>
184
+ <p>This folder is ready to host your TypeDoc or custom API documentation.</p>
185
+ </body>
186
+ </html>`);
187
+ ['classes', 'interfaces', 'types', 'variables'].forEach(fold => {
188
+ fs.writeFileSync(path.join(projectPath, `api-docs/${fold}/README.md`), `# ${fold}\nDocumentation for your project ${fold} goes here.`);
189
+ });
190
+
191
+ // --- STANDARD CONFIG & EXAMPLES ---
133
192
  const baseConfig = { healingEnabled: true, environment: 'dev', baseUrl: 'https://example.com', apiUrl: 'https://api.example.com', timeout: 30000, retries: 2 };
134
193
  const environments = ['dev', 'qa', 'auto', 'staging', 'prod'];
135
-
136
194
  environments.forEach(env => {
137
- const config = {
138
- ...baseConfig,
139
- environment: env,
140
- baseUrl: `https://${env}.example.com`,
141
- apiUrl: `https://api-${env}.example.com`
142
- };
195
+ const config = { ...baseConfig, environment: env, baseUrl: `https://${env}.example.com`, apiUrl: `https://api-${env}.example.com` };
143
196
  fs.writeFileSync(path.join(projectPath, `framework.config.${env}.json`), JSON.stringify(config, null, 2));
144
197
  });
145
198
  fs.writeFileSync(path.join(projectPath, 'framework.config.json'), JSON.stringify(baseConfig, null, 2));
146
199
 
147
200
  const playwrightConfig = `import { defineConfig } from '@playwright/test';
148
201
  export default defineConfig({
149
- testDir: './src/tests', timeout: 30000,
202
+ testDir: './src/tests',
203
+ timeout: 30000,
150
204
  reporter: [['html'], ['allure-playwright', { outputFolder: 'allure-results' }]],
151
205
  use: { trace: 'on-first-retry', screenshot: 'only-on-failure' }
152
206
  });`;
@@ -154,47 +208,101 @@ fs.writeFileSync(path.join(projectPath, 'playwright.config.ts'), playwrightConfi
154
208
 
155
209
  const fixturesTs = `import { test as base } from '@sridharkikkeri/playwright-common';
156
210
  import { HomePage } from '../pages/HomePage';
211
+
157
212
  export const test = base.extend<{ homePage: HomePage }>({
158
- homePage: async ({ page, orchestrator }, use) => { await use(new HomePage(page, orchestrator)); },
213
+ homePage: async ({ page, orchestrator }, use) => {
214
+ await use(new HomePage(page, orchestrator));
215
+ },
159
216
  });
217
+
160
218
  export { expect } from '@playwright/test';`;
161
219
  fs.writeFileSync(path.join(projectPath, 'src/fixtures/fixtures.ts'), fixturesTs);
162
220
 
163
221
  const samplePage = `import { Page } from '@playwright/test';
164
222
  import { BasePage, ActionOrchestrator } from '@sridharkikkeri/playwright-common';
223
+
165
224
  export class HomePage extends BasePage {
166
- constructor(page: Page, orchestrator?: ActionOrchestrator) { super(page, { pageName: 'HomePage', orchestrator }); }
225
+ constructor(page: Page, orchestrator?: ActionOrchestrator) {
226
+ super(page, { pageName: 'HomePage', orchestrator });
227
+ }
167
228
  private readonly searchBtn = this.element('button[type="submit"]');
168
- async clickSearch() { await this.searchBtn.click('Click Search'); }
169
- }`;
229
+ async clickSearch() { await this.searchBtn.click('Click Search Button'); }
230
+ }
231
+ `;
170
232
  fs.writeFileSync(path.join(projectPath, 'src/pages/HomePage.ts'), samplePage);
171
233
 
234
+ const visualTest = `import { test, expect } from '../fixtures/fixtures';
235
+
236
+ test.describe('Enterprise Visual Regression', () => {
237
+ test('HP Visual Verification', async ({ page }) => {
238
+ await page.goto('https://playwright.dev');
239
+ await expect(page).toHaveScreenshot('homepage.png', {
240
+ mask: [page.locator('.navbar')],
241
+ threshold: 0.1
242
+ });
243
+ });
244
+ });`;
245
+ fs.writeFileSync(path.join(projectPath, 'src/tests/visual.spec.ts'), visualTest);
246
+
172
247
  const sampleTest = `import { test, expect } from '../fixtures/fixtures';
173
- test('Demo Test', async ({ page, homePage }) => {
248
+
249
+ test('Standard Smoke Test', async ({ page }) => {
174
250
  await page.goto('https://playwright.dev');
175
251
  await expect(page).toHaveTitle(/Playwright/);
176
252
  });`;
177
253
  fs.writeFileSync(path.join(projectPath, 'src/tests/sample.spec.ts'), sampleTest);
178
254
 
179
- fs.writeFileSync(path.join(projectPath, 'src/i18n/en.json'), JSON.stringify({ "welcome": "Hello" }, null, 2));
180
-
181
- const tsConfig = { compilerOptions: { target: 'ES2020', module: 'commonjs', lib: ['ES2020'], strict: true, esModuleInterop: true, skipLibCheck: true, resolveJsonModule: true }, include: ['src/**/*'] };
255
+ const tsConfig = {
256
+ compilerOptions: {
257
+ target: 'ES2020',
258
+ module: 'commonjs',
259
+ lib: ['ES2020'],
260
+ strict: true,
261
+ esModuleInterop: true,
262
+ skipLibCheck: true,
263
+ resolveJsonModule: true
264
+ },
265
+ include: ['src/**/*']
266
+ };
182
267
  fs.writeFileSync(path.join(projectPath, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
183
268
 
184
269
  const gitignore = `node_modules/
185
270
  allure-results/
186
271
  allure-report/
272
+ test-results/
273
+ playwright-report/
187
274
  .env
188
275
  *.log
276
+ dist/
189
277
  `;
190
278
  fs.writeFileSync(path.join(projectPath, '.gitignore'), gitignore);
191
279
 
192
- console.log('āœ… Project structure created');
280
+ const readme = `# ${projectName}
281
+
282
+ ## Overview
283
+ Enterprise automation test project powered by **@sridharkikkeri/playwright-common**.
284
+
285
+ ## Getting Started
286
+ \`\`\`bash
287
+ npm install
288
+ npm run test:dev
289
+ \`\`\`
290
+
291
+ ## Features
292
+ - **Self-Healing**: Enabled by default
293
+ - **Visual Regression**: \`npm run test:visual\`
294
+ - **Enterprise Reporting**: Allure integration
295
+ `;
296
+ fs.writeFileSync(path.join(projectPath, 'README.md'), readme);
297
+
298
+ console.log('āœ… Comprehensive Project Structure Created');
193
299
  console.log('\nšŸ“¦ Installing dependencies...\n');
194
300
 
195
301
  try {
196
302
  execSync('npm install', { cwd: projectPath, stdio: 'inherit' });
197
303
  console.log('\nāœ… Dependencies installed');
198
- } catch (error) { console.log('\nāš ļø Run "npm install" manually'); }
304
+ } catch (error) {
305
+ console.log('\nāš ļø npm install failed. Please run manually.');
306
+ }
199
307
 
200
- console.log(`\nšŸŽ‰ Project ready! cd ${projectName} and npm run test:dev\n`);
308
+ console.log(`\nšŸŽ‰ Project ready! cd ${projectName} and try: 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.16",
3
+ "version": "1.0.17",
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",