@zohodesk/testinglibrary 0.0.5-exp.15 → 0.0.5-exp.17

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.
@@ -22,6 +22,7 @@ const fileName = 'uat.config.js';
22
22
  * @property {boolean} debug - debug mode
23
23
  * @property {string} mode: mode in which the test cases needs to run
24
24
  * @property {boolean} isAuthMode - Auth Mode
25
+ * @property {string} authFilePath - File Path where the cookies stored
25
26
  * @property {any} browsers: List of browsers
26
27
  * @property {string} openReportOn: default Option value (never, on-failure and always)
27
28
  * @property {any} reportPath : directory where report is generate
@@ -57,6 +58,8 @@ function getAuthFilePath(filePath) {
57
58
  try {
58
59
  if ((0, _fs.existsSync)(filePath)) {
59
60
  return filePath;
61
+ } else {
62
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Ensure cookies present in ${filePath}. Authetication file not Exist ...`);
60
63
  }
61
64
  } catch (err) {
62
65
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Founded Path - ${filePath} Authetication file not Exist ...`);
@@ -23,7 +23,8 @@ const {
23
23
  reportPath = _path.default.join(process.cwd(), 'uat', 'playwright-report'),
24
24
  bddMode = false,
25
25
  expectTimeout = 5 * 1000,
26
- testTimeout = 60 * 1000
26
+ testTimeout = 60 * 1000,
27
+ authFilePath = 'uat/playwright/.auth/user.json'
27
28
  } = (0, _readConfigFile.generateConfigFromFile)();
28
29
  let projects = browsers.map(browser => {
29
30
  if (browser === 'Chrome') {
@@ -31,7 +32,7 @@ let projects = browsers.map(browser => {
31
32
  name: 'chromium',
32
33
  use: {
33
34
  ..._test.devices['Desktop Chrome'],
34
- storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')) : {}
35
+ storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
35
36
  },
36
37
  dependencies: isAuthMode ? ['setup'] : []
37
38
  };
@@ -41,7 +42,7 @@ let projects = browsers.map(browser => {
41
42
  use: {
42
43
  ..._test.devices['Desktop Chrome'],
43
44
  channel: 'msedge',
44
- storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')) : {}
45
+ storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
45
46
  },
46
47
  dependencies: isAuthMode ? ['setup'] : []
47
48
  };
@@ -54,7 +55,7 @@ let projects = browsers.map(browser => {
54
55
  },
55
56
  use: {
56
57
  ..._test.devices['Desktop Firefox'],
57
- storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')) : {}
58
+ storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
58
59
  },
59
60
  dependencies: isAuthMode ? ['setup'] : []
60
61
  };
@@ -67,7 +68,7 @@ let projects = browsers.map(browser => {
67
68
  },
68
69
  use: {
69
70
  ..._test.devices['Desktop Safari'],
70
- storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')) : {}
71
+ storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
71
72
  },
72
73
  dependencies: isAuthMode ? ['setup'] : null
73
74
  };
package/build/lib/cli.js CHANGED
@@ -6,9 +6,10 @@ var _reportGenerator = _interopRequireDefault(require("../core/playwright/report
6
6
  var _codegen = _interopRequireDefault(require("../core/playwright/codegen"));
7
7
  var _logger = require("../utils/logger");
8
8
  var _setupProject = _interopRequireDefault(require("../setup-folder-structure/setupProject"));
9
+ var _parser = require("../parser/parser");
9
10
  // import createJestRunner from '../core/jest/runner/jest-runner';
10
11
 
11
- const [,, option] = process.argv;
12
+ const [,, option, ...otherOptions] = process.argv;
12
13
  // const args = process.argv.slice(3);
13
14
  // const appPath = process.cwd();
14
15
 
@@ -42,6 +43,7 @@ switch (option) {
42
43
  case 'generateSpecFile':
43
44
  {
44
45
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Generating Spec file...');
46
+ (0, _parser.generateSpecCodeForFeatureFile)(otherOptions);
45
47
  break;
46
48
  }
47
49
  default:
@@ -4,11 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.generateSpecCodeForFeatureFile = generateSpecCodeForFeatureFile;
7
8
  exports.parseFeature = parseFeature;
8
9
  exports.specFileGenerator = specFileGenerator;
9
10
  var _fs = _interopRequireDefault(require("fs"));
10
11
  var _path = _interopRequireDefault(require("path"));
11
12
  var _logger = require("../utils/logger");
13
+ var _cliArgsToObject = require("../utils/cliArgsToObject");
14
+ var _fileUtils = require("../utils/fileUtils");
12
15
  function parseFeature(featureContent) {
13
16
  const lines = featureContent.split('\n');
14
17
  let currentFeature = null;
@@ -86,6 +89,7 @@ function generateSpecFileContent({
86
89
  return specContent;
87
90
  }
88
91
  function specFileGenerator(filePath) {
92
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Generating spec file using file ${filePath}`);
89
93
  // Read the Gherkin feature file
90
94
  _fs.default.readFile(filePath, 'utf8', (err, data) => {
91
95
  if (err) {
@@ -93,9 +97,15 @@ function specFileGenerator(filePath) {
93
97
  } else {
94
98
  // Parse the feature file content and get the JSON-like object
95
99
  const parsedFeature = parseFeature(data);
96
- let specFilePath = _path.default.resolve(process.cwd(), '../', filePath.replace(/\.feature$/, '.spec.js'));
97
- if (filePath.includes('features')) {
98
- specFilePath = filePath.replace(/\.feature$/, '.spec.js').replace(/\/features\//, '/steps/');
100
+ let specFilePath = filePath.replace(/\.feature$/, '.spec.js');
101
+ if (filePath.includes('feature-files')) {
102
+ specFilePath = specFilePath.replace(/\/feature-files\//, '/steps/');
103
+ } else {
104
+ specFilePath = specFilePath.replace('./', '../steps/');
105
+ }
106
+ if ((0, _fileUtils.checkIfFileExists)(filePath)) {
107
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'File Already exists. Make sure to either delete or pass --update option true');
108
+ return;
99
109
  }
100
110
 
101
111
  // Output the JSON-like object
@@ -113,4 +123,13 @@ function specFileGenerator(filePath) {
113
123
  });
114
124
  }
115
125
  });
126
+ }
127
+ function generateSpecCodeForFeatureFile(options) {
128
+ let cliObj = (0, _cliArgsToObject.cliArgsToObject)(options);
129
+ let featureFilePath = cliObj.featureFile;
130
+ if (featureFilePath) {
131
+ specFileGenerator(_path.default.join(process.cwd(), './', featureFilePath));
132
+ } else {
133
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Need option --featureFile to run this command');
134
+ }
116
135
  }
@@ -1,39 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.verifyFeatureFileWithSpecFile = verifyFeatureFileWithSpecFile;
8
- var _fs = _interopRequireDefault(require("fs"));
9
4
  var _path = _interopRequireDefault(require("path"));
10
5
  var _fastGlob = _interopRequireDefault(require("fast-glob"));
11
6
  var _parser = require("./parser");
12
7
  var _logger = require("../utils/logger");
8
+ var _fileUtils = require("../utils/fileUtils");
13
9
  // Specify the directory where you want to search for .feature and .spec.js files
14
- const directoryPath = '../../examples/uat';
10
+ const directoryPath = './uat';
15
11
 
16
12
  // Use glob to match .feature files in the directory
17
- const featurePattern = _path.default.join(directoryPath, '**/*.feature');
13
+ const featurePattern = _path.default.join(process.cwd(), directoryPath, '**/*.feature');
18
14
 
19
15
  // function onSpecFileNotFound() { }
20
16
 
21
- function checkIfFileExists(file) {
22
- try {
23
- _fs.default.accessSync(file, _fs.default.constants.F_OK);
24
- return true;
25
- } catch (err) {
26
- return false;
27
- }
28
- }
29
- function readFileContents(file) {
30
- try {
31
- let fileContents = _fs.default.readFileSync(file, 'utf-8');
32
- return fileContents;
33
- } catch (err) {
34
- return null;
35
- }
36
- }
37
17
  function verifyFeatureFileWithSpecFile() {
38
18
  try {
39
19
  let errorCount = 0;
@@ -42,14 +22,14 @@ function verifyFeatureFileWithSpecFile() {
42
22
  });
43
23
  featureFiles.forEach(featureFile => {
44
24
  // Construct the corresponding .spec.js filename
45
- const specFile = featureFile.replace(/\.feature$/, '.spec.js').replace(/\/features\//, '/steps/');
25
+ const specFile = featureFile.replace(/\.feature$/, '.spec.js').replace(/\/feature-files\//, '/steps/');
46
26
  let featureFileNameExtract = featureFile.split('/').pop();
47
27
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `parsing feature file ${featureFileNameExtract}...`);
48
28
  // Check if the .spec.js file exists
49
29
 
50
- if (checkIfFileExists(specFile)) {
51
- let featureContents = readFileContents(featureFile);
52
- let specContents = readFileContents(specFile);
30
+ if ((0, _fileUtils.checkIfFileExists)(specFile)) {
31
+ let featureContents = (0, _fileUtils.readFileContents)(featureFile);
32
+ let specContents = (0, _fileUtils.readFileContents)(specFile);
53
33
  //let [featureContents, specContents] = Promise.all([readFileContents(featureFile), readFileContents(specFile)]);
54
34
  if (featureContents !== null && specContents !== null) {
55
35
  const featureJSON = (0, _parser.parseFeature)(featureContents);
@@ -92,6 +72,7 @@ function verifyFeatureFileWithSpecFile() {
92
72
  }
93
73
  } catch (err) {
94
74
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, err);
95
- process.exit();
75
+ process.exit(1);
96
76
  }
97
- }
77
+ }
78
+ verifyFeatureFileWithSpecFile();
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
 
3
3
  /**
4
- * Represents the user configuration object.
5
- * @typedef {Object} UserConfig
6
- * @property {string} headless - Headless Browsers mode.
7
- * @property {number} trace - trace for test cases.
8
- * @property {boolean} video - video for test cases,
9
- * @property {boolean} debug - debug mode
10
- * @property {string} mode: mode in which the test cases needs to run
11
- * @property {boolean} isAuthMode - Auth Mode
12
- * @property {any} browsers: List of browsers
13
- * @property {string} openReportOn: default Option value (never, on-failure and always)
14
- * @property {any} reportPath : directory where report is generate
15
- * @property {boolean} bddMode: Feature files needs to be processed
16
- * @property {number} expectTimeout: time in milliseconds which the expect condition should fail
17
- * @property {number} testTimeout: time in milliseconds which the test should fail
18
- * @property {Object} additionalPages: custom pages configuration
4
+ * Represents the user configuration object.
5
+ * @typedef {Object} UserConfig
6
+ * @property {string} headless - Headless Browsers mode.
7
+ * @property {number} trace - trace for test cases.
8
+ * @property {boolean} video - video for test cases,
9
+ * @property {boolean} debug - debug mode
10
+ * @property {string} mode: mode in which the test cases needs to run
11
+ * @property {boolean} isAuthMode - Auth Mode
12
+ * @property {string} authFilePath - File Path where the cookies stored
13
+ * @property {any} browsers: List of browsers
14
+ * @property {string} openReportOn: default Option value (never, on-failure and always)
15
+ * @property {any} reportPath : directory where report is generate
16
+ * @property {boolean} bddMode: Feature files needs to be processed
17
+ * @property {number} expectTimeout: time in milliseconds which the expect condition should fail
18
+ * @property {number} testTimeout: time in milliseconds which the test should fail
19
+ * @property {Object} additionalPages: custom pages configuration
19
20
  */
20
21
 
21
22
  /**
@@ -26,6 +27,7 @@ module.exports = {
26
27
  browsers: ['Chrome', 'Firefox'],
27
28
  mode: 'dev',
28
29
  isAuthMode: true,
30
+ authFilePath: 'uat/playwright/.auth/user.json',
29
31
  trace: true,
30
32
  video: true
31
33
  };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.checkIfFileExists = checkIfFileExists;
8
+ exports.readFileContents = readFileContents;
9
+ var _fs = _interopRequireDefault(require("fs"));
10
+ function checkIfFileExists(file) {
11
+ try {
12
+ _fs.default.accessSync(file, _fs.default.constants.F_OK);
13
+ return true;
14
+ } catch (err) {
15
+ return false;
16
+ }
17
+ }
18
+ function readFileContents(file) {
19
+ try {
20
+ let fileContents = _fs.default.readFileSync(file, 'utf-8');
21
+ return fileContents;
22
+ } catch (err) {
23
+ return null;
24
+ }
25
+ }
package/changelog.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Framework that abstracts the configuration for playwright and Jest
4
4
 
5
+ # 0.0.5-exp.17
6
+
7
+ - Minor bugfix
8
+ - Added config for auth file path
9
+
10
+ # 0.0.5-exp.16
11
+
12
+ - Provided option for generating code from feature
13
+ - npm run generateSpecFile -- --featureFile=filepath
14
+
5
15
  # 0.0.5-exp.15
6
16
 
7
17
  - parser added for feature file verification
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.0.5-exp.15",
3
+ "version": "0.0.5-exp.17",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {