@zohodesk/testinglibrary 0.0.3 → 0.0.5

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.
@@ -1,30 +1,63 @@
1
- const { existsSync } = require('fs');
2
- const path = require('path');
3
-
4
- const fileName = 'uat.config.js';
5
-
6
- function generateConfigFromFile() {
7
- const filePath = path.resolve(process.cwd(), fileName);
8
-
9
- if (existsSync(filePath)) {
10
- const config = require(filePath);
11
- return config;
12
- }
13
-
14
- return {};
15
- }
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
-
25
-
26
- module.exports = {
27
- fileName,
28
- isUserConfigFileAvailable,
29
- generateConfigFromFile
1
+ const { existsSync } = require('fs');
2
+ const path = require('path');
3
+ const { Logger } = require('../../utils/logger');
4
+
5
+ const fileName = 'uat.config.js';
6
+
7
+ /**
8
+ * Represents the user configuration object.
9
+ * @typedef {Object} UserConfig
10
+ * @property {string} headless - Headless Browsers mode.
11
+ * @property {number} trace - trace for test cases.
12
+ * @property {boolean} video - video for test cases,
13
+ * @property {boolean} debug - debug mode
14
+ * @property {string} mode: mode in which the test cases needs to run
15
+ * @property {boolean} isAuthMode - Auth Mode
16
+ * @property {any} browsers: List of browsers
17
+ * @property {string} openReportOn: default Option value (never, on-failure and always)
18
+ * @property {any} reportPath : directory where report is generate
19
+ */
20
+
21
+
22
+ /**
23
+ * Generates a configuration object from a file, if it exists.
24
+ *
25
+ * @returns {UserConfig}
26
+ */
27
+ function generateConfigFromFile() {
28
+ const filePath = path.resolve(process.cwd(), fileName);
29
+
30
+ if (existsSync(filePath)) {
31
+ /** @type {UserConfig} */
32
+ const config = require(filePath);
33
+ return config;
34
+ }
35
+
36
+ return {};
37
+ }
38
+
39
+ function isUserConfigFileAvailable() {
40
+ const filePath = path.resolve(process.cwd(), fileName);
41
+ if (existsSync(filePath)) {
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+
47
+ function getAuthFilePath(filePath){
48
+ try{
49
+ if(existsSync(filePath)){
50
+ return filePath
51
+ }
52
+ }catch(err){
53
+ Logger.log(Logger.FAILURE_TYPE,`Founded Path - ${filePath} Authetication file not Exist ...`)
54
+ }
55
+
56
+ }
57
+
58
+ module.exports = {
59
+ fileName,
60
+ isUserConfigFileAvailable,
61
+ generateConfigFromFile,
62
+ getAuthFilePath
30
63
  };
@@ -1,43 +1,45 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
3
- const { Logger } = require('../../utils/logger');
4
- const { getExecutableBinaryPath } = require('../../utils/rootPath');
5
-
6
-
7
- const userArgs = process.argv.slice(3);
8
-
9
- const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));;
10
- const command = playwrightPath;
11
- const reportPath = path.resolve(process.cwd(), './playwright-report');
12
-
13
-
14
- const args = ['show-report', reportPath].concat(userArgs);
15
-
16
- function generateReport() {
17
- const childProcess = spawn(command, args, { stdio: 'inherit' });
18
- childProcess.on('error', (error) => {
19
- Logger.log(Logger.FAILURE_TYPE, error);
20
- })
21
-
22
- childProcess.on('exit', (code, signal) => {
23
- Logger.log(Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
24
-
25
- process.exit();
26
- });
27
-
28
- process.on('exit', () => {
29
- Logger.log(Logger.INFO_TYPE, 'Terminating Playwright Process...');
30
- childProcess.kill();
31
- return;
32
- });
33
-
34
- process.on('SIGINT', () => {
35
- Logger.log(Logger.INFO_TYPE, 'Cleaning up...');
36
- childProcess.kill();
37
- process.exit();
38
-
39
- });
40
- }
41
-
42
-
1
+ const { spawn } = require('child_process');
2
+ const path = require('path');
3
+ const { Logger } = require('../../utils/logger');
4
+ const { getExecutableBinaryPath } = require('../../utils/rootPath');
5
+ const { generateConfigFromFile } = require('./readConfigFile');
6
+
7
+
8
+ const userArgs = process.argv.slice(3);
9
+
10
+ const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));;
11
+ const command = playwrightPath;
12
+ const { reportPath : htmlPath = path.resolve(process.cwd(), './playwright-report') } = generateConfigFromFile()
13
+ const reportPath = htmlPath
14
+
15
+
16
+ const args = ['show-report', htmlPath].concat(userArgs);
17
+
18
+ function generateReport() {
19
+ const childProcess = spawn(command, args, { stdio: 'inherit' });
20
+ childProcess.on('error', (error) => {
21
+ Logger.log(Logger.FAILURE_TYPE, error);
22
+ })
23
+
24
+ childProcess.on('exit', (code, signal) => {
25
+ Logger.log(Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
26
+
27
+ process.exit();
28
+ });
29
+
30
+ process.on('exit', () => {
31
+ Logger.log(Logger.INFO_TYPE, 'Terminating Playwright Process...');
32
+ childProcess.kill();
33
+ return;
34
+ });
35
+
36
+ process.on('SIGINT', () => {
37
+ Logger.log(Logger.INFO_TYPE, 'Cleaning up...');
38
+ childProcess.kill();
39
+ process.exit();
40
+
41
+ });
42
+ }
43
+
44
+
43
45
  module.exports = generateReport;
@@ -1,79 +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') : null
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') : null
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') : null
45
- },
46
- dependencies: isAuthMode ? ['setup'] : null,
47
- }
48
- }
49
- }).filter(Boolean);
50
-
51
- console.log(projects);
52
-
53
- module.exports = defineConfig({
54
- testDir: path.join(path.resolve(process.cwd()), 'uat'),
55
- outputDir: path.join(process.cwd(), 'test-results'),
56
- fullyParallel: true,
57
- forbidOnly: !!process.env.CI,
58
- retries: process.env.CI ? 2 : 0,
59
- workers: process.env.CI ? 1 : 1,
60
- reporter: [['html', { outputFolder: path.join(process.cwd(), 'playwright-report'), open: "always" }]],
61
- timeout: 60 * 1000,
62
- expect: {
63
- timeout: 5 * 1000,
64
- },
65
-
66
- use: {
67
- trace: trace ? 'on' : 'off',
68
- video: video ? {
69
- mode: 'on',
70
- size: { width: 640, height: 480 }
71
- } : 'off'
72
- },
73
-
74
- projects: isAuthMode ? [
75
- { name: 'setup', testMatch: /.*\.setup\.js/ },
76
- ...projects
77
- ] : [...projects]
78
- });
79
-
1
+ // @ts-check
2
+ const { defineConfig, devices } = require('@playwright/test');
3
+ const path = require('path');
4
+ const { generateConfigFromFile, getAuthFilePath } = require('../readConfigFile');
5
+ const { existsSync } = require('fs');
6
+ const numCPUs = require('os').cpus().length;
7
+
8
+ const defaultBrowser = ['Chrome']
9
+
10
+ const { browsers = defaultBrowser, trace = false, video = false, isAuthMode, openReportOn, reportPath = path.join(process.cwd(), 'playwright-report') } = generateConfigFromFile();
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 ? getAuthFilePath(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 ? getAuthFilePath(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 ? getAuthFilePath(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: reportPath, open: openReportOn }]],
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
+
@@ -1,64 +1,67 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
3
- const { CUSTOM_COMMANDS } = require('./custom-commands');
4
- const { cliArgsToObject, objectToCliArgs } = require('../../utils/cliArgsToObject');
5
- const { initializeEnvConfig } = require('./env-initializer');
6
- const { Logger } = require('../../utils/logger');
7
- const { isUserConfigFileAvailable } = require('./readConfigFile');
8
- const { getExecutableBinaryPath } = require('../../utils/rootPath');
9
-
10
-
11
-
12
- // Access the command line arguments
13
- const userArgs = process.argv.slice(2);
14
-
15
- const userArgsObject = cliArgsToObject(userArgs);
16
-
17
-
18
- // Environment variables Initialization
19
- initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : 'dev');
20
-
21
-
22
- const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS.includes(key));
23
-
24
- // Command and arguments for npx playwright test
25
- const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
26
-
27
- const command = playwrightPath;
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
-
33
-
34
- function createTestRunner() {
35
- // Spawn the child process
36
-
37
- const childProcess = spawn(command, args, { stdio: 'inherit' });
38
-
39
- childProcess.on('error', (error) => {
40
- Logger.log(Logger.FAILURE_TYPE, error);
41
- })
42
-
43
- childProcess.on('exit', (code, signal) => {
44
- Logger.log(Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
45
-
46
- process.exit();
47
- });
48
-
49
- process.on('exit', () => {
50
- Logger.log(Logger.INFO_TYPE, 'Terminating Playwright Process...');
51
- //childProcess.kill();
52
- return;
53
- });
54
-
55
- process.on('SIGINT', () => {
56
- Logger.log(Logger.INFO_TYPE, 'Cleaning up...');
57
- //childProcess.kill();
58
- process.exit();
59
-
60
- });
61
- }
62
-
63
-
64
- module.exports = createTestRunner;
1
+ const { spawn } = require('child_process');
2
+ const path = require('path');
3
+ const { CUSTOM_COMMANDS } = require('./custom-commands');
4
+ const { cliArgsToObject, objectToCliArgs } = require('../../utils/cliArgsToObject');
5
+ const { initializeEnvConfig } = require('./env-initializer');
6
+ const { Logger } = require('../../utils/logger');
7
+ const { isUserConfigFileAvailable, generateConfigFromFile } = require('./readConfigFile');
8
+ const { getExecutableBinaryPath } = require('../../utils/rootPath');
9
+
10
+
11
+ function createTestRunner() {
12
+ // Access the command line arguments
13
+ const userArgs = process.argv.slice(2);
14
+
15
+ const userArgsObject = cliArgsToObject(userArgs);
16
+
17
+
18
+ const { debug, mode = 'dev' } = generateConfigFromFile();
19
+
20
+ // Environment variables Initialization
21
+ initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : mode);
22
+
23
+
24
+ const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS.includes(key));
25
+
26
+ if (debug) {
27
+ playwrightArgs.push('--debug')
28
+ }
29
+
30
+ // Command and arguments for npx playwright test
31
+ const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
32
+
33
+ const command = playwrightPath;
34
+
35
+ const configPath = isUserConfigFileAvailable() ? require.resolve('./setup/config-creator.js') : require.resolve('../../../playwright.config.js');
36
+
37
+ const args = ['test', '--config', configPath].concat(playwrightArgs);
38
+ // Spawn the child process
39
+
40
+ const childProcess = spawn(command, args, { stdio: 'inherit' });
41
+
42
+ childProcess.on('error', (error) => {
43
+ Logger.log(Logger.FAILURE_TYPE, error);
44
+ })
45
+
46
+ childProcess.on('exit', (code, signal) => {
47
+ Logger.log(Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
48
+
49
+ process.exit();
50
+ });
51
+
52
+ process.on('exit', () => {
53
+ Logger.log(Logger.INFO_TYPE, 'Terminating Playwright Process...');
54
+ //childProcess.kill();
55
+ return;
56
+ });
57
+
58
+ process.on('SIGINT', () => {
59
+ Logger.log(Logger.INFO_TYPE, 'Cleaning up...');
60
+ //childProcess.kill();
61
+ process.exit();
62
+
63
+ });
64
+ }
65
+
66
+
67
+ module.exports = createTestRunner;
package/src/index.js CHANGED
@@ -1,9 +1,9 @@
1
- const { expect, test } = require('./core/playwright/index');
2
- const { fireEvent, render } = require('@testing-library/react');
3
-
4
- module.exports = {
5
- expect,
6
- test,
7
- fireEvent,
8
- render
1
+ const { expect, test } = require('./core/playwright/index');
2
+ const { fireEvent, render } = require('@testing-library/react');
3
+
4
+ module.exports = {
5
+ expect,
6
+ test,
7
+ fireEvent,
8
+ render
9
9
  }
package/src/lib/cli.js CHANGED
@@ -1,35 +1,42 @@
1
- const createTestRunner = require("../core/playwright/test-runner");
2
- const createJestRunner = require('../core/jest/runner/jest-runner');
3
- const generateReport = require("../core/playwright/report-generator");
4
- const generateCodegen = require('../core/playwright/codegen')
5
- const { Logger } = require("../utils/logger");
6
-
7
- const [, , option] = process.argv;
8
- const args = process.argv.slice(3);
9
- const appPath = process.cwd();
10
-
11
-
12
- switch (option) {
13
- case 'test': {
14
- Logger.log(Logger.SUCCESS_TYPE, 'Running Tests..');
15
- createTestRunner();
16
- //createJestRunner();
17
- break;
18
- }
19
- case 'report': {
20
- // console.log('\x1b[36mGenerating Reports...\x1b[0m');
21
- Logger.log(Logger.SUCCESS_TYPE, 'Generating Reports...');
22
- generateReport();
23
- break;
24
- }
25
- case 'codegen': {
26
- Logger.log(Logger.INFO_TYPE, 'The purpose of codegen is to assist developer .....')
27
- generateCodegen();
28
- break;
29
- }
30
-
31
- default: {
32
- console.log('Supported Commands test and report')
33
- break;
34
- }
1
+ const createTestRunner = require("../core/playwright/test-runner");
2
+ const createJestRunner = require('../core/jest/runner/jest-runner');
3
+ const generateReport = require("../core/playwright/report-generator");
4
+ const generateCodegen = require('../core/playwright/codegen')
5
+ const { Logger } = require("../utils/logger");
6
+ const setupProject = require("../setup-folder-structure/setupProject");
7
+
8
+ const [, , option] = process.argv;
9
+ const args = process.argv.slice(3);
10
+ const appPath = process.cwd();
11
+
12
+
13
+ switch (option) {
14
+ case 'test': {
15
+ Logger.log(Logger.SUCCESS_TYPE, 'Running Tests..');
16
+ createTestRunner();
17
+ //createJestRunner();
18
+ break;
19
+ }
20
+ case 'report': {
21
+ // console.log('\x1b[36mGenerating Reports...\x1b[0m');
22
+ Logger.log(Logger.SUCCESS_TYPE, 'Generating Reports...');
23
+ generateReport();
24
+ break;
25
+ }
26
+ case 'codegen': {
27
+ Logger.log(Logger.INFO_TYPE, 'The purpose of codegen is to assist developer .....')
28
+ generateCodegen();
29
+ break;
30
+ }
31
+
32
+ case 'init': {
33
+ Logger.log(Logger.SUCCESS_TYPE, 'Initializing projects...');
34
+ setupProject();
35
+ break;
36
+ }
37
+
38
+ default: {
39
+ console.log('Supported Commands test and report')
40
+ break;
41
+ }
35
42
  }
@@ -0,0 +1,17 @@
1
+ {
2
+ "dev": {
3
+ "domain": "https://desk.localzoho.com/agent",
4
+ "username": "your-username",
5
+ "password": "your-password"
6
+ },
7
+ "prod": {
8
+ "domain": "https://desk.localzoho.com/agent",
9
+ "username": "your-username",
10
+ "password": "your-password"
11
+ },
12
+ "k8test": {
13
+ "domain": "https://desk.localzoho.com/agent",
14
+ "username": "your-username",
15
+ "password": "your-password"
16
+ }
17
+ }