Skip to content

Commit b72a1cd

Browse files
added docs for core features (#93)
1 parent a33501b commit b72a1cd

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

docs/intro.md

+174
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,179 @@ If you have the basic config `npx qavajs` will launch test execution.
4747
To specify custom path to the config file use `npx qavajs run --config <config>`.
4848
In case if your config exports an object with multiple properties, you can specify which property to read `npx qavajs run --profile <profile>`.
4949

50+
### 🛠️ Override memory values
51+
In case if tests need to be run with updated memory value they can be passed via CLI (e.g run scenarios on some other url)
52+
It can be done by passing `--memory-values` parameter which is JSON with params that need to be overridden.
53+
For instance, to override `$url` value:
54+
55+
```bash
56+
npx qavajs run --config config.ts --memory-values '{"url": "https://github.com"}'
57+
```
58+
59+
### 🛠️ Pass CLI params to workers
60+
All params that you passed to qavajs cli will be available in `CLI_ARGV` environment variable in all child workers.
61+
62+
### 🛠️ Memory value parameter type
63+
`value` parameter type provides API to access memory
64+
65+
```typescript
66+
When('Read memory {value}', async function(memoryValue) {
67+
expect(memoryValue.value()).to.equal('ts');
68+
});
69+
70+
When('Set memory {value} as {string}', async function(memoryKey, value) {
71+
memoryKey.set(value);
72+
});
73+
```
74+
75+
### 🛠️ Validation parameter type
76+
`validation` parameter type provides API to verify values by certain condition
77+
78+
```typescript
79+
When('I expect {string} {validation} {string}', async function(value1, validate, value2) {
80+
validate(value1, value2);
81+
});
82+
```
83+
84+
### 🛠️ Test Sharding
85+
qavajs provides ability to shard your tests between different machines. To do so pass `--shard x/y` parameter in CLI,
86+
where x - current shard, y - total number of shards.
87+
88+
```
89+
npx qavajs run --config config.js --shard 1/2
90+
npx qavajs run --config config.js --shard 2/2
91+
```
92+
93+
### 🛠️ Execute steps from other steps
94+
It is possible to implement complex logic using built-in qavajs steps via `executeStep` world method
95+
```typescript
96+
When('I do smth complex', async function() {
97+
await this.executeStep(`I type 'username' to 'Username Input'`);
98+
await this.executeStep(`I type 'password' to 'Password Input'`);
99+
await this.executeStep(`I click 'Login Button'`);
100+
await this.executeStep(`I fill following fields`, new DataTable([
101+
[ 'Order', '123' ],
102+
[ 'Delivery Location', 'New York' ]
103+
]))
104+
});
105+
```
106+
107+
### 🛠️ World
108+
Module extends CucumberJS world with additional entities
109+
110+
| entity | type | description | example |
111+
|-------------|----------|--------------------------------------------------|--------------------------------------------------------------------|
112+
| config | object | loaded config | `this.config.parallel` |
113+
| executeStep | function | programmatically execute certain step definition | `await this.executeStep("I type 'username' to 'Username Input'");` |
114+
| setValue | function | set memory value | `await this.setValue('key', 'value');` |
115+
| getValue | function | get memory value or expression | `await this.getValue('$key');` |
116+
| validation | function | get validation function based | `await this.getValue('to equal');` |
117+
118+
### 🛠️ Override step definition
119+
`Override` function provides capability to override step implementation and avoid ambiguous exception
120+
121+
```typescript
122+
import { Override } from '@qavajs/core';
123+
124+
When('I do test', async function () {});
125+
126+
Override('I do test', async function () {
127+
console.log('I am overridden');
128+
});
129+
```
130+
131+
### 🛠️ Fixture
132+
`Fixture` provides convenient way to prepare test environment for specific test.
133+
134+
This example will open pdp page before test and clean cart after test
135+
```typescript
136+
import { Fixture } from '@qavajs/core';
137+
138+
Fixture('pdp', async function() {
139+
await this.playwright.page.goto('https://my-site/pdp');
140+
// fixture may return function that will be executed after test
141+
return async function() {
142+
await this.playwright.page.request.get('/cleanCart');
143+
}
144+
});
145+
```
146+
147+
```gherkin
148+
Feature: feature with fixture
149+
150+
@pdp
151+
Scenario: scenario with fixture
152+
When I click 'qavajs T-shirt'
153+
And I click 'cart icon'
154+
Then I expect 'qavajs T-shirt cart item' to be visible
155+
```
156+
157+
### 🛠️ Template
158+
`Template` provides a way to define step definition using Gherkin language
159+
160+
```typescript
161+
import { When, Template } from '@qavajs/core';
162+
163+
When('I click {string} and verify {string}', Template((locator, expected) => `
164+
I click '${locator}'
165+
I expect '${locator} > Value' to equal '${expected}'
166+
`));
167+
```
168+
169+
### 🛠️ Test Execution Hooks
170+
`BeforeExecution` and `AfterExecution` allow to define hooks that will be executed
171+
once before/after whole test execution
172+
173+
```typescript
174+
import { BeforeExecution, AfterExecution } from '@qavajs/core';
175+
import { Server } from './server';
176+
177+
const server = new Server();
178+
179+
BeforeExecution(async function () {
180+
await server.start();
181+
});
182+
183+
AfterExecution(async function () {
184+
await server.stop();
185+
});
186+
```
187+
188+
### 🛠️ Service
189+
Services is an entities that can execute logic before and after whole test run.
190+
191+
```typescript
192+
import externalService from './externalService';
193+
194+
export default {
195+
service: [
196+
{
197+
options: {
198+
data: 42
199+
},
200+
before() {
201+
console.log(this.options.data);
202+
},
203+
after(result) {
204+
if (!result.success) process.exitCode = 1;
205+
}
206+
},
207+
{
208+
options: {
209+
data: 42
210+
},
211+
...externalService
212+
}
213+
]
214+
}
215+
```
216+
There is a one minute-long default timeout for a before and after test logic to prevent entire process from freezing.
217+
To set up a custom timeout in milliseconds use serviceTimeout property in the config file
218+
```typescript
219+
export default {
220+
serviceTimeout: 1_200_000
221+
}
222+
```
223+
50224
### 📘 Extra
51225
[Code Examples](https://github.com/qavajs/demo)

0 commit comments

Comments
 (0)