artes 1.2.14 → 1.2.16

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.
Files changed (38) hide show
  1. package/README.md +533 -533
  2. package/cucumber.config.js +171 -171
  3. package/docs/functionDefinitions.md +2401 -2401
  4. package/docs/stepDefinitions.md +352 -352
  5. package/executer.js +161 -161
  6. package/index.js +48 -48
  7. package/package.json +51 -54
  8. package/src/helper/contextManager/browserManager.js +63 -63
  9. package/src/helper/contextManager/requestManager.js +23 -23
  10. package/src/helper/controller/elementController.js +182 -182
  11. package/src/helper/controller/pomCollector.js +25 -25
  12. package/src/helper/executers/cleaner.js +19 -19
  13. package/src/helper/executers/exporter.js +15 -15
  14. package/src/helper/executers/helper.js +95 -95
  15. package/src/helper/executers/projectCreator.js +198 -198
  16. package/src/helper/executers/reportGenerator.js +58 -57
  17. package/src/helper/executers/testRunner.js +30 -30
  18. package/src/helper/executers/versionChecker.js +31 -31
  19. package/src/helper/imports/commons.js +56 -56
  20. package/src/helper/stepFunctions/APIActions.js +362 -362
  21. package/src/helper/stepFunctions/assertions.js +523 -523
  22. package/src/helper/stepFunctions/browserActions.js +22 -22
  23. package/src/helper/stepFunctions/elementInteractions.js +38 -38
  24. package/src/helper/stepFunctions/exporter.js +19 -19
  25. package/src/helper/stepFunctions/frameActions.js +50 -50
  26. package/src/helper/stepFunctions/keyboardActions.js +41 -41
  27. package/src/helper/stepFunctions/mouseActions.js +145 -145
  28. package/src/helper/stepFunctions/pageActions.js +27 -27
  29. package/src/hooks/context.js +15 -15
  30. package/src/hooks/hooks.js +257 -257
  31. package/src/stepDefinitions/API.steps.js +299 -299
  32. package/src/stepDefinitions/assertions.steps.js +861 -861
  33. package/src/stepDefinitions/browser.steps.js +7 -7
  34. package/src/stepDefinitions/frameActions.steps.js +76 -76
  35. package/src/stepDefinitions/keyboardActions.steps.js +226 -226
  36. package/src/stepDefinitions/mouseActions.steps.js +275 -275
  37. package/src/stepDefinitions/page.steps.js +71 -71
  38. package/src/stepDefinitions/random.steps.js +158 -158
