@testsmith/testblocks 0.9.8 → 0.9.9
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/dist/cli/executor.d.ts +15 -0
- package/dist/cli/executor.js +25 -4
- package/dist/cli/index.js +39 -1
- package/dist/client/assets/{index-CYoJ_6bl.js → index-CSdQPHwK.js} +84 -84
- package/dist/client/assets/{index-CYoJ_6bl.js.map → index-CSdQPHwK.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/server/startServer.js +50 -0
- package/package.json +1 -1
package/dist/cli/executor.d.ts
CHANGED
|
@@ -6,6 +6,21 @@ export interface ExecutorOptions {
|
|
|
6
6
|
variables?: Record<string, unknown>;
|
|
7
7
|
plugins?: Plugin[];
|
|
8
8
|
procedures?: Record<string, ProcedureDefinition>;
|
|
9
|
+
testIdAttribute?: string;
|
|
10
|
+
locale?: string;
|
|
11
|
+
timezoneId?: string;
|
|
12
|
+
geolocation?: {
|
|
13
|
+
latitude: number;
|
|
14
|
+
longitude: number;
|
|
15
|
+
};
|
|
16
|
+
viewport?: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
localStorage?: {
|
|
21
|
+
name: string;
|
|
22
|
+
value: string;
|
|
23
|
+
}[];
|
|
9
24
|
}
|
|
10
25
|
export declare class TestExecutor {
|
|
11
26
|
private options;
|
package/dist/cli/executor.js
CHANGED
|
@@ -29,13 +29,34 @@ class TestExecutor {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
async initialize() {
|
|
32
|
+
if (this.options.testIdAttribute) {
|
|
33
|
+
playwright_1.selectors.setTestIdAttribute(this.options.testIdAttribute);
|
|
34
|
+
}
|
|
32
35
|
this.browser = await playwright_1.chromium.launch({
|
|
33
36
|
headless: this.options.headless,
|
|
34
37
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const contextOptions = {
|
|
39
|
+
viewport: this.options.viewport || { width: 1920, height: 1080 },
|
|
40
|
+
};
|
|
41
|
+
if (this.options.locale) {
|
|
42
|
+
contextOptions.locale = this.options.locale;
|
|
43
|
+
}
|
|
44
|
+
if (this.options.timezoneId) {
|
|
45
|
+
contextOptions.timezoneId = this.options.timezoneId;
|
|
46
|
+
}
|
|
47
|
+
if (this.options.geolocation) {
|
|
48
|
+
contextOptions.geolocation = this.options.geolocation;
|
|
49
|
+
contextOptions.permissions = ['geolocation'];
|
|
50
|
+
}
|
|
51
|
+
this.browserContext = await this.browser.newContext(contextOptions);
|
|
52
|
+
if (this.options.localStorage && this.options.localStorage.length > 0) {
|
|
53
|
+
const items = this.options.localStorage;
|
|
54
|
+
await this.browserContext.addInitScript((storageItems) => {
|
|
55
|
+
for (const item of storageItems) {
|
|
56
|
+
localStorage.setItem(item.name, item.value);
|
|
57
|
+
}
|
|
58
|
+
}, items);
|
|
59
|
+
}
|
|
39
60
|
this.page = await this.browserContext.newPage();
|
|
40
61
|
if (this.options.timeout) {
|
|
41
62
|
this.page.setDefaultTimeout(this.options.timeout);
|
package/dist/cli/index.js
CHANGED
|
@@ -209,6 +209,7 @@ program
|
|
|
209
209
|
globalsPath = findGlobalsFile(testDir) || globalsPath;
|
|
210
210
|
}
|
|
211
211
|
let globalTimeout;
|
|
212
|
+
let globalBrowserConfig;
|
|
212
213
|
if (fs.existsSync(globalsPath)) {
|
|
213
214
|
try {
|
|
214
215
|
const globalsContent = fs.readFileSync(globalsPath, 'utf-8');
|
|
@@ -222,6 +223,9 @@ program
|
|
|
222
223
|
if (typeof globals.timeout === 'number') {
|
|
223
224
|
globalTimeout = globals.timeout;
|
|
224
225
|
}
|
|
226
|
+
if (globals.browserConfig && typeof globals.browserConfig === 'object') {
|
|
227
|
+
globalBrowserConfig = globals.browserConfig;
|
|
228
|
+
}
|
|
225
229
|
}
|
|
226
230
|
catch (e) {
|
|
227
231
|
console.warn(`Warning: Could not load globals from ${globalsPath}: ${e.message}`);
|
|
@@ -286,6 +290,40 @@ program
|
|
|
286
290
|
variables,
|
|
287
291
|
procedures: globalProcedures,
|
|
288
292
|
};
|
|
293
|
+
// Apply browser config from globals.json
|
|
294
|
+
if (globalBrowserConfig) {
|
|
295
|
+
if (globalBrowserConfig.testIdAttribute) {
|
|
296
|
+
executorOptions.testIdAttribute = globalBrowserConfig.testIdAttribute;
|
|
297
|
+
}
|
|
298
|
+
if (globalBrowserConfig.locale) {
|
|
299
|
+
executorOptions.locale = globalBrowserConfig.locale;
|
|
300
|
+
}
|
|
301
|
+
if (globalBrowserConfig.timezoneId) {
|
|
302
|
+
executorOptions.timezoneId = globalBrowserConfig.timezoneId;
|
|
303
|
+
}
|
|
304
|
+
const geo = globalBrowserConfig.geolocation;
|
|
305
|
+
if (geo?.latitude && geo?.longitude) {
|
|
306
|
+
executorOptions.geolocation = {
|
|
307
|
+
latitude: parseFloat(geo.latitude),
|
|
308
|
+
longitude: parseFloat(geo.longitude),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const vp = globalBrowserConfig.viewport;
|
|
312
|
+
if (vp?.width && vp?.height) {
|
|
313
|
+
executorOptions.viewport = {
|
|
314
|
+
width: parseInt(vp.width, 10),
|
|
315
|
+
height: parseInt(vp.height, 10),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
const ls = globalBrowserConfig.localStorage;
|
|
319
|
+
if (Array.isArray(ls) && ls.length > 0) {
|
|
320
|
+
executorOptions.localStorage = ls;
|
|
321
|
+
}
|
|
322
|
+
// --headed CLI flag overrides globals.json headless setting
|
|
323
|
+
if (!options.headed && globalBrowserConfig.headless === false) {
|
|
324
|
+
executorOptions.headless = false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
289
327
|
// Create reporters (supports multiple, comma-separated)
|
|
290
328
|
const reporters = createReporters(options.reporter, options.output);
|
|
291
329
|
// Run tests
|
|
@@ -454,7 +492,7 @@ program
|
|
|
454
492
|
'test:ci': 'testblocks run tests/**/*.testblocks.json -r console,html,junit -o reports',
|
|
455
493
|
},
|
|
456
494
|
devDependencies: {
|
|
457
|
-
'@testsmith/testblocks': '^0.9.
|
|
495
|
+
'@testsmith/testblocks': '^0.9.9',
|
|
458
496
|
},
|
|
459
497
|
};
|
|
460
498
|
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
|