artes 1.1.45 → 1.1.48

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.
@@ -30,6 +30,21 @@ const finalFormats = [
30
30
  ]),
31
31
  ];
32
32
 
33
+ function resolveEnv(artesConfig) {
34
+ if (typeof artesConfig.baseURL === "object" && artesConfig.baseURL !== null) {
35
+ if (process.env.ENV && artesConfig.baseURL.hasOwnProperty(process.env.ENV.trim())) {
36
+ return process.env.ENV.trim();
37
+ } else if (artesConfig.env && artesConfig.baseURL.hasOwnProperty(artesConfig.env.trim())) {
38
+ return artesConfig.env.trim();
39
+ } else {
40
+ return Object.keys(artesConfig.baseURL)[0];
41
+ }
42
+ }
43
+
44
+ return process.env.ENV || artesConfig.env || "";
45
+ }
46
+ const env = resolveEnv(artesConfig);
47
+
33
48
  module.exports = {
34
49
  default: {
35
50
  // File paths and patterns
@@ -116,17 +131,7 @@ module.exports = {
116
131
  // World parameters
117
132
  worldParameters: artesConfig.worldParameters || {}, // Custom world parameters
118
133
  },
119
- env: (typeof artesConfig.baseURL === "object" && artesConfig.baseURL !== null
120
- ? (
121
- process.env.ENV && artesConfig.baseURL.hasOwnProperty(process.env.ENV.trim())
122
- ? process.env.ENV.trim()
123
- : (
124
- artesConfig.env && artesConfig.baseURL.hasOwnProperty(artesConfig.env.trim())
125
- ? artesConfig.env.trim()
126
- : Object.keys(artesConfig.baseURL)[0]
127
- )
128
- )
129
- : (process.env.ENV || artesConfig.env || "")),
134
+ env: env,
130
135
  baseURL: process.env.BASE_URL
131
136
  ? JSON.parse(process.env.BASE_URL)
132
137
  : artesConfig?.baseURL
package/executer.js CHANGED
@@ -55,22 +55,8 @@ const height = args[args.indexOf("--height") + 1];
55
55
  const timeout = args[args.indexOf("--timeout") + 1];
56
56
  const slowMo = args[args.indexOf("--slowMo") + 1];
57
57
 
58
- if (flags.env) {
59
- const envCandidate = env.trim();
60
- if (typeof artesConfig.baseURL === "object" && artesConfig.baseURL !== null) {
61
- if (artesConfig.baseURL.hasOwnProperty(envCandidate)) {
62
- process.env.ENV = JSON.stringify(envCandidate);
63
- console.log("Running env:", envCandidate);
64
- } else {
65
- const firstKey = Object.keys(artesConfig.baseURL)[0];
66
- process.env.ENV = JSON.stringify(firstKey);
67
- console.log(`Env "${envCandidate}" not found, falling back to:`, firstKey);
68
- }
69
- } else {
70
- process.env.ENV = JSON.stringify(envCandidate);
71
- console.log("Running env:", envCandidate);
72
- }
73
- }
58
+
59
+ flags.env ? (process.env.ENV = env) : ""
74
60
 
75
61
  flags.reportWithTrace ||
76
62
  artesConfig.reportWithTrace ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.1.45",
3
+ "version": "1.1.48",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,12 +8,7 @@ const invokeBrowser = async () => {
8
8
 
9
9
  if (typeof cucumberConfig.baseURL === "object") {
10
10
  const env = (cucumberConfig.env || "").trim();
11
- if (env && cucumberConfig.baseURL.hasOwnProperty(env)) {
12
11
  baseURL = cucumberConfig.baseURL[env];
13
- } else {
14
- const firstKey = Object.keys(cucumberConfig.baseURL)[0];
15
- baseURL = cucumberConfig.baseURL[firstKey];
16
- }
17
12
  } else {
18
13
  baseURL = cucumberConfig.baseURL;
19
14
  }
@@ -5,12 +5,7 @@ let baseURL = "";
5
5
 
6
6
  if (typeof cucumberConfig.baseURL === "object") {
7
7
  const env = (cucumberConfig.env || "").trim();
8
- if (env && cucumberConfig.baseURL.hasOwnProperty(env)) {
9
8
  baseURL = cucumberConfig.baseURL[env];
10
- } else {
11
- const firstKey = Object.keys(cucumberConfig.baseURL)[0];
12
- baseURL = cucumberConfig.baseURL[firstKey];
13
- }
14
9
  } else {
15
10
  baseURL = cucumberConfig.baseURL;
16
11
  }
@@ -134,17 +134,42 @@ function saveVar(value, customName, path) {
134
134
  }
135
135
 
136
136
  function resolveVariable(template) {
137
- if (typeof template !== "string") return template;
138
- return template.replace(/{{\s*(\w+)\s*}}/g, (_, varName) => {
139
- let value = context.vars[varName];
140
- if (typeof value === "string") {
141
- value = value
142
- .replace(/\n/g, "\\n")
143
- .replace(/\r/g, "\\r")
144
- .replace(/\t/g, "\\t");
137
+ if (typeof template === "string") {
138
+ return template.replace(/{{\s*(\w+)\s*}}/g, (_, varName) => {
139
+ let value = context.vars[varName];
140
+
141
+ if (value !== undefined) {
142
+ if (typeof value !== "string") {
143
+ try {
144
+ value = JSON.stringify(value);
145
+ } catch {
146
+ value = String(value);
147
+ }
148
+ }
149
+
150
+ return value
151
+ .replace(/\n/g, "\\n")
152
+ .replace(/\r/g, "\\r")
153
+ .replace(/\t/g, "\\t");
154
+ }
155
+
156
+ return `{{${varName}}}`;
157
+ });
158
+ }
159
+
160
+ if (Array.isArray(template)) {
161
+ return template.map((item) => resolveVariable(item));
162
+ }
163
+
164
+ if (template && typeof template === "object") {
165
+ const result = {};
166
+ for (const key in template) {
167
+ result[key] = resolveVariable(template[key]);
145
168
  }
146
- return value !== undefined ? value : `{{${varName}}}`;
147
- });
169
+ return result;
170
+ }
171
+
172
+ return template;
148
173
  }
149
174
 
150
175
  module.exports = {
@@ -1,6 +1,7 @@
1
1
  const { addElements } = require("./elementController");
2
2
  const cucumberConfig = require("../../../cucumber.config");
3
3
  const fs = require("fs");
4
+
4
5
  function pomCollector() {
5
6
  if (fs.existsSync(cucumberConfig.default.pomPath)) {
6
7
  fs.readdir(`${cucumberConfig.default.pomPath}`, (err, files) => {
@@ -12,6 +12,7 @@ const browser = {
12
12
  }
13
13
 
14
14
  cookieData = Array.isArray(cookieData) ? cookieData : [cookieData];
15
+
15
16
  await context.browserContext.addCookies(cookieData);
16
17
  },
17
18
  };
@@ -190,6 +190,21 @@ When('User types random fullname in {string}', async (input) => {
190
190
  await element(input).fill(`${randomFirstName} ${randomLastName}`)
191
191
  })
192
192
 
193
+ When('User types random first name in {string}', async (input) => {
194
+ const randomFirstName = await random.person.firstName()
195
+ await element(input).fill(randomFirstName)
196
+ })
197
+
198
+ When('User types random last name in {string}', async (input) => {
199
+ const randomLastName = await random.person.lastName()
200
+ await element(input).fill(randomLastName)
201
+ })
202
+
203
+ When('User types random middle name in {string}', async (input) => {
204
+ const randomMiddleName = await random.person.middleName()
205
+ await element(input).fill(randomMiddleName)
206
+ })
207
+
193
208
  When('User types random date between {int} and {int} in {string}', async (fromYear, toYear, input) => {
194
209
  const year = Math.floor(Math.random() * (toYear - fromYear + 1)) + fromYear
195
210
  const month = Math.floor(Math.random() * 12) + 1
@@ -1,4 +1,4 @@
1
- const { Given, context, random } = require("../helper/imports/commons");
1
+ const { Given, context, random, time } = require("../helper/imports/commons");
2
2
  const { api } = require("../helper/stepFunctions/exporter");
3
3
 
4
4
  Given("User sets random word as {string}", async (key) => {
@@ -16,8 +16,8 @@ Given(
16
16
 
17
17
  Given(
18
18
  "User sets random word that has character between {int} and {int} as {string}",
19
- async (key, from, to) => {
20
- const word = random.lorem.word({ length: { min: from, max: to } });
19
+ async (from, to, key) => {
20
+ const word = random.lorem.word({ min: from, max: to });
21
21
  context.vars[key] = word;
22
22
  },
23
23
  );
@@ -37,12 +37,17 @@ Given(
37
37
 
38
38
  Given(
39
39
  "User sets random words that range between {int} and {int} as {string}",
40
- async (key, from, to) => {
40
+ async (from, to, key) => {
41
41
  const words = random.lorem.words({ min: from, max: to });
42
42
  context.vars[key] = words;
43
43
  },
44
44
  );
45
45
 
46
+ Given('User sets random number as {string}', async (key) => {
47
+ const randomNumber = random.number.int();
48
+ context.vars[key] = randomNumber;
49
+ });
50
+
46
51
  Given(
47
52
  "User sets random number from {int} to {int} as {string}",
48
53
  async (from, to, key) => {
@@ -86,4 +91,69 @@ Given("User sets random value from given {string} array as {string}", async (arr
86
91
  const parsedArray = JSON.parse(array.replace(/'/g, '"'));
87
92
  const randomValue = parsedArray[Math.floor(Math.random() * parsedArray.length)];
88
93
  context.vars[key] = randomValue;
89
- });
94
+ });
95
+
96
+ Given('User sets random paragraph as {string}', async (key) => {
97
+ const randomParagraph = random.lorem.paragraph();
98
+ context.vars[key] = randomParagraph;
99
+ });
100
+
101
+ Given(
102
+ "User sets random paragraph that range between {int} and {int} as {string}",
103
+ async (from, to, key) => {
104
+ const words = random.lorem.paragraph({ min: from, max: to });
105
+ context.vars[key] = words;
106
+ },
107
+ );
108
+
109
+ Given('User sets random characters from {string} as {string}', async (chars, key) => {
110
+ const randomCharacters = random.string.fromCharacters(chars,10);
111
+ context.vars[key] = randomCharacters;
112
+ })
113
+
114
+ Given('User sets random alphanumeric in range from {int} to {int} as {string}', async (from,to, key) => {
115
+ const randomWords = await random.string.alphanumeric({ min: from, max: to })
116
+ context.vars[key] = randomWords;
117
+ })
118
+
119
+ Given('User sets random fullname as {string}', async (key) => {
120
+ const randomFirstName = await random.person.firstName()
121
+ const randomLastName = await random.person.lastName()
122
+ context.vars[key] = `${randomFirstName} ${randomLastName}`
123
+ })
124
+
125
+ Given('User sets random first name as {string}', async (key) => {
126
+ const randomFirstName = await random.person.firstName()
127
+ context.vars[key] = randomFirstName;
128
+ })
129
+
130
+ Given('User sets random last name as {string}', async (key) => {
131
+ const randomLastName = await random.person.lastName()
132
+ context.vars[key] = randomLastName;
133
+ })
134
+
135
+ Given('User sets random middle name as {string}', async (key) => {
136
+ const randomMiddleName = await random.person.middleName()
137
+ context.vars[key] = randomMiddleName;
138
+ })
139
+
140
+ Given('User sets random date between {int} and {int} as {string}', async (fromYear, toYear, key) => {
141
+ const year = Math.floor(Math.random() * (toYear - fromYear + 1)) + fromYear
142
+ const month = Math.floor(Math.random() * 12) + 1
143
+ const day = Math.floor(Math.random() * 28) + 1
144
+ const pad = (num) => num.toString().padStart(2, '0')
145
+ const dateStr = `${pad(day)}.${pad(month)}.${year}`
146
+ context.vars[key] = dateStr;
147
+ })
148
+
149
+ Given('User sets date {int} days after today as {string}', async (day, key) => {
150
+ const now = new time();
151
+ const afterDate = now.add(day, 'day').format("DD-MM-YYYY");
152
+ context.vars[key] = afterDate;
153
+ })
154
+
155
+ Given('User sets date {int} days before today as {string}', async (day, key) => {
156
+ const now = new time();
157
+ const beforeDate = now.subtract(day, 'day').format("DD-MM-YYYY");
158
+ context.vars[key] = beforeDate;
159
+ })