Skip to content

Commit 2415093

Browse files
added docs for custom steps (#103)
1 parent 7d08a94 commit 2415093

File tree

6 files changed

+72
-27
lines changed

6 files changed

+72
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Option `enable` is set to `true` even if it is not defined explicitly in rpConfi
4242
## Test Level Attributes
4343
Test level attributes can be added via cucumber logs e.g. in Before hook
4444
```javascript
45-
const { Before } = require('@cucumber/cucumber');
45+
const { Before } = require('@qavajs/core');
4646

4747
Before(function () {
4848
this.log('log from before'); //just log

versioned_docs/version-2x/Guides/composing-steps.mdx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,40 @@ import TabItem from '@theme/TabItem';
77

88
# Composing Steps
99

10-
### executeStep
10+
## Custom Steps
11+
qavajs is based on `@cucumber/cucumber` package so you can use `Given`, `When`, `Then` functions
12+
enhanced by qavajs parameter types.
13+
14+
<Tabs>
15+
<TabItem value="js" label="JavaScript">
16+
```javascript
17+
const { When } = require('@qavajs/core');
18+
19+
When('I select {value} option from {playwrightLocator}', async function(option, locator) {
20+
await locator.selectOption(await option.value());
21+
});
22+
```
23+
</TabItem>
24+
<TabItem value="ts" label="TypeScript" default default>
25+
```typescript
26+
import { When } from '@qavajs/core';
27+
import type { Locator } from '@playwright/test';
28+
29+
When('I select {value} option from {playwrightLocator}', async function(option: MemoryValue, locator: Locator) {
30+
await locator.selectOption(await option.value());
31+
});
32+
```
33+
</TabItem>
34+
</Tabs>
35+
36+
## executeStep
1137
Framework provides capability to implement complex logic via `executeStep` world method
1238
that allow to call gherkin definitions programmatically
1339

1440
<Tabs>
15-
<TabItem value="js" label="JavaScript" default>
41+
<TabItem value="js" label="JavaScript">
1642
```javascript
17-
const { When, DataTable } = require('@cucumber/cucumber');
43+
const { When, DataTable } = require('@qavajs/core');
1844

1945
When('I do smth complex', async function() {
2046
await this.executeStep(`I type 'username' to 'Username Input'`);
@@ -23,14 +49,13 @@ that allow to call gherkin definitions programmatically
2349
await this.executeStep(`I fill following fields`, new DataTable([
2450
[ 'Order', '123' ],
2551
[ 'Delivery Location', 'New York' ]
26-
]))
52+
]));
2753
});
2854
```
2955
</TabItem>
30-
<TabItem value="ts" label="TypeScript">
56+
<TabItem value="ts" label="TypeScript" default default>
3157
```typescript
32-
import { IQavajsWorld } from '@qavajs/core';
33-
import { When, DataTable } from '@cucumber/cucumber';
58+
import { IQavajsWorld, When, DataTable } from '@qavajs/core';
3459

