@zohodesk/testinglibrary 0.0.1 → 0.0.3

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,81 +1,82 @@
1
- const { expect, test: base } = require('@playwright/test');
2
- // function test(descrition, callback) {
3
- // return test(descrition, ({ page }) => {
4
- // const { locator, ...custompage } = page
5
- // callback({ page: custompage })
6
- // })
7
- // }
8
-
9
- // class FilteredPage {
10
- // constructor(page) {
11
- // this.page = page;
12
- // this.allowedMethods = ['getByText', 'getByTitle'];
13
- // this.context = page.context;
14
- // }
15
-
16
- // goto(...args) {
17
- // return this.page['goto'](...args);
18
- // }
19
-
20
-
21
- // getByRole(...args) {
22
- // return this.page['getByRole'](...args);
23
- // }
24
- // }
25
-
26
-
27
- // function FilteredPage(page) {
28
- // return {
29
- // getByRole: () => {
30
- // throw new Error('You cannnot use getByRole property')
31
- // }
32
- // }
33
- // }
34
-
35
- const test = base.extend({
36
- page: async ({ baseURL, page }, use) => {
37
- // const proxyPage = new Proxy(page, {
38
- // get: function (obj, prop) {
39
- // console.log('Gettig Priop', prop);
40
- // let filterMethod = FilteredPage(page)[prop];
41
- // if (filterMethod) {
42
- // return filterMethod;
43
- // } else {
44
- // return obj[prop] ? obj[prop] : 'property does not exist';
45
- // }
46
- // }
47
- // })
48
- page.getBaseUrl = function () {
49
- if (process.env.mode === 'dev') {
50
- return `${process.env.domain}?devURL=${process.env.devUrl}`;
51
- }
52
- return `${process.env.domain}`;
53
- }
54
-
55
- page.getCustomPageUrl = function (url) {
56
- if (process.env.mode === 'dev') {
57
- return `${process.env.domain}/${url}?devURL=${process.env.devUrl}`
58
- }
59
- return `${process.env.domain}/${url}`
60
- }
61
- await use(page);
62
-
63
-
64
- //await use(new FilteredPage(page));
65
-
66
- // await use(async (page) => {
67
- // delete page.getByTestId;
68
- // await page;
69
- // });
70
-
71
- },
72
- context: async ({ context }, use) => {
73
- await context.addInitScript(() => window.localStorage.setItem('isDnBannerHide', true));
74
- await use(context);
75
- }
76
- })
77
-
78
- module.exports = {
79
- expect,
80
- test
1
+ const { expect, test: base } = require('@playwright/test');
2
+ // function test(descrition, callback) {
3
+ // return test(descrition, ({ page }) => {
4
+ // const { locator, ...custompage } = page
5
+ // callback({ page: custompage })
6
+ // })
7
+ // }
8
+
9
+ // class FilteredPage {
10
+ // constructor(page) {
11
+ // this.page = page;
12
+ // this.allowedMethods = ['getByText', 'getByTitle'];
13
+ // this.context = page.context;
14
+ // }
15
+
16
+ // goto(...args) {
17
+ // return this.page['goto'](...args);
18
+ // }
19
+
20
+
21
+ // getByRole(...args) {
22
+ // return this.page['getByRole'](...args);
23
+ // }
24
+ // }
25
+
26
+
27
+ // function FilteredPage(page) {
28
+ // return {
29
+ // getByRole: () => {
30
+ // throw new Error('You cannnot use getByRole property')
31
+ // }
32
+ // }
33
+ // }
34
+
35
+ const test = base.extend({
36
+ page: async ({ baseURL, page }, use) => {
37
+ // const proxyPage = new Proxy(page, {
38
+ // get: function (obj, prop) {
39
+ // console.log('Gettig Priop', prop);
40
+ // let filterMethod = FilteredPage(page)[prop];
41
+ // if (filterMethod) {
42
+ // return filterMethod;
43
+ // } else {
44
+ // return obj[prop] ? obj[prop] : 'property does not exist';
45
+ // }
46
+ // }
47
+ // })
48
+ page.getBaseUrl = function () {
49
+ if (process.env.mode === 'dev') {
50
+ return `${process.env.domain}?devURL=${process.env.devUrl}`;
51
+ }
52
+ return `${process.env.domain}`;
53
+ }
54
+
55
+ page.getCustomPageUrl = function (url) {
56
+ if (process.env.mode === 'dev') {
57
+ return `${process.env.domain}/${url}?devURL=${process.env.devUrl}`
58
+ }
59
+ return `${process.env.domain}/${url}`
60
+ }
61
+ await use(page);
62
+
63
+
64
+ //await use(new FilteredPage(page));
65
+
66
+ // await use(async (page) => {
67
+ // delete page.getByTestId;
68
+ // await page;
69
+ // });
70
+
71
+ },
72
+ context: async ({ context }, use) => {
73
+ await context.addInitScript(() => window.localStorage.setItem('isDnBannerHide', true));
74
+ await use(context);
75
+ }
76
+ })
77
+
78
+
79
+ module.exports = {
80
+ expect,
81
+ test
81
82
  }
@@ -1,18 +1,30 @@
1
- const { existsSync } = require('fs');
2
- const path = require('path');
3
-
4
- const fileName = 'test.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
-
18
- module.exports = generateConfigFromFile;
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
30
+ };
@@ -1,44 +1,43 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
3
- const { Logger } = require('../../utils/logger');
4
- const getFilePathWithExtension = require('../../utils/getFilePath');
5
- const { getBinPath } = require('../../utils/rootPath');
6
-
7
-
8
- const userArgs = process.argv.slice(3);
9
-
10
- const playwrightPath = path.resolve(getBinPath(), getFilePathWithExtension('playwright'));;
11
- const command = playwrightPath;
12
- const reportPath = path.resolve(process.cwd(), './playwright-report');
13
-
14
-
15
- const args = ['show-report', reportPath].concat(userArgs);
16
-
17
- function generateReport() {
18
- const childProcess = spawn(command, args, { stdio: 'inherit' });
19
- childProcess.on('error', (error) => {
20
- Logger.log(Logger.FAILURE_TYPE, error);
21
- })
22
-
23
- childProcess.on('exit', (code, signal) => {
24
- Logger.log(Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
25
-
26
- process.exit();
27
- });
28
-
29
- process.on('exit', () => {
30
- Logger.log(Logger.INFO_TYPE, 'Terminating Playwright Process...');
31
- childProcess.kill();
32
- return;
33
- });
34
-
35
- process.on('SIGINT', () => {
36
- Logger.log(Logger.INFO_TYPE, 'Cleaning up...');
37
- childProcess.kill();
38
- process.exit();
39
-
40
- });
41
- }
42
-
43
-
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
+
44
43
  module.exports = generateReport;
@@ -0,0 +1,79 @@
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,64 +1,64 @@
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 getFilePathWithExtension = require('../../utils/getFilePath');
8
- const generateConfigFromFile = require('./readConfigFile');
9
- const { getBinPath } = require('../../utils/rootPath');
10
-
11
-
12
-
13
- // Access the command line arguments
14
- const userArgs = process.argv.slice(2);
15
-
16
- const userArgsObject = cliArgsToObject(userArgs);
17
-
18
- initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : 'dev');
19
-
20
-
21
- generateConfigFromFile();
22
-
23
-
24
-
25
- const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS.includes(key));
26
-
27
- // Command and arguments for npx playwright test
28
- const playwrightPath = path.resolve(getBinPath(), getFilePathWithExtension('playwright'));
29
-
30
- const command = playwrightPath;
31
- const args = ['test', '--config', require.resolve('../../../playwright.config.js')].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 } = 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;
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,35 @@
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
+
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
+ }
35
35
  }
