artes 1.1.23 → 1.1.24

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/README.md CHANGED
@@ -42,32 +42,32 @@ npx artes [options]
42
42
 
43
43
  ### Options
44
44
 
45
- | Option | Description | Usage Example |
46
- | ------------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
47
- | 🆘 `-h, --help` | Show the usage options | `artes -h` or `artes --help` |
48
- | 🏷️ `-v, --version` | Show the current version of Artes | `artes -v` or `artes --version` |
49
- | 🏗️ `-c, --create` | Create an example project with Artes | `artes -c` or `artes --create` |
50
- | ✅ `-y, --yes` | Skip the confirmation prompt when creating an example project | `artes -c -y` or `artes --create --yes` |
51
- | 📊 `-r, --report` | Run tests and generate Allure report | `artes -r` or `artes --report` |
52
- | `--reportSuccess` | Add screenshots and video records for also Success test cases | `artes --reportSuccess` |
53
- | `--trace` | Enable tracing | `artes --trace ` |
54
- | `-rwt, --reportWithTrace` | Add trace to the report | ` artes -rwt ` or `artes --reportWithTrace`|
55
- | 📁 `--features` | Specify one or more feature files' relative paths to run (comma-separated) | `artes --features "tests/features/Alma,tests/features/Banan.feature"` |
56
- | 📜 `--stepDef` | Specify one or more step definition files' relative paths to use (comma-separated) | `artes --stepDef "tests/steps/login.js,tests/steps/home.js"` |
57
- | 🔖 `--tags` | Run tests with specified Cucumber tags | `artes --tags "@smoke or @wip"` |
58
- | 🌐 `--env` | Set the environment for the test run | `artes --env "dev"` |
59
- | 🕶️ `--headless` | Run browser in headless mode | `artes --headless` |
60
- | ⚡ `--parallel` | Run tests in parallel mode | `artes --parallel 2` |
61
- | 🔁 `--retry` | Retry failed tests | `artes --retry 3` |
62
- | 🎭 `--dryRun` | Perform a dry run without executing tests | `artes --dryRun` |
63
- | 📈 `--percentage` | Set minimum success percentage to pass test run (default is 0) | `artes --percentage 85` |
64
- | 🌍 `--browser` | Specify browser to use (`chromium`, `firefox`, or `webkit`) | `artes --browser chromium` |
65
- | 🔗 `--baseURL` | Set base URL for the tests | `artes --baseURL "https://example.com"` |
66
- | 🖥️ `--maxScreen` | Maximize browser window on launch | `artes --maxScreen` |
67
- | 📏 `--width` | Set browser width (default is 1280) | `artes --width 1920` |
68
- | 📐 `--height` | Set browser height (default is 720) | `artes --height 1080` |
69
- | ⏱️ `--timeout` | Set timeout for each test step in seconds (default is 30 seconds) | `artes --timeout 10` |
70
- | 🐢 `--slowMo` | Slow down text execution for clear view (default: 0 seconds) | `artes --slowMo 1` |
45
+ | Option | Description | Usage Example |
46
+ | ------------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
47
+ | 🆘 `-h, --help` | Show the usage options | `artes -h` or `artes --help` |
48
+ | 🏷️ `-v, --version` | Show the current version of Artes | `artes -v` or `artes --version` |
49
+ | 🏗️ `-c, --create` | Create an example project with Artes | `artes -c` or `artes --create` |
50
+ | ✅ `-y, --yes` | Skip the confirmation prompt when creating an example project | `artes -c -y` or `artes --create --yes` |
51
+ | 📊 `-r, --report` | Run tests and generate Allure report | `artes -r` or `artes --report` |
52
+ | `--reportSuccess` | Add screenshots and video records for also Success test cases | `artes --reportSuccess` |
53
+ | `--trace` | Enable tracing | `artes --trace ` |
54
+ | `-rwt, --reportWithTrace` | Add trace to the report | `artes -rwt` or `artes --reportWithTrace` |
55
+ | 📁 `--features` | Specify one or more feature files' relative paths to run (comma-separated) | `artes --features "tests/features/Alma,tests/features/Banan.feature"` |
56
+ | 📜 `--stepDef` | Specify one or more step definition files' relative paths to use (comma-separated) | `artes --stepDef "tests/steps/login.js,tests/steps/home.js"` |
57
+ | 🔖 `--tags` | Run tests with specified Cucumber tags | `artes --tags "@smoke or @wip"` |
58
+ | 🌐 `--env` | Set the environment for the test run | `artes --env "dev"` |
59
+ | 🕶️ `--headless` | Run browser in headless mode | `artes --headless` |
60
+ | ⚡ `--parallel` | Run tests in parallel mode | `artes --parallel 2` |
61
+ | 🔁 `--retry` | Retry failed tests | `artes --retry 3` |
62
+ | 🎭 `--dryRun` | Perform a dry run without executing tests | `artes --dryRun` |
63
+ | 📈 `--percentage` | Set minimum success percentage to pass test run (default is 0) | `artes --percentage 85` |
64
+ | 🌍 `--browser` | Specify browser to use (`chromium`, `firefox`, or `webkit`) | `artes --browser chromium` |
65
+ | 🔗 `--baseURL` | Set base URL for the tests | `artes --baseURL "https://example.com"` |
66
+ | 🖥️ `--maxScreen` | Maximize browser window on launch | `artes --maxScreen` |
67
+ | 📏 `--width` | Set browser width (default is 1280) | `artes --width 1920` |
68
+ | 📐 `--height` | Set browser height (default is 720) | `artes --height 1080` |
69
+ | ⏱️ `--timeout` | Set timeout for each test step in seconds (default is 30 seconds) | `artes --timeout 10` |
70
+ | 🐢 `--slowMo` | Slow down text execution for clear view (default: 0 seconds) | `artes --slowMo 1` |
71
71
 