package/README.md CHANGED
@@ -1,534 +1,534 @@
1
- <p align="center">
2
- <img alt="artesLogo" src="https://github.com/user-attachments/assets/e0641011-0e96-4330-8ad5-935b395b0838" width="280">
3
- </p>
4
-
5
- <h1 align="center">Artes</h1>
6
-
7
- ## 🚀 Summary
8
-
9
- Artes is a test runner for Playwright that executes [predefined Cucumber tests](./docs/stepDefinitions.md) and can generate Allure reports for test results. It simplifies setting up Playwright with Cucumber in your automation workflow. With Artes, you can easily run tests without writing step definitions, generate reports, and customize your testing environment.
10
-
11
- ![artes demonstration](https://github.com/user-attachments/assets/c46172f7-103d-45d1-a37d-8d4267df0967)
12
-
13
- ## 🧑‍💻 Installation
14
-
15
- You can install **Artes** via npm. To install it globally**(RECOMMENDED)**, run the following command:
16
-
17
- ```bash
18
- npm install -g artes
19
- ```
20
-
21
- To install it locally in your project, run:
22
-
23
- ```bash
24
- npm install artes
25
- ```
26
-
27
- Once installed, you can run **Artes** using:
28
-
29
- ```bash
30
- npx artes [options]
31
- ```
32
-
33
- ---
34
-
35
- ## 💡 Usage
36
-
37
- **Artes** has following CLI options:
38
-
39
- ```bash
40
- npx artes [options]
41
- ```
42
-
43
- ### Options
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
- | `--singleFileReport` | Generate single file allure report | ` artes -r --singleFileReport` |
56
- | `--zip` | Zip the report folder after generation | ` artes -r --zip` |
57
- | 📁 `--features` | Specify one or more feature files' relative paths to run (comma-separated) | `artes --features "tests/features/Alma,tests/features/Banan.feature"` |
58
- | 📜 `--stepDef` | Specify one or more step definition files' relative paths to use (comma-separated) | `artes --stepDef "tests/steps/login.js,tests/steps/home.js"` |
59
- | 🔖 `--tags` | Run tests with specified Cucumber tags | `artes --tags "@smoke or @wip"` |
60
- | 🌐 `--env` | Set the environment for the test run | `artes --env "dev"` |
61
- | 🕶️ `--headless` | Run browser in headless mode | `artes --headless` |
62
- | ⚡ `--parallel` | Run tests in parallel mode | `artes --parallel 2` |
63
- | 🔁 `--retry` | Retry failed tests | `artes --retry 3` |
64
- | 🎭 `--dryRun` | Perform a dry run without executing tests | `artes --dryRun` |
65
- | 📈 `--percentage` | Set minimum success percentage to pass test run (default is 0) | `artes --percentage 85` |
66
- | 🌍 `--browser` | Specify browser to use (`chromium`, `firefox`, or `webkit`) | `artes --browser chromium` |
67
- | 🔗 `--baseURL` | Set base URL for the tests | `artes --baseURL "https://example.com"` |
68
- | 🖥️ `--maxScreen` | Maximize browser window on launch | `artes --maxScreen` |
69
- | 📏 `--width` | Set browser width (default is 1280) | `artes --width 1920` |
70
- | 📐 `--height` | Set browser height (default is 720) | `artes --height 1080` |
71
- | ⏱️ `--timeout` | Set timeout for each test step in seconds (default is 30 seconds) | `artes --timeout 10` |
72
- | 🐢 `--slowMo` | Slow down text execution for clear view (default: 0 seconds) | `artes --slowMo 1` |
73
-
74
- \*\* To just run the tests: <br>
75
- Globally: artes <br>
76
- Locally: npx artes
77
-
78
- ---
79
-
80
- ## 🎯 Best Practices
81
-
82
- - **Global Installation:**
83
- For ease of use, it's recommended that Artes be installed globally. You can do this by running the following command:
84
-
85
- ```bash
86
- npm install -g artes
87
- ```
88
-
89
- - **Project Creation (Recommended):**
90
- To create a new project with Artes, use the `-c` flag. This will automatically set up the folder structure and configuration for you. Run the command:
91
-
92
- ```bash
93
- artes -c
94
- ```
95
-
96
- 🗂️ Example Project Structure: <br/>
97
- After running the `-c` flag to create a new project, the structure will look like this:
98
-
99
- ```
100
- /artes (Project Name)
101
- /tests
102
- /features
103
- (Your feature files here)
104
- /POMs // Optional
105
- (POM JSON file here)
106
- /steps // For custom steps
107
- (Your step definition JS files here)
108
- artes.config.js
109
- /report
110
- (Generated Allure report HTML here)
111
- ```
112
-
113
- **If you choose not to use the `-c` flag**, you can still download Artes to your testing project and use the prepared steps by running:
114
-
115
- ```bash
116
- npx artes
117
- ```
118
-
119
- You must customize the paths of features, steps, and other configurations by editing the `artes.config.js` file located inside your project folder (or create it).
120
-
121
- For example:
122
-
123
- ```javascript
124
- module.exports = {
125
- paths: ["tests/features/"], // Custom path for feature files
126
- require: ["tests/steps/*.js"], // Custom path for step definitions files
127
- pomPath: "tests/POMS/*.js", // Custom path for POM files
128
- };
129
- ```
130
-
131
- ---
132
-
133
- ## 📝 Writing Feature Files and POM Files
134
-
135
- Artes simplifies your test writing with structured feature files and organized Page Object Models (POM). Here’s how you can create them:
136
-
137
- ### 1. 📄 Feature File Structure
138
-
139
- ```gherkin
140
- Feature: Searching on Google 🔍
141
- Scenario Outline: Search for a term on Google
142
- Given User is on "https://www.google.com/" page
143
- When User types "alma" in "google_search_input"
144
- And User clicks "google_search_button"
145
- And User waits 10 seconds
146
- Then "google_text" should have "Alma" text
147
- ```
148
-
149
- - **Feature**: Describes the main feature being tested (e.g., Google search).
150
- - **Scenario Outline**: Defines a test case with steps.
151
- - **Steps**: Use `Given`, `When`, `And`, `Then` keywords to describe actions and expectations.
152
- - **Selectors**: The element names (e.g., `google_search_input`, `google_search_button`) map to the POM file or can be defined directly.
153
-
154
- ### 2. 📂 POM File Example
155
-
156
- ```json
157
- {
158
- "google_search_input": { "selector": "#APjFqb" },
159
- "google_search_button": {
160
- "selector": "input.gNO89b"
161
- },
162
- "google_text": {
163
- "selector": "#rso div h3",
164
- "waitTime": 5 //seconds
165
- }
166
- }
167
- ```
168
-
169
- - 📑 Using POM File is optional but it is **RECOMMENDED**
170
- - 🔗 Using Selector in Feature File is possible
171
- ```gherkin
172
- When User types "alma" in "#APjFqb"
173
- ```
174
- - 🐍 It is good to use snake_case for element names
175
- - ⏳ "waitTime" is to define custom wait for elements, but the feature currently under development
176
- "selector" must be used if "waitTime" is used, but when using only selector is not needed mention in "selector"
177
-
178
- ---
179
-
180
- ## 🛠️ Customization
181
-
182
- ## ✍️ Writing Custom Step Definitions
183
-
184
- Artes allows you to extend its functionality by writing custom step definitions. Here's how you can do it:
185
-
186
- ### Import Required APIs
187
-
188
- ```javascript
189
- const {
190
- expect,
191
- Given,
192
- When,
193
- Then,
194
- element,
195
- context,
196
- keyboard,
197
- mouse,
198
- frame,
199
- assert,
200
- elementInteractions,
201
- } = require("artes"); // Common JS
202
- import { expect, Given, When, Then, element, context } from "artes"; // ES Modules (Do not RECOMMENDED)
203
- ```
204
-
205
- - **`Given`, `When`, `Then`**: These define your steps in Cucumber syntax. Example:
206
-
207
- ```javascript
208
- Given("User is on the login page", async () => {
209
- await context.page.navigateTo("https://example.com/login");
210
- });
211
- ```
212
-
213
- - **`page`**: Provides higher-level page actions such as navigation and waiting(Same as PlayWright). Examples:
214
- - Navigate to a URL:
215
- ```javascript
216
- await context.page.navigate("https://example.com");
217
- ```
218
- - Wait for a selector:
219
- ```javascript
220
- await context.page.waitForSelector("#loadingSpinner");
221
- ```
222
- - **`request`**: Use for sending HTTP requests. _(Note: This feature is currently under development.)_
223
-
224
- - **`element`**: Use for interacting with elements on the web page. Examples:
225
- - Clicking a button:
226
- ```javascript
227
- await element("#submitButton").click();
228
- ```
229
- - Filling an input:
230
- ```javascript
231
- await element("#username").fill("testUser");
232
- ```
233
- - **`expect`**: Use for assertions in your steps. For example:
234
- ```javascript
235
- expect(actualValue).toBe(expectedValue);
236
- expect(element("Page_Title")).toHaveText(expectedValue);
237
- ```
238
-
239
- ## 📋 Simplified Functions
240
-
241
- If you don't want to deal with Playwright methods directly, you can simply use the following predefined actions methods by import them:
242
-
243
- ```javascript
244
- const { mouse, keyboard, frame, elementInteractions, page } = require("artes");
245
- ```
246
-
247
- - **Mouse Actions:**
248
- `mouse.click(element)`
249
-
250
- - **Keyboard Actions:**
251
- `keyboard.press(key)`
252
-
253
- - **Element Interactions:**
254
- `elementInteractions.isChecked()`
255
-
256
- - **Assertions:**
257
- `assert.shouldBeTruthy(element)`
258
-
259
- - **Frame Actions:**
260
- `frame.first()`
261
-
262
- - **API Actions:**
263
- `api.post(url, payload, requestDataType)`
264
-
265
- ---
266
-
267
- For a detailed explanation of each function, please refer to the [function definitions](./docs/functionDefinitions.md).
268
-
269
- ---
270
-
271
- ### Example of Custom Step Definition
272
-
273
- ```javascript
274
- const { Given, When, Then, expect, element, page } = require("artes");
275
-
276
- Given("User is on the home page", async () => {
277
- await page.navigate("https://example.com");
278
- });
279
-
280
- When("User clicks the login button", async () => {
281
- await element("#loginButton").click();
282
- });
283
-
284
- Then("User should see the login form", async () => {
285
- expect(element("#loginForm")).toBeVisible(true);
286
- });
287
- ```
288
-
289
- ## 🪝 Hooks (Lifecycle Hooks)
290
-
291
- Artes supports **hooks** that allow you to execute custom logic **before and after tests, scenarios, and steps**.
292
-
293
- Hooks are **user-defined**.
294
-
295
- ---
296
-
297
- ### 📁 Hooks File Location
298
-
299
- Create the following file **inside your project** (optional):
300
- ```
301
- tests/steps/hooks.js
302
- ```
303
-
304
- ---
305
-
306
- ### ✍️ Writing Hooks
307
-
308
- You can define **only the hooks you need** in hooks.js under the steps folder.
309
- Undefined hooks are automatically skipped.
310
- ```js
311
- // tests/steps/hooks.js
312
-
313
- export function BeforeStep() {
314
- // hook for before each step
315
- }
316
-
317
- export function Before() {
318
- // hook for before each test
319
- }
320
-
321
- export function BeforeAll() {
322
- // hook for before all tests
323
- }
324
-
325
- export function AfterStep() {
326
- // hook for after each step
327
- }
328
-
329
- export function After() {
330
- // hook for after each test
331
- }
332
-
333
- export function AfterAll() {
334
- // hook for after all tests
335
- }
336
- ```
337
-
338
- ---
339
-
340
- ### 🔁 Supported Hook Types
341
-
342
- | Hook Name | Execution Time |
343
- | ------------ | ----------------------------- |
344
- | `BeforeAll` | Once before **all scenarios** |
345
- | `Before` | Before **each scenario** |
346
- | `BeforeStep` | Before **each step** |
347
- | `AfterStep` | After **each step** |
348
- | `After` | After **each scenario** |
349
- | `AfterAll` | Once after **all scenarios** |
350
-
351
- ---
352
-
353
- ### ▶️ Execution Order Example
354
-
355
- For a scenario with steps:
356
- ```
357
- BeforeAll
358
- Before
359
- BeforeStep
360
- (step executes)
361
- AfterStep
362
- After
363
- AfterAll
364
- ```
365
-
366
- ---
367
-
368
- ## ⚙️ Configuration
369
-
370
- You can configure Artes by editing the `artes.config.js` file. Below are the default configuration options with explanations:
371
-
372
- | **Option** | **Default Value** | **Description** |
373
- | ----------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------- |
374
- | `timeout` | `30` | Default timeout in seconds. |
375
- | `slowMo` | `0` | Default slow motion in seconds |
376
- | `paths` | `[moduleConfig.featuresPath]` | Paths to feature files. |
377
- | `require` | `[moduleConfig.stepsPath, "src/stepDefinitions/*.js", "src/hooks/hooks.js"]` | Support code paths (CommonJS). |
378
- | `pomPath` | `moduleConfig.pomPath` | Path to Page Object Models. |
379
- | `import` | `[]` | Support code paths. |
380
- | `testPercentage` | `0` | Define test coverage percentage |
381
- | `report` | `false` | Generate report |
382
- | `reportSuccess` | `false` | Add screenshots and video records for also success test cases |
383
- | `trace` | `false` | Enable trace |
384
- | `reportWithTrace` | `false` | Add trace to the report |
385
- | `format` | `["rerun:@rerun.txt", "allure-cucumberjs/reporter"]` | Formatter names/paths. |
386
- | `formatOptions` | `{ "resultsDir": "allure-result" }` | Formatter options. |
387
- | `parallel` | `1` | Number of parallel workers. |
388
- | `dryRun` | `false` | Prepare test run without execution. |
389
- | `failFast` | `false` | Stop on first test failure. |
390
- | `forceExit` | `false` | Force `process.exit()` after tests. |
391
- | `strict` | `true` | Fail on pending steps. |
392
- | `backtrace` | `false` | Show full backtrace for errors. |
393
- | `tags` | `""` | Tag expression to filter scenarios. |
394
- | `name` | `[]` | Run scenarios matching regex. |
395
- | `order` | `"defined"` | Run order (defined/random). |
396
- | `language` | `"en"` | Default feature file language. |
397
- | `loader` | `[]` | Module loader specifications. |
398
- | `requireModule` | `[]` | Transpilation module names. |
399
- | `retry` | `0` | Retry attempts for failing tests. |
400
- | `retryTagFilter` | `""` | Tag expression for retries. |
401
- | `publish` | `false` | Publish to cucumber.io. |
402
- | `worldParameters` | `{}` | Custom world parameters. |
403
-
404
- ---
405
-
406
- ## 🌍 Environment Configuration
407
-
408
- | **Option** | **Default Value** | **Description** |
409
- | ---------- | ----------------- | ------------------------------------------------------------------------------------------------------------ |
410
- | `env` | `""` | Environment configuration. Should match the name with the baseURL object, like "dev" |
411
- | `baseURL` | `""` | Base URL for API requests. Can be object {"dev":"dev-api.com", "pre":"pre-api.com"}, or string "dev-api.com" |
412
-
413
-
414
- ### Environment Variables Configuration
415
-
416
- Artes supports environment-specific configurations through environment variables. This feature allows to manage different settings for environments.
417
-
418
- ### Setting Up Environment Variables
419
-
420
- 1. **Configure Environment in artes.config.js:**
421
- ```javascript
422
- module.exports = {
423
- baseURL: {
424
- dev: "https://dev.alma.az",
425
- pre: "https://pre.alma.az",
426
- prod: "https://api.alma.az"
427
- },
428
- env: "dev", // Specify which environment to use
429
- };
430
- ```
431
-
432
- **Alternative single URL configuration:**
433
- ```javascript
434
- module.exports = {
435
- baseURL: "https://api.alma.az", // Direct string URL
436
- };
437
- ```
438
-
439
- 2. **Create Environment Variable Files:**
440
- Create JSON files under `src/tests/environment_variables/` folder with names matching your environment:
441
-
442
- **dev.env.json:**
443
- ```json
444
- {
445
- "api_key": "dev-api-key-12345",
446
- "auth_token": "dev-auth-token",
447
- "database_url": "dev-db.example.com",
448
- "timeout": 5000,
449
- "headers": {
450
- "Authorization": "Bearer dev-token",
451
- "Content-Type": "application/json"
452
- }
453
- }
454
- ```
455
-
456
- ### How It Works
457
-
458
- 1. **Environment Detection:** When Artes runs, it reads the `env` value from `artes.config.js`
459
- 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
460
- 3. **Variable Loading:** Artes looks for a JSON file matching the environment name in `src/tests/environment_variables/`
461
- 4. **Runtime Access:** All variables from the environment file become available during test execution
462
-
463
- ### Important Notes
464
-
465
- - ⚠️ **Base URLs must be defined in `artes.config.js`** - they cannot be set in the environment variable JSON files
466
- - 📁 Environment variable files should be placed in `src/tests/environment_variables/`
467
- - 🏷️ File names must follow the format `{env}.env.json` (e.g., `dev.env.json` for `env: "dev"`)
468
- - 🔄 Variables are loaded into variable storage and can be accessed during test runs
469
- - 🌐 Use environment variables for headers, API keys, timeouts, and other environment-specific configurations
470
-
471
- ---
472
-
473
- ### Browser Configuration
474
-
475
- | Option | Default Value | Description |
476
- | ------------- | ------------------------------ | ------------------------------------------------------ |
477
- | `browserType` | `"chrome"` | Browser type (`"chrome"`, `"firefox"`, or `"webkit"`). |
478
- | `viewport` | `{ width: 1280, height: 720 }` | Browser viewport size. |
479
- | `headless` | `true` | Run browser in headless mode (`true` or `false`). |
480
-
481
- ## 📊 Report Generation
482
-
483
- Artes can generate Allure reports. After running tests with the `-r` flag, the reports will be stored in the `report` folder in HTML format. You can view them in your browser after the tests complete.
484
-
485
- ---
486
-
487
- ## 🐳 Docker Image for CI/CD
488
-
489
- A Docker image `vahidaghayev/artes` is available for running Artes in CI/CD pipelines. This image includes:
490
-
491
- - **Playwright Browsers**: Pre-installed to support UI testing.
492
- - **Xvfb**: Enables running UI tests with video recording in a virtual display.
493
-
494
- ### Recommended Settings for Best Quality
495
-
496
- To achieve the best video recording quality, use the following command:
497
-
498
- ```bash
499
- xvfb-run -a --server-args="-screen 0 3840x1180x24" --auto-servernum npx artes --width 1600 --height 900
500
- ```
501
-
502
- ---
503
-
504
- ## 👍 Good To Use
505
-
506
- If you don't use the -c or --create option that the package offers, save the file below under the `.vscode` folder:
507
-
508
- - Those configurations will help autocomplete both predefined and custom step definitions in your features file
509
-
510
- **extensions.json**
511
-
512
- ```json
513
- {
514
- "recommendations": ["CucumberOpen.cucumber-official"]
515
- }
516
- ```
517
-
518
- **settings.json**
519
-
520
- ```json
521
- {
522
- "cucumber.glue": [
523
- "tests/steps/*.{ts,js}",
524
- "node_modules/artes/src/tests/stepDefinitions/*.{ts,js}"
525
- ],
526
- "cucumber.features": ["tests/features/*.features"],
527
- "cucumberautocomplete.syncfeatures": true,
528
- "cucumberautocomplete.strictGherkinCompletion": true
529
- }
530
- ```
531
-
532
- ---
533
-
1
+ <p align="center">
2
+ <img alt="artesLogo" src="https://github.com/user-attachments/assets/e0641011-0e96-4330-8ad5-935b395b0838" width="280">
3
+ </p>
4
+
5
+ <h1 align="center">Artes</h1>
6
+
7
+ ## 🚀 Summary
8
+
9
+ Artes is a test runner for Playwright that executes [predefined Cucumber tests](./docs/stepDefinitions.md) and can generate Allure reports for test results. It simplifies setting up Playwright with Cucumber in your automation workflow. With Artes, you can easily run tests without writing step definitions, generate reports, and customize your testing environment.
10
+
11
+ ![artes demonstration](https://github.com/user-attachments/assets/c46172f7-103d-45d1-a37d-8d4267df0967)
12
+
13
+ ## 🧑‍💻 Installation
14
+
15
+ You can install **Artes** via npm. To install it globally**(RECOMMENDED)**, run the following command:
16
+
17
+ ```bash
18
+ npm install -g artes
19
+ ```
20
+
21
+ To install it locally in your project, run:
22
+
23
+ ```bash
24
+ npm install artes
25
+ ```
26
+
27
+ Once installed, you can run **Artes** using:
28
+
29
+ ```bash
30
+ npx artes [options]
31
+ ```
32
+
33
+ ---
34
+
35
+ ## 💡 Usage
36
+
37
+ **Artes** has following CLI options:
38
+
39
+ ```bash
40
+ npx artes [options]
41
+ ```
42
+
43
+ ### Options
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
+ | `--singleFileReport` | Generate single file allure report | ` artes -r --singleFileReport` |
56
+ | `--zip` | Zip the report folder after generation | ` artes -r --zip` |
57
+ | 📁 `--features` | Specify one or more feature files' relative paths to run (comma-separated) | `artes --features "tests/features/Alma,tests/features/Banan.feature"` |
58
+ | 📜 `--stepDef` | Specify one or more step definition files' relative paths to use (comma-separated) | `artes --stepDef "tests/steps/login.js,tests/steps/home.js"` |
59
+ | 🔖 `--tags` | Run tests with specified Cucumber tags | `artes --tags "@smoke or @wip"` |
60
+ | 🌐 `--env` | Set the environment for the test run | `artes --env "dev"` |
61
+ | 🕶️ `--headless` | Run browser in headless mode | `artes --headless` |
62
+ | ⚡ `--parallel` | Run tests in parallel mode | `artes --parallel 2` |
63
+ | 🔁 `--retry` | Retry failed tests | `artes --retry 3` |
64
+ | 🎭 `--dryRun` | Perform a dry run without executing tests | `artes --dryRun` |
65
+ | 📈 `--percentage` | Set minimum success percentage to pass test run (default is 0) | `artes --percentage 85` |
66
+ | 🌍 `--browser` | Specify browser to use (`chromium`, `firefox`, or `webkit`) | `artes --browser chromium` |
67
+ | 🔗 `--baseURL` | Set base URL for the tests | `artes --baseURL "https://example.com"` |
68
+ | 🖥️ `--maxScreen` | Maximize browser window on launch | `artes --maxScreen` |
69
+ | 📏 `--width` | Set browser width (default is 1280) | `artes --width 1920` |
70
+ | 📐 `--height` | Set browser height (default is 720) | `artes --height 1080` |
71
+ | ⏱️ `--timeout` | Set timeout for each test step in seconds (default is 30 seconds) | `artes --timeout 10` |
72
+ | 🐢 `--slowMo` | Slow down text execution for clear view (default: 0 seconds) | `artes --slowMo 1` |
73
+
74
+ \*\* To just run the tests: <br>
75
+ Globally: artes <br>
76
+ Locally: npx artes
77
+
78
+ ---
79
+
80
+ ## 🎯 Best Practices
81
+
82
+ - **Global Installation:**
83
+ For ease of use, it's recommended that Artes be installed globally. You can do this by running the following command:
84
+
85
+ ```bash
86
+ npm install -g artes
87
+ ```
88
+
89
+ - **Project Creation (Recommended):**
90
+ To create a new project with Artes, use the `-c` flag. This will automatically set up the folder structure and configuration for you. Run the command:
91
+
92
+ ```bash
93
+ artes -c
94
+ ```
95
+
96
+ 🗂️ Example Project Structure: <br/>
97
+ After running the `-c` flag to create a new project, the structure will look like this:
98
+
99
+ ```
100
+ /artes (Project Name)
101
+ /tests
102
+ /features
103
+ (Your feature files here)
104
+ /POMs // Optional
105
+ (POM JSON file here)
106
+ /steps // For custom steps
107
+ (Your step definition JS files here)
108
+ artes.config.js
109
+ /report
110
+ (Generated Allure report HTML here)
111
+ ```
112
+
113
+ **If you choose not to use the `-c` flag**, you can still download Artes to your testing project and use the prepared steps by running:
114
+
115
+ ```bash
116
+ npx artes
117
+ ```
118
+
119
+ You must customize the paths of features, steps, and other configurations by editing the `artes.config.js` file located inside your project folder (or create it).
120
+
121
+ For example:
122
+
123
+ ```javascript
124
+ module.exports = {
125
+ paths: ["tests/features/"], // Custom path for feature files
126
+ require: ["tests/steps/*.js"], // Custom path for step definitions files
127
+ pomPath: "tests/POMS/*.js", // Custom path for POM files
128
+ };
129
+ ```
130
+
131
+ ---
132
+
133
+ ## 📝 Writing Feature Files and POM Files
134
+
135
+ Artes simplifies your test writing with structured feature files and organized Page Object Models (POM). Here’s how you can create them:
136
+
137
+ ### 1. 📄 Feature File Structure
138
+
139
+ ```gherkin
140
+ Feature: Searching on Google 🔍
141
+ Scenario Outline: Search for a term on Google
142
+ Given User is on "https://www.google.com/" page
143
+ When User types "alma" in "google_search_input"
144
+ And User clicks "google_search_button"
145
+ And User waits 10 seconds
146
+ Then "google_text" should have "Alma" text
147
+ ```
148
+
149
+ - **Feature**: Describes the main feature being tested (e.g., Google search).
150
+ - **Scenario Outline**: Defines a test case with steps.
151
+ - **Steps**: Use `Given`, `When`, `And`, `Then` keywords to describe actions and expectations.
152
+ - **Selectors**: The element names (e.g., `google_search_input`, `google_search_button`) map to the POM file or can be defined directly.
153
+
154
+ ### 2. 📂 POM File Example
155
+
156
+ ```json
157
+ {
158
+ "google_search_input": { "selector": "#APjFqb" },
159
+ "google_search_button": {
160
+ "selector": "input.gNO89b"
161
+ },
162
+ "google_text": {
163
+ "selector": "#rso div h3",
164
+ "waitTime": 5 //seconds
165
+ }
166
+ }
167
+ ```
168
+
169
+ - 📑 Using POM File is optional but it is **RECOMMENDED**
170
+ - 🔗 Using Selector in Feature File is possible
171
+ ```gherkin
172
+ When User types "alma" in "#APjFqb"
173
+ ```
174
+ - 🐍 It is good to use snake_case for element names
175
+ - ⏳ "waitTime" is to define custom wait for elements, but the feature currently under development
176
+ "selector" must be used if "waitTime" is used, but when using only selector is not needed mention in "selector"
177
+
178
+ ---
179
+
180
+ ## 🛠️ Customization
181
+
182
+ ## ✍️ Writing Custom Step Definitions
183
+
184
+ Artes allows you to extend its functionality by writing custom step definitions. Here's how you can do it:
185
+
186
+ ### Import Required APIs
187
+
188
+ ```javascript
189
+ const {
190
+ expect,
191
+ Given,
192
+ When,
193
+ Then,
194
+ element,
195
+ context,
196
+ keyboard,
197
+ mouse,
198
+ frame,
199
+ assert,
200
+ elementInteractions,
201
+ } = require("artes"); // Common JS
202
+ import { expect, Given, When, Then, element, context } from "artes"; // ES Modules (Do not RECOMMENDED)
203
+ ```
204
+
205
+ - **`Given`, `When`, `Then`**: These define your steps in Cucumber syntax. Example:
206
+
207
+ ```javascript
208
+ Given("User is on the login page", async () => {
209
+ await context.page.navigateTo("https://example.com/login");
210
+ });
211
+ ```
212
+
213
+ - **`page`**: Provides higher-level page actions such as navigation and waiting(Same as PlayWright). Examples:
214
+ - Navigate to a URL:
215
+ ```javascript
216
+ await context.page.navigate("https://example.com");
217
+ ```
218
+ - Wait for a selector:
219
+ ```javascript
220
+ await context.page.waitForSelector("#loadingSpinner");
221
+ ```
222
+ - **`request`**: Use for sending HTTP requests. _(Note: This feature is currently under development.)_
223
+
224
+ - **`element`**: Use for interacting with elements on the web page. Examples:
225
+ - Clicking a button:
226
+ ```javascript
227
+ await element("#submitButton").click();
228
+ ```
229
+ - Filling an input:
230
+ ```javascript
231
+ await element("#username").fill("testUser");
232
+ ```
233
+ - **`expect`**: Use for assertions in your steps. For example:
234
+ ```javascript
235
+ expect(actualValue).toBe(expectedValue);
236
+ expect(element("Page_Title")).toHaveText(expectedValue);
237
+ ```
238
+
239
+ ## 📋 Simplified Functions
240
+
241
+ If you don't want to deal with Playwright methods directly, you can simply use the following predefined actions methods by import them:
242
+
243
+ ```javascript
244
+ const { mouse, keyboard, frame, elementInteractions, page } = require("artes");
245
+ ```
246
+
247
+ - **Mouse Actions:**
248
+ `mouse.click(element)`
249
+
250
+ - **Keyboard Actions:**
251
+ `keyboard.press(key)`
252
+
253
+ - **Element Interactions:**
254
+ `elementInteractions.isChecked()`
255
+
256
+ - **Assertions:**
257
+ `assert.shouldBeTruthy(element)`
258
+
259
+ - **Frame Actions:**
260
+ `frame.first()`
261
+
262
+ - **API Actions:**
263
+ `api.post(url, payload, requestDataType)`
264
+
265
+ ---
266
+
267
+ For a detailed explanation of each function, please refer to the [function definitions](./docs/functionDefinitions.md).
268
+
269
+ ---
270
+
271
+ ### Example of Custom Step Definition
272
+
273
+ ```javascript
274
+ const { Given, When, Then, expect, element, page } = require("artes");
275
+
276
+ Given("User is on the home page", async () => {
277
+ await page.navigate("https://example.com");
278
+ });
279
+
280
+ When("User clicks the login button", async () => {
281
+ await element("#loginButton").click();
282
+ });
283
+
284
+ Then("User should see the login form", async () => {
285
+ expect(element("#loginForm")).toBeVisible(true);
286
+ });
287
+ ```
288
+
289
+ ## 🪝 Hooks (Lifecycle Hooks)
290
+
291
+ Artes supports **hooks** that allow you to execute custom logic **before and after tests, scenarios, and steps**.
292
+
293
+ Hooks are **user-defined**.
294
+
295
+ ---
296
+
297
+ ### 📁 Hooks File Location
298
+
299
+ Create the following file **inside your project** (optional):
300
+ ```
301
+ tests/steps/hooks.js
302
+ ```
303
+
304
+ ---
305
+
306
+ ### ✍️ Writing Hooks
307
+
308
+ You can define **only the hooks you need** in hooks.js under the steps folder.
309
+ Undefined hooks are automatically skipped.
310
+ ```js
311
+ // tests/steps/hooks.js
312
+
313
+ export function BeforeStep() {
314
+ // hook for before each step
315
+ }
316
+
317
+ export function Before() {
318
+ // hook for before each test
319
+ }
320
+
321
+ export function BeforeAll() {
322
+ // hook for before all tests
323
+ }
324
+
325
+ export function AfterStep() {
326
+ // hook for after each step
327
+ }
328
+
329
+ export function After() {
330
+ // hook for after each test
331
+ }
332
+
333
+ export function AfterAll() {
334
+ // hook for after all tests
335
+ }
336
+ ```
337
+
338
+ ---
339
+
340
+ ### 🔁 Supported Hook Types
341
+
342
+ | Hook Name | Execution Time |
343
+ | ------------ | ----------------------------- |
344
+ | `BeforeAll` | Once before **all scenarios** |
345
+ | `Before` | Before **each scenario** |
346
+ | `BeforeStep` | Before **each step** |
347
+ | `AfterStep` | After **each step** |
348
+ | `After` | After **each scenario** |
349
+ | `AfterAll` | Once after **all scenarios** |
350
+
351
+ ---
352
+
353
+ ### ▶️ Execution Order Example
354
+
355
+ For a scenario with steps:
356
+ ```
357
+ BeforeAll
358
+ Before
359
+ BeforeStep
360
+ (step executes)
361
+ AfterStep
362
+ After
363
+ AfterAll
364
+ ```
365
+
366
+ ---
367
+
368
+ ## ⚙️ Configuration
369
+
370
+ You can configure Artes by editing the `artes.config.js` file. Below are the default configuration options with explanations:
371
+
372
+ | **Option** | **Default Value** | **Description** |
373
+ | ----------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------- |
374
+ | `timeout` | `30` | Default timeout in seconds. |
375
+ | `slowMo` | `0` | Default slow motion in seconds |
376
+ | `paths` | `[moduleConfig.featuresPath]` | Paths to feature files. |
377
+ | `require` | `[moduleConfig.stepsPath, "src/stepDefinitions/*.js", "src/hooks/hooks.js"]` | Support code paths (CommonJS). |
378
+ | `pomPath` | `moduleConfig.pomPath` | Path to Page Object Models. |
379
+ | `import` | `[]` | Support code paths. |
380
+ | `testPercentage` | `0` | Define test coverage percentage |
381
+ | `report` | `false` | Generate report |
382
+ | `reportSuccess` | `false` | Add screenshots and video records for also success test cases |
383
+ | `trace` | `false` | Enable trace |
384
+ | `reportWithTrace` | `false` | Add trace to the report |
385
+ | `format` | `["rerun:@rerun.txt", "allure-cucumberjs/reporter"]` | Formatter names/paths. |
386
+ | `formatOptions` | `{ "resultsDir": "allure-result" }` | Formatter options. |
387
+ | `parallel` | `1` | Number of parallel workers. |
388
+ | `dryRun` | `false` | Prepare test run without execution. |
389
+ | `failFast` | `false` | Stop on first test failure. |
390
+ | `forceExit` | `false` | Force `process.exit()` after tests. |
391
+ | `strict` | `true` | Fail on pending steps. |
392
+ | `backtrace` | `false` | Show full backtrace for errors. |
393
+ | `tags` | `""` | Tag expression to filter scenarios. |
394
+ | `name` | `[]` | Run scenarios matching regex. |
395
+ | `order` | `"defined"` | Run order (defined/random). |
396
+ | `language` | `"en"` | Default feature file language. |
397
+ | `loader` | `[]` | Module loader specifications. |
398
+ | `requireModule` | `[]` | Transpilation module names. |
399
+ | `retry` | `0` | Retry attempts for failing tests. |
400
+ | `retryTagFilter` | `""` | Tag expression for retries. |
401
+ | `publish` | `false` | Publish to cucumber.io. |
402
+ | `worldParameters` | `{}` | Custom world parameters. |
403
+
404
+ ---
405
+
406
+ ## 🌍 Environment Configuration
407
+
408
+ | **Option** | **Default Value** | **Description** |
409
+ | ---------- | ----------------- | ------------------------------------------------------------------------------------------------------------ |
410
+ | `env` | `""` | Environment configuration. Should match the name with the baseURL object, like "dev" |
411
+ | `baseURL` | `""` | Base URL for API requests. Can be object {"dev":"dev-api.com", "pre":"pre-api.com"}, or string "dev-api.com" |
412
+
413
+
414
+ ### Environment Variables Configuration
415
+
416
+ Artes supports environment-specific configurations through environment variables. This feature allows to manage different settings for environments.
417
+
418
+ ### Setting Up Environment Variables
419
+
420
+ 1. **Configure Environment in artes.config.js:**
421
+ ```javascript
422
+ module.exports = {
423
+ baseURL: {
424
+ dev: "https://dev.alma.az",
425
+ pre: "https://pre.alma.az",
426
+ prod: "https://api.alma.az"
427
+ },
428
+ env: "dev", // Specify which environment to use
429
+ };
430
+ ```
431
+
432
+ **Alternative single URL configuration:**
433
+ ```javascript
434
+ module.exports = {
435
+ baseURL: "https://api.alma.az", // Direct string URL
436
+ };
437
+ ```
438
+
439
+ 2. **Create Environment Variable Files:**
440
+ Create JSON files under `src/tests/environment_variables/` folder with names matching your environment:
441
+
442
+ **dev.env.json:**
443
+ ```json
444
+ {
445
+ "api_key": "dev-api-key-12345",
446
+ "auth_token": "dev-auth-token",
447
+ "database_url": "dev-db.example.com",
448
+ "timeout": 5000,
449
+ "headers": {
450
+ "Authorization": "Bearer dev-token",
451
+ "Content-Type": "application/json"
452
+ }
453
+ }
454
+ ```
455
+
456
+ ### How It Works
457
+
458
+ 1. **Environment Detection:** When Artes runs, it reads the `env` value from `artes.config.js`
459
+ 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
460
+ 3. **Variable Loading:** Artes looks for a JSON file matching the environment name in `src/tests/environment_variables/`
461
+ 4. **Runtime Access:** All variables from the environment file become available during test execution
462
+
463
+ ### Important Notes
464
+
465
+ - ⚠️ **Base URLs must be defined in `artes.config.js`** - they cannot be set in the environment variable JSON files
466
+ - 📁 Environment variable files should be placed in `src/tests/environment_variables/`
467
+ - 🏷️ File names must follow the format `{env}.env.json` (e.g., `dev.env.json` for `env: "dev"`)
468
+ - 🔄 Variables are loaded into variable storage and can be accessed during test runs
469
+ - 🌐 Use environment variables for headers, API keys, timeouts, and other environment-specific configurations
470
+
471
+ ---
472
+
473
+ ### Browser Configuration
474
+
475
+ | Option | Default Value | Description |
476
+ | ------------- | ------------------------------ | ------------------------------------------------------ |
477
+ | `browserType` | `"chrome"` | Browser type (`"chrome"`, `"firefox"`, or `"webkit"`). |
478
+ | `viewport` | `{ width: 1280, height: 720 }` | Browser viewport size. |
479
+ | `headless` | `true` | Run browser in headless mode (`true` or `false`). |
480
+
481
+ ## 📊 Report Generation
482
+
483
+ Artes can generate Allure reports. After running tests with the `-r` flag, the reports will be stored in the `report` folder in HTML format. You can view them in your browser after the tests complete.
484
+
485
+ ---
486
+
487
+ ## 🐳 Docker Image for CI/CD
488
+
489
+ A Docker image `vahidaghayev/artes` is available for running Artes in CI/CD pipelines. This image includes:
490
+
491
+ - **Playwright Browsers**: Pre-installed to support UI testing.
492
+ - **Xvfb**: Enables running UI tests with video recording in a virtual display.
493
+
494
+ ### Recommended Settings for Best Quality
495
+
496
+ To achieve the best video recording quality, use the following command:
497
+
498
+ ```bash
499
+ xvfb-run -a --server-args="-screen 0 3840x1180x24" --auto-servernum npx artes --width 1600 --height 900
500
+ ```
501
+
502
+ ---
503
+
504
+ ## 👍 Good To Use
505
+
506
+ If you don't use the -c or --create option that the package offers, save the file below under the `.vscode` folder:
507
+
508
+ - Those configurations will help autocomplete both predefined and custom step definitions in your features file
509
+
510
+ **extensions.json**
511
+
512
+ ```json
513
+ {
514
+ "recommendations": ["CucumberOpen.cucumber-official"]
515
+ }
516
+ ```
517
+
518
+ **settings.json**
519
+
520
+ ```json
521
+ {
522
+ "cucumber.glue": [
523
+ "tests/steps/*.{ts,js}",
524
+ "node_modules/artes/src/tests/stepDefinitions/*.{ts,js}"
525
+ ],
526
+ "cucumber.features": ["tests/features/*.features"],
527
+ "cucumberautocomplete.syncfeatures": true,
528
+ "cucumberautocomplete.strictGherkinCompletion": true
529
+ }
530
+ ```
531
+
532
+ ---
533
+
534
534
  ## 🧑‍💻 Have a Good Testing