@@ -1,35 +1,35 @@
1
- function cliArgsToObject(cliArgs, isKeyNeedToBeAdded) {
2
- const processEnv = {};
3
- cliArgs.forEach(option => {
4
- if (/^--./.test(option)) {
5
- const equIndex = option.indexOf('=');
6
- let key = option.slice(2, equIndex);
7
- let value = option.slice(equIndex + 1);
8
- if (equIndex === -1) {
9
- key = option.slice(2);
10
- value = true;
11
- }
12
- processEnv[key] = value;
13
- }
14
- });
15
- return processEnv;
16
- }
17
-
18
- function objectToCliArgs(objectToBeConverted, isKeyNeedToBeAdded) {
19
- const argsArray = [];
20
-
21
- Object.keys(objectToBeConverted).forEach(key => {
22
- if (isKeyNeedToBeAdded(key)) {
23
- if (typeof objectToBeConverted[key] === 'boolean' && objectToBeConverted[key]) {
24
- argsArray.push(`--${key}`)
25
- } else {
26
- argsArray.push(`--${key}=${objectToBeConverted[key]}`)
27
- }
28
- }
29
- })
30
-
31
- return argsArray;
32
- }
33
-
34
-
1
+ function cliArgsToObject(cliArgs, isKeyNeedToBeAdded) {
2
+ const processEnv = {};
3
+ cliArgs.forEach(option => {
4
+ if (/^--./.test(option)) {
5
+ const equIndex = option.indexOf('=');
6
+ let key = option.slice(2, equIndex);
7
+ let value = option.slice(equIndex + 1);
8
+ if (equIndex === -1) {
9
+ key = option.slice(2);
10
+ value = true;
11
+ }
12
+ processEnv[key] = value;
13
+ }
14
+ });
15
+ return processEnv;
16
+ }
17
+
18
+ function objectToCliArgs(objectToBeConverted, isKeyNeedToBeAdded) {
19
+ const argsArray = [];
20
+
21
+ Object.keys(objectToBeConverted).forEach(key => {
22
+ if (isKeyNeedToBeAdded(key)) {
23
+ if (typeof objectToBeConverted[key] === 'boolean' && objectToBeConverted[key]) {
24
+ argsArray.push(`--${key}`)
25
+ } else {
26
+ argsArray.push(`--${key}=${objectToBeConverted[key]}`)
27
+ }
28
+ }
29
+ })
30
+
31
+ return argsArray;
32
+ }
33
+
34
+
35
35
  module.exports = { cliArgsToObject, objectToCliArgs };