Skip to content

Commit 9ca617a

Browse files
update guides (#100)
1 parent 91f079d commit 9ca617a

File tree

12 files changed

+1424
-269
lines changed

12 files changed

+1424
-269
lines changed

versioned_docs/version-2x/Formatters/console-formatter.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ npm install @qavajs/console-formatter
1414
## Configuration
1515
To use formatter just add formatter section in config file
1616

17-
```javascript
18-
module.exports = {
19-
default: {
20-
format: ['@qavajs/console-formatter'],
21-
formatOptions: {
22-
console: {
23-
showLogs: true, //show cucumber logs. Default - false
24-
showProgress: true //show progress bar. Default - false
25-
}
26-
},
27-
}
17+
```typescript
18+
export default {
19+
format: ['@qavajs/console-formatter'],
20+
formatOptions: {
21+
console: {
22+
showLogs: true, //show cucumber logs. Default - false
23+
showProgress: true //show progress bar. Default - false
24+
}
25+
},
26+
}
2827
}
2928
```
3029

versioned_docs/version-2x/Formatters/html-formatter.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ npm install @qavajs/html-formatter
1414
## Configuration
1515
Add to formatter section in config file
1616

17-
```javascript
18-
module.exports = {
19-
default: {
20-
format: [
21-
['@qavajs/html-formatter', 'report.html']
22-
],
23-
formatOptions: {
24-
htmlConfig: {
25-
metadata: {
26-
'OS': 'macos',
27-
'OS Version': '13.1'
28-
}
17+
```typescript
18+
export default {
19+
format: [
20+
['@qavajs/html-formatter', 'report.html']
21+
],
22+
formatOptions: {
23+
htmlConfig: {
24+
metadata: {
25+
'OS': 'macos',
26+
'OS Version': '13.1'
2927
}
3028
}
3129
}

versioned_docs/version-2x/Formatters/report-portal.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,26 @@ npm install @qavajs/format-report-portal
1414

1515
Add formatter to config.js
1616
```javascript
17-
module.exports = {
18-
default: {
19-
format: [
20-
['@qavajs/format-report-portal', 'report/rp.out']
21-
],
22-
formatOptions: {
23-
rpConfig: {
24-
enable: true,
25-
debug: false,
26-
apiKey: 'your token',
27-
endpoint: 'https://your-rp-instance/api/v1',
28-
description: 'Description',
29-
tags: ['Tag'],
30-
project: 'your project',
31-
launch: 'your launch name',
32-
mode: 'DEFAULT',
33-
retry: 1, // number of retries to send result to report portal (default - 1)
34-
ignoreErrors: false, // ignore RP errors (default: false)
35-
showLaunchURL: true, // log report portal launch link,
36-
tagsAsAttributes: true // (default: false → tags go to description)
37-
},
38-
}
17+
export default {
18+
format: [
19+
['@qavajs/format-report-portal', 'report/rp.out']
20+
],
21+
formatOptions: {
22+
rpConfig: {
23+
enable: true,
24+
debug: false,
25+
apiKey: 'your token',
26+
endpoint: 'https://your-rp-instance/api/v1',
27+
description: 'Description',
28+
tags: ['Tag'],
29+
project: 'your project',
30+
launch: 'your launch name',
31+
mode: 'DEFAULT',
32+
retry: 1, // number of retries to send result to report portal (default - 1)
33+
ignoreErrors: false, // ignore RP errors (default: false)
34+
showLaunchURL: true, // log report portal launch link,
35+
tagsAsAttributes: true // (default: false → tags go to description)
36+
},
3937
}
4038
}
4139
```

versioned_docs/version-2x/Guides/memory.mdx

Lines changed: 134 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,134 +5,196 @@ sidebar_position: 1
55
import Tabs from '@theme/Tabs';
66
import TabItem from '@theme/TabItem';
77

8-
# Memory
9-
Framework provides the capability to transit variables between step and access them from gherkin definitions
8+
# Test Data Management
9+
10+
The `@qavajs/memory` module provides powerful capabilities to store, retrieve, and manipulate variables between test steps. This allows you to create more dynamic and data-driven test scenarios.
11+
12+
## Basic Usage
13+
14+
Memory allows you to save values during test execution and reference them later:
1015

1116
```gherkin
12-
When I save text of 'Answer' to equal 'answer'
13-
Then I expect text of 'Another Answer' to equal '$answer'
17+
When I save text of 'Answer' as 'userAnswer'
18+
Then I expect text of 'Another Answer' to equal '$userAnswer'
1419
```
1520

16-
### Memory value parameter type
17-
`value` parameter type provides API to access memory
21+
## Memory API
22+
23+
### Using the Memory Value Parameter Type
24+
All built-in steps can consume memory params.
25+
26+
```gherkin
27+
Then I expect text of 'Title' to equal '$userAnswer'
28+
```
29+
30+
The `value` parameter type provides a strongly-typed API to access memory and can be used in custom step:
1831

1932
```typescript
33+
// Reading from memory
2034
When('Read memory {value}', async function(memoryValue) {
21-
expect(memoryValue.value()).to.equal('ts');
35+
// memoryValue.value() retrieves the actual value from memory
36+
expect(memoryValue.value()).to.equal('stored value');
2237
});
2338

39+
// Writing to memory
2440
When('Set memory {value} as {string}', async function(memoryKey, value) {
41+
// memoryKey.set() stores a value in memory
2542
memoryKey.set(value);
2643
});
2744
```
2845

29-
### Custom steps
30-
Memory value can be set and read from memory object
46+
### Direct Memory Access in Custom Steps
47+
48+
You can also access the memory object directly in your step definitions:
3149

3250
<Tabs>
3351
<TabItem value="js" label="JavaScript" default>
3452
```javascript
3553
const memory = require('@qavajs/memory');
3654

37-
When(/^save variable as '(.+)'$/, async function (key) {
38-
memory.setValue(key, 42);
55+
When(/^I save value '(.+)' as '(.+)'$/, async function (value, key) {
56+
memory.setValue(key, value);
3957
});
4058

41-
Then(/^value '(.+)' should be equal to '(.+)'$/, async function (variable1, variable2) {
42-
const val = memory.getValue(variable1);
43-
expect(val).to.equal(variable2);
59+
Then(/^value in '(.+)' should equal '(.+)'$/, async function (variable, expectedValue) {
60+
const actualValue = memory.getValue(variable);
61+
expect(actualValue).to.equal(expectedValue);
4462
});
4563
```
4664
</TabItem>
4765
<TabItem value="ts" label="TypeScript">
4866
```typescript
49-
import memory = from '@qavajs/memory';
67+
import memory from '@qavajs/memory';
5068

51-
When(/^save variable as '(.+)'$/, async function (key: string) {
52-
memory.setValue(key, 42);
69+
When(/^I save value '(.+)' as '(.+)'$/, async function (value: string, key: string) {
70+
memory.setValue(key, value);
5371
});
5472

55-
Then(/^value '(.+)' should be equal to '(.+)'$/, async function (variable1: string, variable2: string) {
56-
const val = memory.getValue(variable1);
57-
expect(val).to.equal(variable2);
73+
Then(/^value in '(.+)' should equal '(.+)'$/, async function (variable: string, expectedValue: string) {
74+
const actualValue = memory.getValue(variable);
75+
expect(actualValue).to.equal(expectedValue);
5876
});
5977
```
6078
</TabItem>
6179
</Tabs>
6280

81+
In your Gherkin scenarios, you can access previously saved variables using the `$` prefix:
82+
6383
```gherkin
64-
When save variable as 'variable'
65-
# previously saved variable can be accessed via $identifier
66-
Then value of '$variable' should be equal to '42'
84+
When I save value '42' as 'myNumber'
85+
Then value in 'myNumber' should equal '42'
86+
And I expect text of 'Result Field' to equal '$myNumber'
6787
```
6888

69-
### Constants and computed
89+
## Advanced Features
7090

71-
Lib provides capability to set constant values and computed (JavaScript function references that can be called from feature file)
91+
### Constants and Computed Values
92+
93+
You can define constant values and computed functions that can be referenced in your feature files:
7294

7395
<Tabs>
7496
<TabItem value="js" label="JavaScript" default>
7597
```javascript
98+
// memory.js
7699
module.exports = {
77-
constant: 42,
78-
computed: function() {
79-
return Date.now()
100+
// Constants
101+
maxRetries: 3,
102+
baseUrl: 'https://example.com',
103+
104+
// Computed values (functions that return dynamic values)
105+
timestamp: function() {
106+
return Date.now();
107+
},
108+
randomUsername: function() {
109+
return 'user_' + Math.floor(Math.random() * 10000);
80110
}
81111
};
82112
```
83113
</TabItem>
84114
<TabItem value="ts" label="TypeScript">
85115
```typescript
116+
// memory.ts
86117
export default {
87-
constant: 42,
88-
computed: function() {
89-
return Date.now()
118+
// Constants
119+
maxRetries: 3,
120+
baseUrl: 'https://example.com',
121+
122+
// Computed values (functions that return dynamic values)
123+
timestamp: function() {
124+
return Date.now();
125+
},
126+
randomUsername: function() {
127+
return 'user_' + Math.floor(Math.random() * 10000);
90128
}
91129
};
92130
```
93131
</TabItem>
94132
</Tabs>
95133

134+
Reference these values in your Gherkin scenarios:
135+
96136
```gherkin
97-
Then I expect text of 'Answer' to equal '$constant'
98-
Then I expect text of 'What Time Is It' to equal '$computed()'
137+
# Using constants
138+
Then I expect retry count to be '$maxRetries'
139+
When I navigate to '$baseUrl/login'
140+
141+
# Using computed values
142+
Then I expect registration timestamp to be '$timestamp()'
143+
When I register with username '$randomUsername()'
99144
```
100145

101-
### String interpolation
102-
Module also provides capability to use string interpolation in your Gherkin scenarios
146+
### String Interpolation
147+
148+
Use curly braces to interpolate memory values within strings:
149+
103150
```gherkin
104-
When I save '42' to memory as 'variable'
105-
Then I expect text of 'Answer' to equal 'answer is {$variable}' #expected value will be 'answer is 42'
151+
When I save '42' as 'score'
152+
Then I expect text of 'Result' to equal 'Your score is {$score} points'
106153
```
107154

108-
### $js
109-
Built-in `$js` computed provides a way to execute JavaScript code.
155+
### Built-in JavaScript Execution with $js
156+
157+
Use the built-in `$js` computed function to execute JavaScript code directly from your Gherkin scenarios:
110158

111159
```gherkin
112-
When I expect text of 'Current Date' to equal '$js(Date.now())'
160+
# Math operations
161+
When I expect the result to equal '$js(42 * 2.5)'
162+
163+
# String manipulation
164+
Then I expect the username to be '$js("user_" + Math.floor(Math.random() * 1000))'
165+
166+
# Date formatting
167+
And I expect the date format to be '$js(new Date().toLocaleDateString())'
113168
```
114169

115-
### Escape $
116-
`$` can be escaped with double backslash
170+
### Escaping the $ Symbol
171+
172+
When you need to use a literal `$` character in your tests, escape it with a double backslash:
117173

118-
```Gherkin
119-
When I expect text of 'Currency Label' to equal '\\$42'
174+
```gherkin
175+
When I expect the price to be '\\$42.99'
176+
# This will expect the actual text to be "$42.99"
120177
```
121178

122-
### Parallel
123-
In case you need to assign uniq value for each Cucumber thread you can use parallel function.
124-
It will assign value based on `CUCUMBER_WORKER_ID` env variable.
179+
### Parallel Execution Support
180+
181+
For parallel test execution, you can assign unique values for each Cucumber thread using the `parallel` function:
125182

126183
<Tabs>
127184
<TabItem value="js" label="JavaScript" default>
128185
```javascript
129186
const { parallel } = require('@qavajs/memory/utils');
130187

131188
class Memory {
132-
user = parallel([
133-
{ username: 'user1', password: 'password' },
134-
{ username: 'user2', password: 'password' }
189+
// Each parallel thread will get a different user from this array
190+
testUser = parallel([
191+
{ username: 'user1@example.com', password: 'password1' },
192+
{ username: 'user2@example.com', password: 'password2' },
193+
{ username: 'user3@example.com', password: 'password3' }
135194
]);
195+
196+
// You can also use parallel with primitive values
197+
port = parallel([8080, 8081, 8082]);
136198
}
137199

138200
module.exports = Memory;
@@ -143,12 +205,31 @@ It will assign value based on `CUCUMBER_WORKER_ID` env variable.
143205
import { parallel } from '@qavajs/memory/utils';
144206

145207
export class Memory {
146-
user = parallel([
147-
{ username: 'user1', password: 'password' },
148-
{ username: 'user2', password: 'password' }
208+
// Each parallel thread will get a different user from this array
209+
testUser = parallel([
210+
{ username: 'user1@example.com', password: 'password1' },
211+
{ username: 'user2@example.com', password: 'password2' },
212+
{ username: 'user3@example.com', password: 'password3' }
149213
]);
214+
215+
// You can also use parallel with primitive values
216+
port = parallel([8080, 8081, 8082]);
150217
}
151218
```
152219
</TabItem>
153220
</Tabs>
154221

222+
Use these values in your scenarios:
223+
224+
```gherkin
225+
When I login with username '$testUser.username' and password '$testUser.password'
226+
And I connect to port '$port'
227+
```
228+
229+
## Best Practices
230+
231+
1. **Use descriptive names** for your memory variables to make scenarios more readable
232+
2. **Prefer string interpolation** for complex strings rather than concatenating multiple parts
233+
3. **Create reusable computed functions** for common operations or data generation
234+
4. **Use TypeScript interfaces** to define the structure of complex memory objects
235+
5. **Document memory constants and functions** for better team collaboration

0 commit comments

Comments
 (0)