72
72
  \*\* To just run the tests: <br>
73
73
  Globally: artes <br>
@@ -175,6 +175,86 @@ Feature: Searching on Google 🔍
175
175
 
176
176
  ---
177
177
 
178
+ ## 🌍 Environment Variables Configuration
179
+
180
+ Artes now supports environment-specific configurations through environment variables. This feature allows you to manage different settings for development, staging, and production environments.
181
+
182
+ ### Setting Up Environment Variables
183
+
184
+ 1. **Configure Environment in artes.config.js:**
185
+
186
+ ```javascript
187
+ module.exports = {
188
+ baseURL: {
189
+ dev: "https://dev.dlp.az",
190
+ pre: "https://pre.dlp.az",
191
+ prod: "https://api.dlp.az",
192
+ },
193
+ env: "dev", // Specify which environment to use
194
+ // ... other configurations
195
+ };
196
+ ```
197
+
198
+ **Alternative single URL configuration:**
199
+
200
+ ```javascript
201
+ module.exports = {
202
+ baseURL: "https://api.example.com", // Direct string URL
203
+ env: "dev",
204
+ // ... other configurations
205
+ };
206
+ ```
207
+
208
+ 2. **Create Environment Variable Files:**
209
+ Create JSON files under `src/tests/environment-variables/` folder with names matching your environment:
210
+
211
+ **dev.json:**
212
+
213
+ ```json
214
+ {
215
+ "api_key": "dev-api-key-12345",
216
+ "auth_token": "dev-auth-token",
217
+ "database_url": "dev-db.example.com",
218
+ "timeout": 5000,
219
+ "headers": {
220
+ "Authorization": "Bearer dev-token",
221
+ "Content-Type": "application/json"
222
+ }
223
+ }
224
+ ```
225
+
226
+ **pre.json:**
227
+
228
+ ```json
229
+ {
230
+ "api_key": "pre-api-key-67890",
231
+ "auth_token": "pre-auth-token",
232
+ "database_url": "pre-db.example.com",
233
+ "timeout": 3000,
234
+ "headers": {
235
+ "Authorization": "Bearer pre-token",
236
+ "Content-Type": "application/json"
237
+ }
238
+ }
239
+ ```
240
+
241
+ ### How It Works
242
+
243
+ 1. **Environment Detection:** When Artes runs, it reads the `env` value from `artes.config.js`
244
+ 2. **Base URL Resolution:** If `baseURL` is an object, it uses the environment key to find the corresponding URL. If `baseURL` is a string, it uses it directly
245
+ 3. **Variable Loading:** Artes looks for a JSON file matching the environment name in `src/tests/environment-variables/`
246
+ 4. **Runtime Access:** All variables from the environment file become available during test execution
247
+
248
+ ### Important Notes
249
+
250
+ - ⚠️ **Base URLs must be defined in `artes.config.js`** - they cannot be set in the environment variable JSON files
251
+ - 📁 Environment variable files should be placed in `src/tests/environment-variables/`
252
+ - 🏷️ File names must exactly match the environment name (e.g., `dev.json` for `env: "dev"`)
253
+ - 🔄 Variables are loaded into variable storage and can be accessed during test runs
254
+ - 🌐 Use environment variables for headers, API keys, timeouts, and other environment-specific configurations
255
+
256
+ ---
257
+
178
258
  ## 🛠️ Customization