3560
When('I do smth complex', async function(this: IQavajsWorld) {
3661
await this.executeStep(`I type 'username' to 'Username Input'`);
@@ -39,13 +64,13 @@ that allow to call gherkin definitions programmatically
3964
await this.executeStep(`I fill following fields`, new DataTable([
4065
[ 'Order', '123' ],
4166
[ 'Delivery Location', 'New York' ]
42-
]))
67+
]));
4368
});
4469
```
4570
</TabItem>
4671
</Tabs>
4772

48-
### Template
73+
## Template
4974
`Template` provides a way to define step definition using Gherkin language
5075

5176
```typescript

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ When('Set memory {value} as {string}', async function(memoryKey, value) {
4848
You can also access the memory object directly in your step definitions:
4949

5050
<Tabs>
51-
<TabItem value="js" label="JavaScript" default>
51+
<TabItem value="js" label="JavaScript">
5252
```javascript
5353
const memory = require('@qavajs/memory');
5454

@@ -62,7 +62,7 @@ You can also access the memory object directly in your step definitions:
6262
});
6363
```
6464
</TabItem>
65-
<TabItem value="ts" label="TypeScript">
65+
<TabItem value="ts" label="TypeScript" default>
6666
```typescript
6767
import memory from '@qavajs/memory';
6868

@@ -93,7 +93,7 @@ And I expect text of 'Result Field' to equal '$myNumber'
9393
You can define constant values and computed functions that can be referenced in your feature files:
9494

9595
<Tabs>
96-
<TabItem value="js" label="JavaScript" default>
96+
<TabItem value="js" label="JavaScript">
9797
```javascript
9898
// memory.js
9999
module.exports = {
@@ -111,7 +111,7 @@ You can define constant values and computed functions that can be referenced in
111111
};
112112
```
113113
</TabItem>
114-
<TabItem value="ts" label="TypeScript">
114+
<TabItem value="ts" label="TypeScript" default>
115115
```typescript
116116
// memory.ts
117117
export default {
@@ -181,7 +181,7 @@ When I expect the price to be '\\$42.99'
181181
For parallel test execution, you can assign unique values for each Cucumber thread using the `parallel` function:
182182

183183
<Tabs>
184-
<TabItem value="js" label="JavaScript" default>
184+
<TabItem value="js" label="JavaScript">
185185
```javascript
186186
const { parallel } = require('@qavajs/memory/utils');
187187

@@ -200,7 +200,7 @@ For parallel test execution, you can assign unique values for each Cucumber thre
200200
module.exports = Memory;
201201
```
202202
</TabItem>
203-
<TabItem value="ts" label="TypeScript">
203+
<TabItem value="ts" label="TypeScript" default>
204204
```typescript
205205
import { parallel } from '@qavajs/memory/utils';
206206

versioned_docs/version-2x/Guides/page-object.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ You can use page objects in your custom step definitions for more advanced inter
506506
<Tabs>
507507
<TabItem value='js' label='JavaScript' default>
508508
```javascript
509-
const { When, Then } = require('@cucumber/cucumber');
509+
const { When, Then } = require('@qavajs/core');
510510
const { memory } = require('@qavajs/memory');
511511

512512
// For Playwright
@@ -534,7 +534,7 @@ You can use page objects in your custom step definitions for more advanced inter
534534
</TabItem>
535535
<TabItem value='ts' label='TypeScript'>
536536
```typescript
537-
import { When, Then } from '@cucumber/cucumber';
537+
import { When, Then } from '@qavajs/core';
538538
import { memory } from '@qavajs/memory';
539539
import { Locator } from '@playwright/test';
540540
import { ChainablePromiseElement } from 'webdriverio';

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,33 @@ Then I expect '$object' to match schema '$schema'
9898
You can also use validations in custom steps
9999

100100
<Tabs>
101-
<TabItem value="js" label="JavaScript" default>
101+
<TabItem value="js" label="JavaScript">
102102
```javascript
103-
const { Then } = require('@cucumber/cucumber');
103+
const { Then } = require('@qavajs/core');
104104
const { getValidation } = require('@qavajs/validation');
105105

106+
Then('I expect the answer {validation} {string}', async function(validate, expected) {
107+
const answer = '42';
108+
validate(answer, expected);
109+
});
110+
106111
Then('I expect the answer {} {string}', async function(validationType, expected) {
107112
const answer = '42';
108113
const validate = getValidation(validationType);
109114
validate(answer, expected);
110115
});
111116
```
112117
</TabItem>
113-
<TabItem value="ts" label="TypeScript">
118+
<TabItem value="ts" label="TypeScript" default>
114119
```typescript
115-
import { Then } from '@cucumber/cucumber';
120+
import { Then } from '@qavajs/core';
116121
import { getValidation } from '@qavajs/validation';
117122

123+
Then('I expect the answer {validation} {string}', async function(validate: Validation, expected: string) {
124+
const answer = '42';
125+
validate(answer, expected);
126+
});
127+
118128
Then('I expect the answer {} {string}', async function(validationType: string, expected: string) {
119129
const answer = '42';
120130
const validate = getValidation(validationType);
@@ -128,23 +138,33 @@ You can also use validations in custom steps
128138
Validation with auto-retries
129139

130140
<Tabs>
131-
<TabItem value="js" label="JavaScript" default>
141+
<TabItem value="js" label="JavaScript">
132142
```javascript
133-
const { Then } = require('@cucumber/cucumber');
143+
const { Then } = require('@qavajs/core');
134144
const { getPollValidation } = require('@qavajs/validation');
135145

146+
Then('I expect the answer {validation} {string}', async function(validate, expected) {
147+
const answer = getAnswer();
148+
await validate.poll(answer, expected, { timeout: 2000, interval: 500 });
149+
});
150+
136151
Then('I expect the answer {} {string}', async function(validationType, expected) {
137152
const answer = getAnswer();
138153
const validate = getPollValidation(validationType);
139154
await validate(getAnswer, expected, { timeout: 2000, interval: 500 });
140155
});
141156
```
142157
</TabItem>
143-
<TabItem value="ts" label="TypeScript">
158+
<TabItem value="ts" label="TypeScript" default>
144159
```typescript
145-
import { Then } from '@cucumber/cucumber';
160+
import { Then } from '@qavajs/core';
146161
import { getPollValidation } from '@qavajs/validation';
147162

163+
Then('I expect the answer {validation} {string}', async function(validate: Validation, expected: string) {
164+
const answer = getAnswer();
165+
await validate.poll(answer, expected);
166+
});
167+
148168
Then('I expect the answer {} {string}', async function(validationType: string, expected: string) {
149169
const answer = getAnswer();
150170
const validate = getPollValidation(validationType);

versioned_docs/version-2x/StandaloneSolutions/playwright.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ npm init playwright
1111
```
1212

1313
```shell
14-
npm install @cucumber/cucumber @qavajs/playwright @qavajs/playwright-runner-adapter @qavajs/memory
14+
npm install @qavajs/core @qavajs/playwright @qavajs/playwright-runner-adapter @qavajs/memory
1515
```
1616

1717
## Configuration

0 commit comments

Comments
 (0)