Skip to content

Commit 6bf6d36

Browse files
committed
fix configurations and add global variable setup
1 parent 1641e3f commit 6bf6d36

16 files changed

+71
-38
lines changed

codecept.conf.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const path = require('path');
21
const playwrightConfig = require('./config/playwright.conf');
32
const restConfig = require('./config/rest.conf');
43
const graphqlConfig = require('./config/graphql.conf');
@@ -7,6 +6,8 @@ const multipleConfig = require('./config/multiple.conf');
76
const gherkinConfig = require('./config/gherkin.conf');
87
const includeConfig = require('./config/include.conf');
98
const mochaConfig = require('./config/mocha.conf');
9+
const globalVariablesConfig = require('./config/global.variables.conf');
10+
1011
exports.config = {
1112
output: './outputs',
1213
helpers: {
@@ -27,5 +28,6 @@ exports.config = {
2728
retries: 2
2829
},
2930
multiple: multipleConfig,
30-
waitForNavigation: "load"
31+
waitForNavigation: "load",
32+
globalVariables: globalVariablesConfig
3133
};

config/gherkin.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
features: './src/features/*.feature',
3-
steps: './src/step_definitions/*.js'
4-
};
3+
steps: './src/step_definitions/*_steps.js'
4+
};

config/global.variables.conf.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global.api_helper = require("../custom_helpers/api_helper");
2+
global.browser_storage_utils = require("../custom_helpers/browser_storage_utils");
3+
global.common_codeceptjs_utils = require("../custom_helpers/common_codeceptjs_utils");
4+
global.common_utils = require("../custom_helpers/common_utils");
5+
global.excel_utils = require("../custom_helpers/excel_utils");
6+
global.graphql_helper = require("../custom_helpers/graphql_helper");
7+
global.keyboard_utils = require("../custom_helpers/keyboard_utils");
8+
global.strings_data = require("../custom_helpers/strings_data");
9+
global.test_data = require("../custom_helpers/test_data");
10+
global.variables = require("../custom_helpers/variables");

config/include.conf.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
22
I: './steps_file.js',
33
page: './src/pages/*.js',
4-
customHelper: '../custom_helpers/*.js'
54
};

