@zohodesk/testinglibrary 0.0.2 → 0.0.4

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/changelog.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Framework that abstracts the configuration for playwright and Jest
4
4
 
5
+ # 0.0.4
6
+
7
+ - Issue Fixes while loading the storage state
8
+
9
+ # 0.0.3
10
+
11
+ - Added Support for custom config generator based on user preferences
12
+
5
13
  # 0.0.2
6
14
 
7
15
  - Fix for Finding directories inside node_modules folder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -28,4 +28,4 @@
28
28
  "bin": {
29
29
  "ZDTestingFramework": "./bin/cli.js"
30
30
  }
31
- }
31
+ }
@@ -1,7 +1,7 @@
1
1
  const { existsSync } = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const fileName = 'test.config.js';
4
+ const fileName = 'uat.config.js';
5
5
 
6
6
  function generateConfigFromFile() {
7
7
  const filePath = path.resolve(process.cwd(), fileName);
@@ -14,5 +14,17 @@ function generateConfigFromFile() {
14
14
  return {};
15
15
  }
16
16
 
17
+ function isUserConfigFileAvailable() {
18
+ const filePath = path.resolve(process.cwd(), fileName);
19
+ if (existsSync(filePath)) {
20
+ return true;
21
+ }
22
+ return false;
23
+ }
24
+
17
25
 
18
- module.exports = generateConfigFromFile;
26
+ module.exports = {
27
+ fileName,
28
+ isUserConfigFileAvailable,
29
+ generateConfigFromFile
30
+ };
@@ -0,0 +1,77 @@
1
+ // @ts-check
2
+ const { defineConfig, devices } = require('@playwright/test');
3
+ const path = require('path');
4
+ const { generateConfigFromFile } = require('../readConfigFile');
5
+ const numCPUs = require('os').cpus().length;
6
+
7
+ const defaultBrowser = ['Chrome']
8
+
9
+ const { browsers = defaultBrowser, isAuthMode, trace = false, video = false } = generateConfigFromFile();
10
+
11
+
12
+ let projects = browsers.map(browser => {
13
+ if (browser === 'Chrome') {
14
+ return {
15
+ name: 'chromium',
16
+ use: {
17
+ ...devices['Desktop Chrome'],
18
+ storageState: isAuthMode ? path.resolve(process.cwd(), 'playwright/.auth/user.json') : {}
19
+ },
20
+ dependencies: isAuthMode ? ['setup'] : [],
21
+ };
22
+ } else if (browser === 'Firefox') {
23
+ return {
24
+ name: 'firefox',
25
+ timeout: 4 * 60 * 1000,
26
+ expect: {
27
+ timeout: 80 * 1000,
28
+ },
29
+ use: {
30
+ ...devices['Desktop Firefox'],
31
+ storageState: isAuthMode ? path.resolve(process.cwd(), 'playwright/.auth/user.json') : {}
32
+ },
33
+ dependencies: isAuthMode ? ['setup'] : [],
34
+ };
35
+ } else if (browser === 'safari') {
36
+ return {
37
+ name: 'webkit',
38
+ timeout: 2 * 60 * 1000,
39
+ expect: {
40
+ timeout: 80 * 1000,
41
+ },
42
+ use: {
43
+ ...devices['Desktop Safari'],
44
+ storageState: isAuthMode ? path.resolve(process.cwd(), 'playwright/.auth/user.json') : {}
45
+ },
46
+ dependencies: isAuthMode ? ['setup'] : null,
47
+ }
48
+ }
49
+ }).filter(Boolean);
50
+
51
+ module.exports = defineConfig({
52
+ testDir: path.join(path.resolve(process.cwd()), 'uat'),
53
+ outputDir: path.join(process.cwd(), 'test-results'),
54
+ fullyParallel: true,
55
+ forbidOnly: !!process.env.CI,
56
+ retries: process.env.CI ? 2 : 0,
57
+ workers: process.env.CI ? 1 : 1,
58
+ reporter: [['html', { outputFolder: path.join(process.cwd(), 'playwright-report'), open: "always" }]],
59
+ timeout: 60 * 1000,
60
+ expect: {
61
+ timeout: 5 * 1000,
62
+ },
63
+
64
+ use: {
65
+ trace: trace ? 'on' : 'off',
66
+ video: video ? {
67
+ mode: 'on',
68
+ size: { width: 640, height: 480 }
69
+ } : 'off'
70
+ },
71
+
72
+ projects: isAuthMode ? [
73
+ { name: 'setup', testMatch: /.*\.setup\.js/ },
74
+ ...projects
75
+ ] : [...projects]
76
+ });
77
+
@@ -4,8 +4,7 @@ const { CUSTOM_COMMANDS } = require('./custom-commands');
4
4
  const { cliArgsToObject, objectToCliArgs } = require('../../utils/cliArgsToObject');
5
5
  const { initializeEnvConfig } = require('./env-initializer');
6
6
  const { Logger } = require('../../utils/logger');
7
- const getFilePathWithExtension = require('../../utils/getFilePath');
8
- const generateConfigFromFile = require('./readConfigFile');
7
+ const { isUserConfigFileAvailable } = require('./readConfigFile');
9
8
  const { getExecutableBinaryPath } = require('../../utils/rootPath');
10
9
 
11
10
 
@@ -15,11 +14,9 @@ const userArgs = process.argv.slice(2);
15
14
 
16
15
  const userArgsObject = cliArgsToObject(userArgs);
17
16
 
18
- initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : 'dev');
19
-
20
-
21
- generateConfigFromFile();
22
17
 
18
+ // Environment variables Initialization
19
+ initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : 'dev');
23
20
 
24
21
 
25
22
  const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS.includes(key));
@@ -28,7 +25,10 @@ const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS
28
25
  const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
29
26
 
30
27
  const command = playwrightPath;
31
- const args = ['test', '--config', require.resolve('../../../playwright.config.js')].concat(playwrightArgs);
28
+
29
+ const configPath = isUserConfigFileAvailable() ? require.resolve('./setup/config-creator.js') : require.resolve('../../../playwright.config.js');
30
+
31
+ const args = ['test', '--config', configPath].concat(playwrightArgs);
32
32
 
33
33
 
34
34
  function createTestRunner() {