@zohodesk/testinglibrary 3.0.4 → 3.0.8
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/.gitlab-ci.yml +26 -13
- package/README.md +27 -0
- package/build/core/playwright/builtInFixtures/page.js +44 -39
- package/build/core/playwright/constants/fileMutexConfig.js +7 -3
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/helpers/auth/loginSteps.js +15 -14
- package/build/core/playwright/helpers/checkAuthDirectory.js +10 -0
- package/build/core/playwright/helpers/fileMutex.js +20 -23
- package/build/core/playwright/runner/Runner.js +22 -0
- package/build/core/playwright/runner/RunnerHelper.js +43 -0
- package/build/core/playwright/runner/RunnerTypes.js +17 -0
- package/build/core/playwright/runner/SpawnRunner.js +110 -0
- package/build/core/playwright/setup/config-creator.js +10 -5
- package/build/core/playwright/test-runner.js +8 -34
- package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +4 -10
- package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
- package/build/setup-folder-structure/samples/uat-config-sample.js +3 -1
- package/build/setup-folder-structure/setupProject.js +4 -0
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +45 -68
- package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
- package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
- package/npm-shrinkwrap.json +817 -494
- package/package.json +8 -7
- package/playwright.config.js +0 -48
- package/zohodesk-testinglibrary-3.0.4.tgz +0 -0
|
@@ -20,27 +20,8 @@ var _browserTypes = require("./constants/browserTypes");
|
|
|
20
20
|
var _ConfigurationHelper = require("./configuration/ConfigurationHelper");
|
|
21
21
|
var _Configuration = _interopRequireDefault(require("./configuration/Configuration"));
|
|
22
22
|
var _UserArgs = _interopRequireDefault(require("./configuration/UserArgs"));
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
browsers = null
|
|
26
|
-
} = userArgsObject;
|
|
27
|
-
let browserList = (0, _configUtils.getBrowsersList)(browsers);
|
|
28
|
-
const playwrightArgs = (0, _cliArgsToObject.objectToCliArgs)(userArgsObject, key => !_customCommands.CUSTOM_COMMANDS.includes(key));
|
|
29
|
-
if (debug) {
|
|
30
|
-
playwrightArgs.push('--debug');
|
|
31
|
-
}
|
|
32
|
-
if (!bddMode && tagArgs) {
|
|
33
|
-
playwrightArgs.push('--grep');
|
|
34
|
-
playwrightArgs.push(tagArgs);
|
|
35
|
-
}
|
|
36
|
-
if (!headless && !userArgsObject.headed) {
|
|
37
|
-
playwrightArgs.push('--headed');
|
|
38
|
-
}
|
|
39
|
-
if (browserList && browserList.length > 0) {
|
|
40
|
-
browserList.map(browser => playwrightArgs.push(`--project=${_browserTypes.BROWSER_PROJECT_MAPPING[browser.toUpperCase()]}`));
|
|
41
|
-
}
|
|
42
|
-
return playwrightArgs;
|
|
43
|
-
}
|
|
23
|
+
var _RunnerHelper = _interopRequireDefault(require("./runner/RunnerHelper"));
|
|
24
|
+
var _Runner = _interopRequireDefault(require("./runner/Runner"));
|
|
44
25
|
function runPreprocessing(tagArgs, configPath) {
|
|
45
26
|
const beforeCommand = 'node';
|
|
46
27
|
const bddGenPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('bddgen'));
|
|
@@ -124,18 +105,11 @@ function main() {
|
|
|
124
105
|
const userArgsObject = userArgConfig.getAll();
|
|
125
106
|
const tagProcessor = new _tagProcessor.default(editionOrder);
|
|
126
107
|
const tagArgs = tagProcessor.processTags(userArgsObject);
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
if (bddMode) {
|
|
134
|
-
promises.push(runPreprocessing(tagArgs, configPath));
|
|
135
|
-
}
|
|
136
|
-
Promise.all(promises).then(() => runPlaywright(command, args)).catch(err => {
|
|
137
|
-
_logger.Logger.error(err);
|
|
138
|
-
process.exit();
|
|
139
|
-
});
|
|
108
|
+
const runnerObj = new _Runner.default();
|
|
109
|
+
runnerObj.setTagArgs(tagArgs);
|
|
110
|
+
runnerObj.setUserArgs(userArgsObject);
|
|
111
|
+
runnerObj.setConfig(uatConfig);
|
|
112
|
+
const runner = _RunnerHelper.default.createRunner('spawn', runnerObj);
|
|
113
|
+
runner.run();
|
|
140
114
|
}
|
|
141
115
|
var _default = exports.default = main;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// This is the sample file generated by testing framework. You can change as per the respective project login
|
|
2
|
+
|
|
3
|
+
const getUrlOrigin = require('../shared/url-helpers/getUrlOrigin');
|
|
4
|
+
|
|
5
|
+
async function accountLogin( { page, email, password } ) {
|
|
6
|
+
await page.locator('#login_id').fill(email);
|
|
7
|
+
await page.locator('#nextbtn').click();
|
|
8
|
+
await page.locator('#password').fill(password);
|
|
9
|
+
await page.locator('#nextbtn').click();
|
|
10
|
+
|
|
11
|
+
const domainUrlOrigin = getUrlOrigin(process.env.domain);
|
|
12
|
+
await page.waitForNavigation();
|
|
13
|
+
await Promise.race([
|
|
14
|
+
page.waitForURL(`${domainUrlOrigin}/**`),
|
|
15
|
+
page.waitForURL('**/announcement/**')
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = accountLogin;
|
|
@@ -5,17 +5,11 @@ import {
|
|
|
5
5
|
getDefaultActor
|
|
6
6
|
} from '@zohodesk/testinglibrary/helpers';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import { loginSteps , validateLogin } from './testSetup';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
//Implement your validation steps here
|
|
12
|
-
//Refer desk_client_app auth.setup.js
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
10
|
+
const user = getDefaultActor();
|
|
15
11
|
|
|
16
12
|
setup(`${user.edition} - Authentication`, async ({ page }) => {
|
|
17
|
-
|
|
18
13
|
//Implement performLoginSteps here
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
14
|
+
await performLoginSteps({page, ...user},validateLogin ,loginSteps);
|
|
15
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
const accountLogin = require('./accountLogin');
|
|
3
|
+
|
|
4
|
+
async function verifyPageIsLoaded({page}) {
|
|
5
|
+
|
|
6
|
+
//Implement your validation logic here
|
|
7
|
+
//Refer deskclientapp testSetup.js
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
loginSteps:accountLogin,
|
|
12
|
+
validateLogin:verifyPageIsLoaded,
|
|
13
|
+
page:()=>{}
|
|
14
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const testSetup = require('../../fixtures/testSetup');
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {Object|null} viewportConfig
|
|
3
4
|
* @property {number} width - width of the viewport
|
|
@@ -40,5 +41,6 @@ module.exports = {
|
|
|
40
41
|
bddMode: true,
|
|
41
42
|
featureFilesFolder: 'feature-files',
|
|
42
43
|
stepDefinitionsFolder: 'steps',
|
|
43
|
-
viewport: { width: 1280, height: 720 }
|
|
44
|
+
viewport: { width: 1280, height: 720 },
|
|
45
|
+
testSetup
|
|
44
46
|
}
|
|
@@ -73,6 +73,10 @@ function createAuthenticationFile() {
|
|
|
73
73
|
}
|
|
74
74
|
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'auth.setup.js'), getSetupFileAsString('auth-setup-sample.js'), null, 2);
|
|
75
75
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Authentication File ....');
|
|
76
|
+
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'accountLogin.js'), getSetupFileAsString('accountLogin-sample.js'), null, 2);
|
|
77
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating login script File ....');
|
|
78
|
+
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'testSetup.js'), getSetupFileAsString('testSetup-sample.js'), null, 2);
|
|
79
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating testSetup File ....');
|
|
76
80
|
} catch (err) {
|
|
77
81
|
_logger.Logger.error(err);
|
|
78
82
|
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat');
|
|
@@ -2,93 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
var _fileMutex = _interopRequireDefault(require("../../../../../core/playwright/helpers/fileMutex"));
|
|
5
|
-
var
|
|
5
|
+
var _properLockfile = _interopRequireDefault(require("proper-lockfile"));
|
|
6
6
|
var _path = _interopRequireDefault(require("path"));
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
-
jest.mock('lockfile');
|
|
8
|
+
jest.mock('proper-lockfile');
|
|
9
9
|
jest.mock('fs');
|
|
10
10
|
describe('FileMutex', () => {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
retries:
|
|
16
|
-
|
|
11
|
+
const directory = '/tmp/locks';
|
|
12
|
+
const lockFileName = 'test-lock';
|
|
13
|
+
const options = {
|
|
14
|
+
stale: 10000,
|
|
15
|
+
retries: {
|
|
16
|
+
retries: 5,
|
|
17
|
+
factor: 1,
|
|
18
|
+
minTimeout: 5000,
|
|
19
|
+
maxTimeout: 8000
|
|
20
|
+
}
|
|
17
21
|
};
|
|
22
|
+
const lockFilePath = _path.default.resolve(directory, lockFileName + '.lock');
|
|
18
23
|
let fileMutex;
|
|
19
24
|
beforeEach(() => {
|
|
20
|
-
fileMutex = new _fileMutex.default(
|
|
21
|
-
});
|
|
22
|
-
afterEach(() => {
|
|
25
|
+
fileMutex = new _fileMutex.default(directory, lockFileName, options);
|
|
23
26
|
jest.clearAllMocks();
|
|
24
27
|
});
|
|
25
28
|
describe('acquire', () => {
|
|
26
|
-
it('should
|
|
27
|
-
const expectedPath = _path.default.resolve(_path.default.join(mockDirectory, `./${mockFileName}.lock`));
|
|
28
|
-
_lockfile.default.lock.mockImplementation((lockPath, options, callback) => {
|
|
29
|
-
expect(lockPath).toBe(expectedPath);
|
|
30
|
-
expect(options).toEqual(mockTimeout);
|
|
31
|
-
callback(null);
|
|
32
|
-
});
|
|
33
|
-
await expect(fileMutex.acquire()).resolves.toBeUndefined();
|
|
34
|
-
expect(_lockfile.default.lock).toHaveBeenCalledWith(expectedPath, mockTimeout, expect.any(Function));
|
|
35
|
-
});
|
|
36
|
-
it('should reject when lockfile.lock fails', async () => {
|
|
37
|
-
const mockError = new Error('Lock failed');
|
|
38
|
-
_lockfile.default.lock.mockImplementation((lockPath, options, callback) => {
|
|
39
|
-
expect(lockPath).toBe(_path.default.resolve(_path.default.join(mockDirectory, `./${mockFileName}.lock`)));
|
|
40
|
-
expect(options).toEqual(mockTimeout);
|
|
41
|
-
callback(mockError);
|
|
42
|
-
});
|
|
43
|
-
await expect(fileMutex.acquire()).rejects.toThrow('Lock failed');
|
|
44
|
-
expect(_lockfile.default.lock).toHaveBeenCalled();
|
|
45
|
-
});
|
|
46
|
-
it('should create the directory if it does not exist and acquire the lock', async () => {
|
|
29
|
+
it('should create the directory if it does not exist', async () => {
|
|
47
30
|
_fs.default.existsSync.mockReturnValue(false);
|
|
48
|
-
_fs.default.mkdirSync.mockImplementation((
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
_lockfile.default.lock.mockImplementation((lockPath, options, callback) => {
|
|
55
|
-
expect(lockPath).toBe(_path.default.resolve(_path.default.join(mockDirectory, `./${mockFileName}.lock`)));
|
|
56
|
-
expect(options).toEqual(mockTimeout);
|
|
57
|
-
callback(null);
|
|
58
|
-
});
|
|
59
|
-
await expect(fileMutex.acquire()).resolves.toBeUndefined();
|
|
60
|
-
expect(_fs.default.existsSync).toHaveBeenCalledWith(mockDirectory);
|
|
61
|
-
expect(_fs.default.mkdirSync).toHaveBeenCalledWith(mockDirectory, {
|
|
31
|
+
_fs.default.mkdirSync.mockImplementation(() => {});
|
|
32
|
+
_properLockfile.default.lock.mockResolvedValue();
|
|
33
|
+
await fileMutex.acquire();
|
|
34
|
+
expect(_fs.default.existsSync).toHaveBeenCalledWith(directory);
|
|
35
|
+
expect(_fs.default.mkdirSync).toHaveBeenCalledWith(directory, {
|
|
62
36
|
recursive: true
|
|
63
37
|
});
|
|
64
|
-
expect(_lockfile.default.lock).toHaveBeenCalled();
|
|
65
38
|
});
|
|
66
|
-
it('should
|
|
39
|
+
it('should create the lock file if it does not exist', async () => {
|
|
40
|
+
_fs.default.existsSync.mockImplementation(filePath => filePath !== lockFilePath);
|
|
41
|
+
_fs.default.writeFileSync.mockImplementation(() => {});
|
|
42
|
+
_properLockfile.default.lock.mockResolvedValue();
|
|
43
|
+
await fileMutex.acquire();
|
|
44
|
+
expect(_fs.default.existsSync).toHaveBeenCalledWith(lockFilePath);
|
|
45
|
+
expect(_fs.default.writeFileSync).toHaveBeenCalledWith(lockFilePath, 'locked');
|
|
46
|
+
});
|
|
47
|
+
it('should acquire the lock using proper-lockfile', async () => {
|
|
67
48
|
_fs.default.existsSync.mockReturnValue(true);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
49
|
+
_properLockfile.default.lock.mockResolvedValue();
|
|
50
|
+
await fileMutex.acquire();
|
|
51
|
+
expect(_properLockfile.default.lock).toHaveBeenCalledWith(lockFilePath, options);
|
|
52
|
+
});
|
|
53
|
+
it('should throw an error if lock acquisition fails', async () => {
|
|
54
|
+
const errorMessage = 'Lock acquisition failed';
|
|
55
|
+
_properLockfile.default.lock.mockRejectedValue(new Error(errorMessage));
|
|
56
|
+
await expect(fileMutex.acquire()).rejects.toThrow(`Failed to acquire lock after ${options.retries.retries} attempts: ${errorMessage}`);
|
|
74
57
|
});
|
|
75
58
|
});
|
|
76
59
|
describe('release', () => {
|
|
77
|
-
it('should
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
await expect(fileMutex.release()).resolves.toBeUndefined();
|
|
83
|
-
expect(_lockfile.default.unlock).toHaveBeenCalledWith(expectedPath, expect.any(Function));
|
|
60
|
+
it('should release the lock using proper-lockfile', async () => {
|
|
61
|
+
_properLockfile.default.unlock.mockResolvedValue();
|
|
62
|
+
await fileMutex.release();
|
|
63
|
+
expect(_properLockfile.default.unlock).toHaveBeenCalledWith(lockFilePath);
|
|
84
64
|
});
|
|
85
|
-
it('should
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
await expect(fileMutex.release()).rejects.toThrow('Unlock failed');
|
|
91
|
-
expect(_lockfile.default.unlock).toHaveBeenCalled();
|
|
65
|
+
it('should throw an error if lock release fails', async () => {
|
|
66
|
+
const errorMessage = 'Lock release failed';
|
|
67
|
+
_properLockfile.default.unlock.mockRejectedValue(new Error(errorMessage));
|
|
68
|
+
await expect(fileMutex.release()).rejects.toThrow(`Failed to release lock: ${errorMessage}`);
|
|
92
69
|
});
|
|
93
70
|
});
|
|
94
71
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _RunnerHelper = _interopRequireDefault(require("../../../../../core/playwright/runner/RunnerHelper"));
|
|
5
|
+
var _SpawnRunner = _interopRequireDefault(require("../../../../../core/playwright/runner/SpawnRunner"));
|
|
6
|
+
describe('RunnerHelper', () => {
|
|
7
|
+
describe('createRunner', () => {
|
|
8
|
+
it('should throw error on invalid runner type', () => {
|
|
9
|
+
expect(() => _RunnerHelper.default.createRunner('invalid-type', {})).toThrow("Invalid runner type");
|
|
10
|
+
});
|
|
11
|
+
it('should create a valid runner class', () => {
|
|
12
|
+
const runnerInstance = _RunnerHelper.default.createRunner('spawn', {});
|
|
13
|
+
expect(runnerInstance).toBeInstanceOf(_SpawnRunner.default); // Directly pass the result
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _RunnerHelper = _interopRequireDefault(require("../../../../../core/playwright/runner/RunnerHelper"));
|
|
5
|
+
var _Runner = _interopRequireDefault(require("../../../../../core/playwright/runner/Runner"));
|
|
6
|
+
var _Configuration = _interopRequireDefault(require("../../../../../core/playwright/configuration/Configuration"));
|
|
7
|
+
jest.mock('child_process');
|
|
8
|
+
jest.mock('../../../../../utils/logger');
|
|
9
|
+
describe('SpawnRunner', () => {
|
|
10
|
+
let spawnRunner;
|
|
11
|
+
const runnerObj = new _Runner.default();
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
const config = new _Configuration.default({});
|
|
14
|
+
config.add("bddMode", true);
|
|
15
|
+
runnerObj.setConfig(config);
|
|
16
|
+
runnerObj.setTagArgs(["--headed"]);
|
|
17
|
+
spawnRunner = _RunnerHelper.default.createRunner('spawn', runnerObj);
|
|
18
|
+
});
|
|
19
|
+
describe('run', () => {
|
|
20
|
+
it('should call runPreprocessing when bddMode is true', () => {
|
|
21
|
+
const runPreprocessingSpy = jest.spyOn(spawnRunner, 'runPreprocessing').mockResolvedValue();
|
|
22
|
+
const runPlaywrightSpy = jest.spyOn(spawnRunner, 'runPlaywright').mockResolvedValue();
|
|
23
|
+
spawnRunner.run();
|
|
24
|
+
expect(runPreprocessingSpy).toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|