179
259
 
180
260
  ## ✍️ Writing Custom Step Definitions
@@ -300,7 +380,7 @@ You can configure Artes by editing the `artes.config.js` file. Below are the def
300
380
  | `report` | `false` | Generate report |
301
381
  | `reportSuccess` | `false` | Add screenshots and video records for also success test cases |
302
382
  | `trace` | `false` | Enable trace |
303
- | `reportWithTrace` | `false` | Add trace to the report |
383
+ | `reportWithTrace` | `false` | Add trace to the report |
304
384
  | `format` | `["rerun:@rerun.txt", "allure-cucumberjs/reporter"]` | Formatter names/paths. |
305
385
  | `formatOptions` | `{ "resultsDir": "allure-result" }` | Formatter options. |
306
386
  | `parallel` | `1` | Number of parallel workers. |
@@ -116,7 +116,12 @@ module.exports = {
116
116
  // World parameters
117
117
  worldParameters: artesConfig.worldParameters || {}, // Custom world parameters
118
118
  },
119
- env: process.env.ENV ? JSON.parse(process.env.ENV) : artesConfig.env || "",
119
+ env: process.env.ENV
120
+ ? JSON.parse(process.env.ENV)
121
+ : artesConfig.env ||
122
+ (typeof artesConfig.baseURL === "object" && artesConfig.baseURL !== null
123
+ ? Object.keys(artesConfig.baseURL)[0]
124
+ : ""),
120
125
  baseURL: process.env.BASE_URL
121
126
  ? JSON.parse(process.env.BASE_URL)
122
127
  : artesConfig?.baseURL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,7 +9,11 @@ function pomCollector() {
9
9
  `${cucumberConfig.default.pomPath}/${file}`,
10
10
  "utf-8",
11
11
  (err, content) => {
12
- addElements(JSON.parse(content));
12
+ try {
13
+ addElements(JSON.parse(content));
14
+ } catch (error) {
15
+ console.log(`Error parsing POM file ${file}:`, error.message);
16
+ }
13
17
  },
14
18
  );
15
19
  });
@@ -8,7 +8,7 @@ function generateReport() {
8
8
  spawnSync("npm", ["run", "testWithReport", moduleConfig.reportPath], {
9
9
  cwd: moduleConfig.modulePath,
10
10
  stdio: "ignore",
11
- shell: true
11
+ shell: true,
12
12
  });
13
13
 
14
14
  console.log(
@@ -35,7 +35,7 @@ const moduleConfig = {
35
35
  stepsPath: path.join(projectPath, "/tests/steps/*.js"),
36
36
  pomPath: path.join(projectPath, "/tests/POMs"),
37
37
  cleanUpPaths:
38
- "allure-result allure-results test-results @rerun.txt testsStatus EXIT_CODE.txt"
38
+ "allure-result allure-results test-results @rerun.txt testsStatus EXIT_CODE.txt",
39
39
  };
40
40
 
41
41
  module.exports = {
@@ -21,10 +21,10 @@ const { moduleConfig } = require("artes/src/helper/imports/commons");
21
21
  const statusDir = path.join(process.cwd(), "testsStatus");
22
22
  const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
23
23
 
24
- setDefaultTimeout(cucumberConfig.default.timeout);
25
-
26
24
  /* ------------------- Helpers ------------------- */
27
25
 
26
+ setDefaultTimeout(cucumberConfig.default.timeout);
27
+
28
28
  async function attachResponse(attachFn) {
29
29
  if (!context.response) return;
30
30
 
@@ -55,6 +55,23 @@ BeforeAll(() => {
55
55
  Before(async function () {
56
56
  context.vars = {};
57
57
 
58
+ const envFilePath = path.join(
59
+ moduleConfig.projectPath,
60
+ "tests",
61
+ "environment_variables",
62
+ `${cucumberConfig.env}.env.json`,
63
+ );
64
+
65
+ if (fs.existsSync(envFilePath)) {
66
+ let env_vars = fs.readFileSync(envFilePath, "utf-8");
67
+ try {
68
+ env_vars = JSON.parse(env_vars);
69
+ context.vars = { ...context.vars, ...env_vars };
70
+ } catch (err) {
71
+ console.log("Error parsing environment variables JSON:", err);
72
+ }
73
+ }
74
+
58
75
  const { browser, context: browserContext } = await invokeBrowser();
59
76
  const requestInstance = await invokeRequest();
60
77