config/plugins.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
allure: {
33
enabled: true, // Enable or disable the allure plugin
4-
outputDir: './allure-results', // Directory to save allure results
4+
outputDir: './outputs/allure-results', // Directory to save allure results
55
require: '@codeceptjs/allure-legacy', // Use the allure legacy reporter
66

77
// Basic Configuration

custom_helpers/api_helper.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
12
const I = actor();
3+
24
const envURL = require('../config/env.conf'); // Import environment configuration
35

46
// Extract the base API endpoint from the environment configuration
@@ -11,8 +13,9 @@ if (!api_endpoint) {
1113
/**
1214
* API Helper class for managing API requests and configurations.
1315
*/
14-
class ApiHelper {
15-
constructor() {
16+
class ApiHelper extends Helper{
17+
constructor(config) {
18+
super(config);
1619
// Initialize common variables or settings
1720
}
1821

custom_helpers/browser_storage_utils.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
12
const I = actor();
23

3-
export class browser_storage_utils {
4-
constructor() {
4+
module.exports = new class browser_storage_utils extends Helper {
5+
constructor(config) {
6+
super(config);
57
}
68

79
/**

custom_helpers/common_codeceptjs_utils.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const I = actor()
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
2+
const I = actor();
23
const {assert} = require('chai'); // Import Chai assertion library for validating test conditions
3-
export class common_codeceptjs_utils {
4-
constructor() {
5-
4+
class common_codeceptjs_utils extends Helper{
5+
constructor(config) {
6+
super(config);
67
}
78

89
/**
@@ -152,4 +153,6 @@ export class common_codeceptjs_utils {
152153
const value = await I.grabAttributeFrom(locator, 'selected');
153154
assert.equal(value[0], 'true');
154155
}
155-
}
156+
}
157+
158+
module.exports = new common_codeceptjs_utils();

custom_helpers/common_utils.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
12
const I = actor();
23
const {assert} = require('chai'); // Import Chai assertion library for validating test conditions
34
const ExcelJS = require('exceljs'); // Import exceljs for reading and writing Excel files
45
const path = require('path'); // Import path module for handling and transforming file paths
56
const fs = require('fs'); // Import fs module for file system operations
67
const mongoose = require('mongoose');
78

8-
export class common_utils {
9-
constructor() {
9+
class common_utils extends Helper {
10+
constructor(config) {
11+
super(config);
1012

1113
}
1214

@@ -160,4 +162,6 @@ export class common_utils {
160162
}
161163
}
162164
}
163-
}
165+
}
166+
167+
module.exports = new common_utils();

custom_helpers/excel_utils.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const I = actor();
2-
const {assert} = require('chai'); // Import Chai assertion library for validating test conditions
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
32
const ExcelJS = require('exceljs'); // Import exceljs for reading and writing Excel files
43
const path = require('path'); // Import path module for handling and transforming file paths
5-
const fs = require('fs'); // Import fs module for file system operations
6-
const mongoose = require('mongoose');
74

8-
export class excel_utils {
5+
6+
class excel_utils extends Helper{
97
/**
108
* Reads an Excel file and returns the workbook.
119
* @param {string} filePath - Path to the Excel file.
@@ -247,4 +245,8 @@ export class excel_utils {
247245
return rowData;
248246
});
249247
}
248+
}
249+
250+
module.exports = {
251+
excel_utils: new excel_utils()
250252
}

custom_helpers/graphql_helper.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
12
const I = actor();
2-
const envURL = require('../config/env.conf'); // Import environment configuration
3+
const envURL = require('../config/env.conf');
34

45
// Extract the base API endpoint for GraphQL from the environment configuration
56
const graphql_endpoint = envURL[envURL.env].services.end_point;
@@ -11,8 +12,9 @@ if (!graphql_endpoint) {
1112
/**
1213
* GraphQL Helper class for managing GraphQL queries and mutations.
1314
*/
14-
class GraphQLHelper {
15-
constructor() {
15+
class GraphQLHelper extends Helper {
16+
constructor(config) {
17+
super(config);
1618
// Initialize common variables or settings
1719
this.defaultTimeout = 30000; // Default timeout for requests
1820
}

custom_helpers/keyboard_utils.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const { Helper } = require('@codeceptjs/helper');
1+
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
2+
const I = actor();
23
const os = require('os');
3-
const { Key } = require('playwright');
4+
const {Key} = require('playwright');
45

5-
class KeyboardHelper extends Helper {
6+
class keyboard_utils extends Helper {
67
constructor(config) {
78
super(config);
89
this.platform = os.platform();
@@ -67,7 +68,7 @@ class KeyboardHelper extends Helper {
6768

6869
// Method to press keys with multiple combinations
6970
async pressKey(keyCombination) {
70-
const { I } = this.helpers;
71+
const {I} = this.helpers;
7172
await I.pressKey(this.mapKeyCombination(keyCombination));
7273
}
7374

@@ -122,4 +123,4 @@ class KeyboardHelper extends Helper {
122123
}
123124
}
124125

125-
module.exports = KeyboardHelper;
126+
module.exports = new keyboard_utils();

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"step_definitions": "./src/step_definitions"
3232
},
3333
"scripts": {
34-
"test:run": "codeceptjs run --plugins allure --config=./codecept.conf.js",
35-
"test:report-serve": "allure serve ./allure-results --clean",
34+
"test:run": "codeceptjs run --debug --plugins allure --config=./codecept.conf.js",
35+
"test:report-serve": "allure serve ./outputs/allure-results --clean",
3636
"test:debug": "codeceptjs run --debug --grep '@debug' --config=./codecept.conf.js",
37-
"test:report-generate": "allure generate ./allure-results --clean -o ./allure-report",
37+
"test:report-generate": "allure generate ./outputs/allure-results --clean -o ./allure-report",
3838
"test:e2e": "codeceptjs run --plugins allure --config=./codecept.conf.js",
3939
"test:parallel": "codeceptjs run-multiple --all --plugins allure --config=./codecept.conf.js",
4040
"test:report-open": "allure open ./allure-report"
@@ -44,7 +44,6 @@
4444
},
4545
"dependencies": {
4646
"@codeceptjs/configure": "^1.0.1",
47-
"@codeceptjs/helper": "^2.0.4",
4847
"axios": "^1.7.3",
4948
"chai": "^4.5.0",
5049
"codeceptjs": "^3.6.5",
@@ -62,7 +61,6 @@
6261
"allure-playwright": "^3.0.0-beta.7",
6362
"codeceptjs-browserlogs-plugin": "^1.0.5",
6463
"debug": "^4.3.6",
65-
"eslint": "^9.8.0",
6664
"moment": "^2.30.1"
6765
},
6866
"engines": {

src/features/01-test_feature.feature

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Feature: test-feature
2+
Scenario: test-scenario
3+
Given test step here
4+
# And steps to be check
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Given(/^test step here$/, function () {
3+
console.log(variables.test)
4+
});

steps.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/// <reference types='codeceptjs' />
22
type steps_file = typeof import('./steps_file.js');
33
type page = typeof import('./src/pages/*.js');
4-
type customHelper = typeof import('./custom_helpers/*.js');
54

65
declare namespace CodeceptJS {
7-
interface SupportObject { I: I, current: any, page: page, customHelper: customHelper }
6+
interface SupportObject { I: I, current: any, page: page }
87
interface Methods extends Playwright, REST, GraphQL, FileSystem {}
98
interface I extends ReturnType<steps_file>, WithTranslation<Methods> {}
109
namespace Translation {

0 commit comments

Comments
 (0)