@sridharkikkeri/playwright-common 1.0.5 → 1.0.12

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.
@@ -11,23 +11,38 @@ console.log(`\nšŸš€ Creating HealthEdge Playwright project: ${projectName}\n`);
11
11
 
12
12
  // Create project structure
13
13
  const dirs = [
14
+ 'src/core/api',
15
+ 'src/core/config',
16
+ 'src/core/i18n',
17
+ 'src/core/pages',
18
+ 'src/core/reporting',
19
+ 'src/core/selfhealing',
20
+ 'src/core/utils',
21
+ 'src/core/visual',
22
+ 'src/core/wrappers',
14
23
  'src/pages',
15
24
  'src/tests',
16
25
  'src/fixtures',
17
26
  'src/i18n',
18
27
  'src/utils',
19
28
  'allure-results',
20
- 'allure-report'
29
+ 'allure-report',
30
+ 'api-docs/assets',
31
+ 'api-docs/classes',
32
+ 'api-docs/interfaces',
33
+ 'api-docs/types',
34
+ 'api-docs/variables'
21
35
  ];
22
36
 
23
- dirs.forEach(dir => {
24
- fs.mkdirSync(path.join(projectPath, dir), { recursive: true });
37
+ dirs.forEach(idr => {
38
+ fs.mkdirSync(path.join(projectPath, idr), { recursive: true });
25
39
  });
26
40
 
27
41
  // package.json
28
42
  const packageJson = {
29
43
  name: projectName,
30
44
  version: '1.0.0',
45
+ description: 'HealthEdge Playwright Test Project',
31
46
  scripts: {
32
47
  'test': 'playwright test',
33
48
  'test:dev': 'TEST_ENV=dev playwright test',
@@ -40,7 +55,7 @@ const packageJson = {
40
55
  'lint:fix': 'eslint . --fix'
41
56
  },
42
57
  dependencies: {
43
- '@sridharkikkeri/playwright-common': '^1.0.5',
58
+ '@sridharkikkeri/playwright-common': '^1.0.12',
44
59
  '@playwright/test': '^1.42.0',
45
60
  'allure-playwright': '^3.4.5'
46
61
  },
@@ -52,182 +67,120 @@ const packageJson = {
52
67
  }
53
68
  };
54
69
 
55
- fs.writeFileSync(
56
- path.join(projectPath, 'package.json'),
57
- JSON.stringify(packageJson, null, 2)
58
- );
70
+ fs.writeFileSync(path.join(projectPath, 'package.json'), JSON.stringify(packageJson, null, 2));
59
71
 
60
- // playwright.config.ts
61
- const playwrightConfig = `import { defineConfig } from '@playwright/test';
62
-
63
- export default defineConfig({
64
- testDir: './src/tests',
65
- timeout: 30000,
66
- retries: process.env.CI ? 2 : 0,
67
- workers: process.env.CI ? 1 : undefined,
68
- reporter: [
69
- ['html'],
70
- ['allure-playwright', { outputFolder: 'allure-results' }]
71
- ],
72
- use: {
73
- baseURL: process.env.BASE_URL || 'https://example.com',
74
- trace: 'on-first-retry',
75
- screenshot: 'only-on-failure',
76
- },
77
- });
78
- `;
72
+ // --- CORE BOILERPLATE FILES ---
79
73
 
80
- fs.writeFileSync(path.join(projectPath, 'playwright.config.ts'), playwrightConfig);
74
+ // src/core/api/BaseApiClient.ts
75
+ const baseApiClientTs = `import { ApiClient } from '@sridharkikkeri/playwright-common';
81
76
 
82
- // framework.config.dev.json
83
- const devConfig = {
84
- healingEnabled: true,
85
- environment: 'dev',
86
- baseUrl: 'https://dev.example.com',
87
- apiUrl: 'https://api-dev.example.com',
88
- timeout: 30000,
89
- retries: 2
90
- };
91
-
92
- fs.writeFileSync(
93
- path.join(projectPath, 'framework.config.dev.json'),
94
- JSON.stringify(devConfig, null, 2)
95
- );
77
+ /**
78
+ * Project-specific Base API Client.
79
+ * Extend this to add custom headers or shared error handling for your app.
80
+ */
81
+ export class BaseApiClient extends ApiClient {
82
+ constructor(baseUrl: string) {
83
+ super(baseUrl);
84
+ }
85
+ }
86
+ `;
87
+ fs.writeFileSync(path.join(projectPath, 'src/core/api/BaseApiClient.ts'), baseApiClientTs);
96
88
 
97
- // New: src/fixtures/fixtures.ts
98
- const fixturesTs = `import { test as base } from '@sridharkikkeri/playwright-common';
99
- import { HomePage } from '../pages/HomePage';
89
+ // src/core/pages/BaseComponent.ts
90
+ const baseComponentTs = `import { Page } from '@playwright/test';
91
+ import { BasePage, ActionOrchestrator } from '@sridharkikkeri/playwright-common';
100
92
 
101
93
  /**
102
- * Extended test object for your project.
103
- * Add your project-specific Page Objects and fixtures here.
94
+ * Base Component for project-specific reusable UI elements (e.g., Modals, Navbars).
104
95
  */
105
- export const test = base.extend<{
106
- homePage: HomePage;
107
- }>({
108
- homePage: async ({ page, orchestrator }, use) => {
109
- await use(new HomePage(page, orchestrator));
110
- },
111
- });
96
+ export abstract class BaseComponent extends BasePage {
97
+ constructor(page: Page, orchestrator?: ActionOrchestrator) {
98
+ super(page, { pageName: 'BaseComponent', orchestrator });
99
+ }
100
+ }
101
+ `;
102
+ fs.writeFileSync(path.join(projectPath, 'src/core/pages/BaseComponent.ts'), baseComponentTs);
112
103
 
113
- export { expect } from '@playwright/test';
104
+ // src/core/utils/ProjectUtils.ts
105
+ const projectUtilsTs = `/**
106
+ * Shared utility functions for this specific test project.
107
+ */
108
+ export class ProjectUtils {
109
+ static async sleep(ms: number) {
110
+ return new Promise(resolve => setTimeout(resolve, ms));
111
+ }
112
+ }
114
113
  `;
114
+ fs.writeFileSync(path.join(projectPath, 'src/core/utils/ProjectUtils.ts'), projectUtilsTs);
115
+
116
+ // --- CONFIGURATION ---
117
+ const baseConfig = { healingEnabled: true, environment: 'dev', baseUrl: 'https://example.com', apiUrl: 'https://api.example.com', timeout: 30000, retries: 2 };
118
+ const environments = ['dev', 'qa', 'auto', 'staging', 'prod'];
119
+ environments.forEach(env => {
120
+ const config = { ...baseConfig, environment: env, baseUrl: \`https://\${env}.example.com\`, apiUrl: \`https://api-\${env}.example.com\` };
121
+ fs.writeFileSync(path.join(projectPath, \`framework.config.\${env}.json\`), JSON.stringify(config, null, 2));
122
+ });
123
+ fs.writeFileSync(path.join(projectPath, 'framework.config.json'), JSON.stringify(baseConfig, null, 2));
115
124
 
125
+ // playwright.config.ts
126
+ const playwrightConfig = `import { defineConfig } from '@playwright/test';
127
+ export default defineConfig({
128
+ testDir: './src/tests',
129
+ timeout: 30000,
130
+ retries: process.env.CI ? 2 : 0,
131
+ workers: process.env.CI ? 1 : undefined,
132
+ reporter: [['html'], ['allure-playwright', { outputFolder: 'allure-results' }]],
133
+ use: { trace: 'on-first-retry', screenshot: 'only-on-failure' }
134
+ }); `;
135
+ fs.writeFileSync(path.join(projectPath, 'playwright.config.ts'), playwrightConfig);
136
+
137
+ // src/fixtures/fixtures.ts
138
+ const fixturesTs = `import { test as base } from '@sridharkikkeri/playwright-common';
139
+ import { HomePage } from '../pages/HomePage';
140
+ export const test = base.extend < { homePage: HomePage } > ({
141
+ homePage: async ({ page, orchestrator }, use) => { await use(new HomePage(page, orchestrator)); },
142
+ });
143
+ export { expect } from '@playwright/test'; `;
116
144
  fs.writeFileSync(path.join(projectPath, 'src/fixtures/fixtures.ts'), fixturesTs);
117
145
 
118
146
  // Sample Page Object
119
147
  const samplePage = `import { Page } from '@playwright/test';
120
- import { BasePage, ActionOrchestrator } from '@sridharkikkeri/playwright-common';
121
-
122
- export class HomePage extends BasePage {
123
- constructor(page: Page, orchestrator?: ActionOrchestrator) {
124
- super(page, { pageName: 'HomePage', orchestrator });
125
- }
126
-
127
- private readonly searchInput = this.element('[data-testid="search"]');
128
- private readonly searchBtn = this.element('button[type="submit"]');
129
-
130
- async search(query: string) {
131
- await this.searchInput.fill(query, 'Enter search query');
132
- await this.searchBtn.click('Click search button');
148
+ import { BasePage, ActionOrchestrator } from '@sridharkikkeri/playwright-common';
149
+ export class HomePage extends BasePage {
150
+ constructor(page: Page, orchestrator?: ActionOrchestrator) { super(page, { pageName: 'HomePage', orchestrator }); }
151
+ private readonly searchInput = this.element('[data-testid="search"]');
152
+ private readonly searchBtn = this.element('button[type="submit"]');
153
+ async search(query: string) {
154
+ await this.searchInput.fill(query, 'Enter search query');
155
+ await this.searchBtn.click('Click search button');
156
+ }
133
157
  }
134
- }
135
- `;
136
-
158
+ `;
137
159
  fs.writeFileSync(path.join(projectPath, 'src/pages/HomePage.ts'), samplePage);
138
160
 
139
161
  // Sample Test
140
162
  const sampleTest = `import { test, expect } from '../fixtures/fixtures';
141
-
142
- test.describe('HealthEdge Framework Demo', () => {
143
- test('Search functionality with Fixtures', async ({ page, homePage }) => {
144
- await page.goto('https://playwright.dev');
145
-
146
- // Using the injected homePage fixture
147
- await homePage.search('playwright');
148
-
149
- await expect(page).toHaveTitle(/Playwright/);
150
- });
151
- });
152
- `;
153
-
163
+ test.describe('HealthEdge Framework Demo', () => {
164
+ test('Search functionality with Fixtures', async ({ page, homePage }) => {
165
+ await page.goto('https://playwright.dev');
166
+ await homePage.search('playwright');
167
+ await expect(page).toHaveTitle(/Playwright/);
168
+ });
169
+ }); `;
154
170
  fs.writeFileSync(path.join(projectPath, 'src/tests/sample.spec.ts'), sampleTest);
155
171
 
156
- // Sample i18n file
157
- const sampleI18n = {
158
- "login_welcome": "Welcome to HealthEdge"
159
- };
172
+ const sampleI18n = { "login_welcome": "Welcome to HealthEdge" };
160
173
  fs.writeFileSync(path.join(projectPath, 'src/i18n/en.json'), JSON.stringify(sampleI18n, null, 2));
161
174
 
162
- // tsconfig.json
163
175
  const tsConfig = {
164
- compilerOptions: {
165
- target: 'ES2020',
166
- module: 'commonjs',
167
- lib: ['ES2020'],
168
- strict: true,
169
- esModuleInterop: true,
170
- skipLibCheck: true,
171
- forceConsistentCasingInFileNames: true,
172
- resolveJsonModule: true
173
- },
176
+ compilerOptions: { target: 'ES2020', module: 'commonjs', lib: ['ES2020'], strict: true, esModuleInterop: true, skipLibCheck: true, forceConsistentCasingInFileNames: true, resolveJsonModule: true },
174
177
  include: ['src/**/*']
175
178
  };
179
+ fs.writeFileSync(path.join(projectPath, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
176
180
 
177
- fs.writeFileSync(
178
- path.join(projectPath, 'tsconfig.json'),
179
- JSON.stringify(tsConfig, null, 2)
180
- );
181
-
182
- // .gitignore
183
- const gitignore = `node_modules/
184
- allure-results/
185
- allure-report/
186
- test-results/
187
- playwright-report/
188
- .env
189
- *.log
190
- `;
191
-
181
+ const gitignore = `node_modules /\nallure - results /\nallure - report /\ntest - results /\nplaywright - report /\n.env\n *.log\n`;
192
182
  fs.writeFileSync(path.join(projectPath, '.gitignore'), gitignore);
193
183
 
194
- // README
195
- const readme = `# ${projectName}
196
-
197
- Generated with \`npx create-healthedge-tests\`
198
-
199
- ## Quick Start
200
-
201
- \`\`\`bash
202
- npm install
203
- npm run test:dev
204
- npm run report
205
- \`\`\`
206
-
207
- ## Key Concepts
208
-
209
- ### Fixtures
210
- This project uses an extended \`test\` object defined in \`src/fixtures/fixtures.ts\`.
211
- Instead of importing from \`@playwright/test\`, always import from your local fixtures:
212
-
213
- \`\`\`typescript
214
- import { test } from '../fixtures/fixtures';
215
- \`\`\`
216
-
217
- ### Page Objects
218
- Add your pages to \`src/pages\` and register them in \`src/fixtures/fixtures.ts\`.
219
-
220
- ## Environment-Specific Tests
221
-
222
- \`\`\`bash
223
- npm run test:dev # Uses framework.config.dev.json
224
- npm run test:staging # Uses framework.config.staging.json
225
- npm run test:prod # Uses framework.config.prod.json
226
- \`\`\`
227
- `;
228
-
229
- fs.writeFileSync(path.join(projectPath, 'README.md'), readme);
230
-
231
184
  console.log('āœ… Project structure created');
232
185
  console.log('\nšŸ“¦ Installing dependencies...\n');
233
186
 
@@ -238,6 +191,6 @@ try {
238
191
  console.log('\nāš ļø Run "npm install" manually in the project directory');
239
192
  }
240
193
 
241
- console.log(`\nšŸŽ‰ Project ready! Next steps:\n`);
242
- console.log(` cd ${projectName}`);
243
- console.log(` npm run test:dev\n`);
194
+ console.log(`\nšŸŽ‰ Project ready! Next steps: \n`);
195
+ console.log(` cd \${ projectName } `);
196
+ 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.5",
3
+ "version": "1.0.12",
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",