@zohodesk/testinglibrary 0.0.5-exp.21 → 0.0.5-exp.23
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/build/core/playwright/test-runner.js +5 -1
- package/build/parser/verifier.js +6 -4
- package/build/setup-folder-structure/auth-setup-sample.js +67 -0
- package/build/setup-folder-structure/authUsers-sample.json +9 -0
- package/build/setup-folder-structure/setupProject.js +4 -8
- package/build/setup-folder-structure/uat-config-sample.js +1 -1
- package/changelog.md +8 -0
- package/package.json +1 -1
- package/build/setup-folder-structure/user-example.json +0 -3
|
@@ -23,7 +23,8 @@ function createTestRunner() {
|
|
|
23
23
|
const {
|
|
24
24
|
debug,
|
|
25
25
|
mode = 'dev',
|
|
26
|
-
bddMode = false
|
|
26
|
+
bddMode = false,
|
|
27
|
+
headless = false
|
|
27
28
|
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
28
29
|
|
|
29
30
|
// Environment variables Initialization
|
|
@@ -35,6 +36,9 @@ function createTestRunner() {
|
|
|
35
36
|
if (tagArgs) {
|
|
36
37
|
playwrightArgs.push(`--grep ${tagArgs}`);
|
|
37
38
|
}
|
|
39
|
+
if (!headless && !userArgsObject.headed) {
|
|
40
|
+
playwrightArgs.push('--headed');
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
// ZDTetsting test --tags=@live
|
|
40
44
|
// Command and arguments for npx playwright test
|
package/build/parser/verifier.js
CHANGED
|
@@ -28,10 +28,11 @@ function verifyIfMultipleStepsExists(steps) {
|
|
|
28
28
|
});
|
|
29
29
|
return isMultipleStepsFound;
|
|
30
30
|
}
|
|
31
|
-
function extractExamplesToSeperateFile(examples, scenarioIndex, filePath) {
|
|
32
|
-
let exampleFileContent = `export const
|
|
31
|
+
function extractExamplesToSeperateFile(examples, scenarioIndex, filePath, featureName) {
|
|
32
|
+
let exampleFileContent = `export const ${featureName.toUpperCase()}_SCENARIO_${scenarioIndex} = ${JSON.stringify(examples, null, 2)};\r\n`;
|
|
33
|
+
const cleanedData = exampleFileContent.replace(/\r\n/g, '\n');
|
|
33
34
|
try {
|
|
34
|
-
(0, _fileUtils.writeFileContents)(filePath,
|
|
35
|
+
(0, _fileUtils.writeFileContents)(filePath, cleanedData, {
|
|
35
36
|
flag: 'a'
|
|
36
37
|
});
|
|
37
38
|
} catch (err) {
|
|
@@ -50,6 +51,7 @@ function verifyFeatureFileWithSpecFile() {
|
|
|
50
51
|
// Construct the corresponding .spec.js filename
|
|
51
52
|
const specFile = featureFile.replace(/\.feature$/, '.spec.js').replace(/\/feature-files\//, '/steps/');
|
|
52
53
|
let featureFileNameExtract = featureFile.split('/').pop();
|
|
54
|
+
let featurePrefixName = featureFileNameExtract.split('.')[0];
|
|
53
55
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `parsing feature file ${featureFileNameExtract}...`);
|
|
54
56
|
// Check if the .spec.js file exists
|
|
55
57
|
|
|
@@ -71,7 +73,7 @@ function verifyFeatureFileWithSpecFile() {
|
|
|
71
73
|
let scenario = scenarios[i];
|
|
72
74
|
const scenarioName = scenario.name;
|
|
73
75
|
const scenarioExamples = scenario.examples;
|
|
74
|
-
extractExamplesToSeperateFile(scenarioExamples, i, testDataFilePath);
|
|
76
|
+
extractExamplesToSeperateFile(scenarioExamples, i, testDataFilePath, featurePrefixName);
|
|
75
77
|
|
|
76
78
|
// spec file check
|
|
77
79
|
if (!specLines.some(line => line.includes(scenarioName))) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _testinglibrary = require("@zohodesk/testinglibrary");
|
|
5
|
+
var _path = _interopRequireDefault(require("path"));
|
|
6
|
+
var _fs = require("fs");
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
|
|
9
|
+
const userdata = require('./authUsers.json');
|
|
10
|
+
const authDirectory = _path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth');
|
|
11
|
+
const authContent = {
|
|
12
|
+
"cookies": []
|
|
13
|
+
};
|
|
14
|
+
const LOGIN_ERR_MESSAGE = 'Need go be logged in';
|
|
15
|
+
// const AUTH_ERR_MESSAGE = `Founded Path - ${path.resolve(process.cwd(),'uat','playwright','.auth')} \n Find if file is Properly Created. Cookies Cannot Be Read .. `
|
|
16
|
+
|
|
17
|
+
function convertCookiesToParse(cookies, authFilePath) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(cookies);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
throw new Error(` Error while parsing cookies ${err} \n${_path.default.resolve(process.cwd(), authFilePath)} File is Empty`);
|
|
22
|
+
// process.exit()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!(0, _fs.existsSync)(authDirectory)) {
|
|
27
|
+
console.log('Creating auth directory for the first time setup...');
|
|
28
|
+
(0, _fs.mkdirSync)(authDirectory, {
|
|
29
|
+
recursive: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
userdata.map(data => {
|
|
33
|
+
let authFile = _path.default.resolve(_path.default.join(authDirectory, `${data.filename}`));
|
|
34
|
+
if (!(0, _fs.existsSync)(authFile)) {
|
|
35
|
+
console.log('creating auth file..');
|
|
36
|
+
(0, _fs.writeFileSync)(authFile, JSON.stringify(authContent, null, 2));
|
|
37
|
+
}
|
|
38
|
+
(0, _testinglibrary.test)(data.description, async ({
|
|
39
|
+
page
|
|
40
|
+
}) => {
|
|
41
|
+
try {
|
|
42
|
+
const cookies = (0, _fs.readFileSync)(authFile);
|
|
43
|
+
const parsedCookies = convertCookiesToParse(cookies, authFile);
|
|
44
|
+
await page.context().addCookies(parsedCookies.cookies == undefined ? [] : parsedCookies.cookies);
|
|
45
|
+
await page.goto(page.getBaseUrl());
|
|
46
|
+
await page.waitForLoadState();
|
|
47
|
+
if (await page.url().includes(process.env.domain)) {
|
|
48
|
+
await page.waitForSelector('header [data-id="zdsetup"]');
|
|
49
|
+
} else {
|
|
50
|
+
throw new Error(LOGIN_ERR_MESSAGE);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (err.message === LOGIN_ERR_MESSAGE) {
|
|
54
|
+
await (0, _testinglibrary.expect)(page.locator('.load-bg')).toBeHidden();
|
|
55
|
+
await page.locator('#login_id').type(data.useremail);
|
|
56
|
+
await page.locator('#nextbtn').click();
|
|
57
|
+
await page.locator('#password').type(data.password);
|
|
58
|
+
await page.locator('#nextbtn').click();
|
|
59
|
+
await page.waitForLoadState("networkidle");
|
|
60
|
+
await page.waitForSelector(data.locator);
|
|
61
|
+
await page.context().storageState({
|
|
62
|
+
path: authFile
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -12,6 +12,7 @@ function getScriptsToBeAdded() {
|
|
|
12
12
|
return {
|
|
13
13
|
"ua-test": "ZDTestingFramework test --mode=prod --headed",
|
|
14
14
|
"ua-test-debug": "ZDTestingFramework test --mode=prod --debug",
|
|
15
|
+
"ua-test-ci": "ZDTestingFramework test --mode=prod",
|
|
15
16
|
"ua-report": "ZDTestingFramework report --port=9009",
|
|
16
17
|
"codegen": "ZDTestingFramework codegen deskclientapp.localzoho.com/agent"
|
|
17
18
|
};
|
|
@@ -35,14 +36,12 @@ function updatePackageJSONScripts() {
|
|
|
35
36
|
(0, _fs.writeFileSync)(packageJsonPath, JSON.stringify(modifiedConfigJSON, null, 2));
|
|
36
37
|
} else {
|
|
37
38
|
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Unable to find package json. Run init command in the root path of the project.');
|
|
38
|
-
process.exit();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
function createFolderForUAT() {
|
|
42
42
|
const uatFolder = _path.default.resolve(process.cwd(), 'uat');
|
|
43
43
|
if ((0, _fs.existsSync)(uatFolder)) {
|
|
44
44
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Uat Folder already Exists.');
|
|
45
|
-
process.exit();
|
|
46
45
|
} else {
|
|
47
46
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Uat Folder');
|
|
48
47
|
(0, _fs.mkdirSync)(uatFolder);
|
|
@@ -55,7 +54,6 @@ function createUatConfig() {
|
|
|
55
54
|
const uatConfigPath = _path.default.resolve(process.cwd(), 'uat.config.js');
|
|
56
55
|
if ((0, _fs.existsSync)(uatConfigPath)) {
|
|
57
56
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Uat Config already Exists.');
|
|
58
|
-
process.exit();
|
|
59
57
|
} else {
|
|
60
58
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Uat config file...');
|
|
61
59
|
(0, _fs.writeFileSync)(uatConfigPath, getSetupFileAsString('uat-config-sample.js'), null, 2);
|
|
@@ -66,14 +64,12 @@ function createAuthenticationFile() {
|
|
|
66
64
|
if ((0, _fs.existsSync)(isUATexist)) {
|
|
67
65
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Authentication File ....');
|
|
68
66
|
try {
|
|
69
|
-
(0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', '
|
|
70
|
-
recursive: true
|
|
71
|
-
});
|
|
67
|
+
(0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'));
|
|
72
68
|
(0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'), {
|
|
73
69
|
recursive: true
|
|
74
70
|
});
|
|
75
|
-
|
|
76
|
-
(0, _fs.writeFileSync)(
|
|
71
|
+
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'auth.setup.js'), getSetupFileAsString('auth-setup-sample.js'), null, 2);
|
|
72
|
+
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'authUser.json'), getSetupFileAsString('authUsers-sample.js'), null, 2);
|
|
77
73
|
} catch (err) {
|
|
78
74
|
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat');
|
|
79
75
|
}
|
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.5-exp.23
|
|
6
|
+
|
|
7
|
+
- Auth File Setup Configuration changes
|
|
8
|
+
|
|
9
|
+
# 0.0.5-exp.22
|
|
10
|
+
|
|
11
|
+
- Bug fixes while creating examples file
|
|
12
|
+
|
|
5
13
|
# 0.0.5-exp.21
|
|
6
14
|
|
|
7
15
|
- Bug fixes while creating examples file
|
package/package.json
CHANGED