Skip to content

Commit 0454cc7

Browse files
Merge pull request #82 from testla-project/80-documentation-of-orskiponfail-and-failasfalse
80 documentation of orskiponfail and failasfalse
2 parents 4874f57 + 3672b7a commit 0454cc7

33 files changed

+428
-14
lines changed

__tests__/failure-handling.spec.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect, test as base } from '@playwright/test';
2+
import { Actor } from '@testla/screenplay';
3+
import { BrowseTheWeb, Navigate, Click, Element } from '../src/web';
4+
5+
type MyActors = {
6+
actor: Actor;
7+
};
8+
9+
const test = base.extend<MyActors>({
10+
actor: async ({ browser }, use) => {
11+
const context = await browser.newContext();
12+
const page = await context.newPage();
13+
const actor = Actor.named('TestActor')
14+
.can(BrowseTheWeb.using(page));
15+
await use(actor);
16+
},
17+
});
18+
19+
test.describe('Testing screenplay-playwright-js failure handling', () => {
20+
test('orSkipOnFail', async ({ actor }) => {
21+
await actor.attemptsTo(
22+
Navigate.to('https://google.de'),
23+
Click.on('#not-existing-element', { timeout: 1000 }).orSkipOnFail,
24+
);
25+
});
26+
27+
test('failAsFalse', async ({ actor }) => {
28+
await actor.attemptsTo(
29+
Navigate.to('https://google.de'),
30+
);
31+
32+
const shallBeFalse = await actor.asks(
33+
Element.toBe.visible('#not-existing-element', { timeout: 1000 }).failAsFalse,
34+
);
35+
36+
await expect(shallBeFalse).toBe(false);
37+
});
38+
});
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[Back to overview](../guides.md)
2+
3+
# Handle Failing Steps
4+
5+
In general tests break when a step fails. This happens if an action or task is not successful or when a question cannot be answered positive.
6+
7+
But what if an action or tasks is allowed to fail based on the current state of the system under test or when you want to react conditionally on failing questions? Testla offers you the follwing options for this.
8+
9+
## Proceeding with the test when an action/task fails
10+
11+
You may have actions or tasks which might (expectedly) fail during the test. An example is to click an element if it is present while it is also fine to proceed with the test when the element is not available.
12+
13+
This can be achieved as follows:
14+
15+
```javascript
16+
await actor.attemptsTo(
17+
// this action might fail but the test will continue
18+
Click.on('#eventually-available').orSkipOnFail,
19+
Click.on('#definitely-available'),
20+
);
21+
```
22+
23+
## Use failing questions for test flow controls
24+
25+
In some cases you may want to ask questions to find out about the status of the system under test to make decisions on how to move on with your test. In order to not fail a test but receive information about questions being answered negative you can use `failAsFalse` on a question which then returns a boolean value instead.
26+
27+
```javascript
28+
// find out if question was answered with false
29+
const wasLoggedIn = await actors.asks(
30+
Login.toBe.successful().failAsFalse,
31+
);
32+
33+
// proceed based on answer from above
34+
if (wasLoggedIn === false) {
35+
// some code to be executed on false case
36+
}
37+
```
38+
39+
[Back to overview](../guides.md)

docs/guides/guides.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- [Write your own Tasks](./advanced_test_setup/create_task.md)
1212
- [Write your own Questions](./advanced_test_setup/create_question.md)
1313
- [Use it in your test](./advanced_test_setup/write_tests.md)
14+
- **Handle Failing Steps**
15+
- [Failing Steps](./failing_steps/failing_steps.md) - Handling for failing actions, tasks and questions
1416
- **Aliasing**
1517
- [Ability Aliasing](./ability_aliasing/ability_aliasing.md) - Using the same ability with different configurations
1618
- **Frame Handling**

docs/guides/logging/logging.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
# Logging
44

5-
> This feature is currently in experimental stage and might see bigger changes.
6-
75
Testla comes with logging which helps you to debug your test code. When logging is enabled all activities an actor triggers are logged in a comprehensive way to stdout. To enable logging set the DEBUG environment variable as follows:
86

97
```typescript

docs/screenplay_elements/API/Actions/delete.md

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The `Delete` class provides a convenient way to perform HTTP DELETE requests. It
1616
- [withHeaders](#withheaders)
1717
- [withResponseBodyFormat](#withresponsebodyformat)
1818
- [withAbilityAlias](#withabilityalias)
19+
- [orSkipOnFail](#orskiponfail)
1920

2021
## Class Overview
2122

@@ -80,4 +81,15 @@ public withAbilityAlias(alias: string): Delete;
8081
- `alias` - The alias.
8182
- **Returns:** `Delete` - Returns the current action.
8283

84+
### orSkipOnFail
85+
86+
*Introduced in: 1.6.0*
87+
88+
```typescript
89+
public get orSkipOnFail(): Delete;
90+
```
91+
92+
- **Description:** Allows to skip an action on fail.
93+
- **Returns:** `Delete` - Returns the current action.
94+
8395
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/API/Actions/get.md

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The `Get` class provides a convenient way to perform HTTP GET requests. It allow
1616
- [withHeaders](#withheaders)
1717
- [withResponseBodyFormat](#withresponsebodyformat)
1818
- [withAbilityAlias](#withabilityalias)
19+
- [orSkipOnFail](#orskiponfail)
1920

2021
## Class Overview
2122

@@ -80,4 +81,15 @@ public withAbilityAlias(alias: string): Get;
8081
- `alias` - The alias.
8182
- **Returns:** `Get` - Returns the current action.
8283

84+
### orSkipOnFail
85+
86+
*Introduced in: 1.6.0*
87+
88+
```typescript
89+
public get orSkipOnFail(): Get;
90+
```
91+
92+
- **Description:** Allows to skip an action on fail.
93+
- **Returns:** `Get` - Returns the current action.
94+
8395
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/API/Actions/head.md

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The `Head` class provides a convenient way to perform HTTP HEAD requests. It all
1515
- [from](#from)
1616
- [withHeaders](#withheaders)
1717
- [withAbilityAlias](#withabilityalias)
18+
- [orSkipOnFail](#orskiponfail)
1819

1920
## Class Overview
2021

@@ -68,4 +69,15 @@ public withAbilityAlias(alias: string): Head;
6869
- `alias` - The alias.
6970
- **Returns:** `Head` - Returns the current action.
7071

72+
### orSkipOnFail
73+
74+
*Introduced in: 1.6.0*
75+
76+
```typescript
77+
public get orSkipOnFail(): Head;
78+
```
79+
80+
- **Description:** Allows to skip an action on fail.
81+
- **Returns:** `Head` - Returns the current action.
82+
7183
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/API/Actions/patch.md

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The `Patch` class provides a convenient way to perform HTTP PATCH requests. It a
1717
- [withHeaders](#withheaders)
1818
- [withResponseBodyFormat](#withresponsebodyformat)
1919
- [withAbilityAlias](#withabilityalias)
20+
- [orSkipOnFail](#orskiponfail)
2021

2122
## Class Overview
2223

@@ -92,4 +93,15 @@ public withAbilityAlias(alias: string): Patch;
9293
- `alias` - The alias.
9394
- **Returns:** `Patch` - Returns the current action.
9495

96+
### orSkipOnFail
97+
98+
*Introduced in: 1.6.0*
99+
100+
```typescript
101+
public get orSkipOnFail(): Patch;
102+
```
103+
104+
- **Description:** Allows to skip an action on fail.
105+
- **Returns:** `Patch` - Returns the current action.
106+
95107
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/API/Actions/post.md

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The `Post` class provides a convenient way to perform HTTP POST requests. It all
1717
- [withHeaders](#withheaders)
1818
- [withResponseBodyFormat](#withresponsebodyformat)
1919
- [withAbilityAlias](#withabilityalias)
20+
- [orSkipOnFail](#orskiponfail)
2021

2122
## Class Overview
2223

@@ -92,4 +93,15 @@ public withAbilityAlias(alias: string): Post;
9293
- `alias` - The alias.
9394
- **Returns:** `Post` - Returns the current action.
9495

96+
### orSkipOnFail
97+
98+
*Introduced in: 1.6.0*
99+
100+
```typescript
101+
public get orSkipOnFail(): Post;
102+
```
103+
104+
- **Description:** Allows to skip an action on fail.
105+
- **Returns:** `Post` - Returns the current action.
106+
95107
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/API/Actions/put.md

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The `Put` class provides a convenient way to perform HTTP PUT requests. It allow
1717
- [withHeaders](#withheaders)
1818
- [withResponseBodyFormat](#withresponsebodyformat)
1919
- [withAbilityAlias](#withabilityalias)
20+
- [orSkipOnFail](#orskiponfail)
2021

2122
## Class Overview
2223

@@ -92,4 +93,15 @@ public withAbilityAlias(alias: string): Put;
9293
- `alias` - The alias.
9394
- **Returns:** `Put` - Returns the current action.
9495

96+
### orSkipOnFail
97+
98+
*Introduced in: 1.6.0*
99+
100+
```typescript
101+
public get orSkipOnFail(): Put;
102+
```
103+
104+
- **Description:** Allows to skip an action on fail.
105+
- **Returns:** `Put` - Returns the current action.
106+
95107
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/API/Questions/response.md

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The `Response` class provides a flexible way to verify various aspects of an API
1818
- [body](#body)
1919
- [headers](#headers)
2020
- [beenReceivedWithin](#beenreceivedwithin)
21+
- [withAbilityAlias](#withabilityalias)
22+
- [failAsFalse](#failasfalse)
2123

2224
## Class Overview
2325

@@ -104,4 +106,26 @@ public beenReceivedWithin(response: ResponseType, duration: number): Response;
104106
- `duration` - The expected duration (in milliseconds).
105107
- **Returns:** `Response` - The updated instance of the `Response` class.
106108

109+
### withAbilityAlias
110+
111+
```typescript
112+
public withAbilityAlias(alias: string): Response;
113+
```
114+
115+
- **Description:** Defines the ability alias to be used during execution.
116+
- **Parameters:**
117+
- `alias` - The alias.
118+
- **Returns:** `Response` - Returns the current question.
119+
120+
### failAsFalse
121+
122+
*Introduced in: 1.6.0*
123+
124+
```typescript
125+
public get failAsFalse(): Response;
126+
```
127+
128+
- **Description:** Returns false instead of failing when exception occurrs.
129+
- **Returns:** `Response` - Returns the current question.
130+
107131
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/Web/Actions/add.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The `Add` class is an action class in the Screenplay pattern designed for use wi
1313
- [performAs](#performas)
1414
- [cookies](#cookies)
1515
- [withAbilityAlias](#withabilityalias)
16+
- [orSkipOnFail](#orskiponfail)
1617

1718
## Class Overview
1819

@@ -51,4 +52,15 @@ public withAbilityAlias(alias: string): Add;
5152
- `alias` - The alias.
5253
- **Returns:** `Add` - Returns the current action.
5354

55+
### orSkipOnFail
56+
57+
*Introduced in: 1.6.0*
58+
59+
```typescript
60+
public get orSkipOnFail(): Add;
61+
```
62+
63+
- **Description:** Allows to skip an action on fail.
64+
- **Returns:** `Add` - Returns the current action.
65+
5466
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/Web/Actions/check.md

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The `Check` class is an action class in the Screenplay pattern designed for use
1414
- [element](#element)
1515
- [inFrame](#inframe)
1616
- [withAbilityAlias](#withabilityalias)
17+
- [orSkipOnFail](#orskiponfail)
1718

1819
## Class Overview
1920

@@ -64,4 +65,15 @@ public withAbilityAlias(alias: string): Check;
6465
- `alias` - The alias.
6566
- **Returns:** `Check` - Returns the current action.
6667

68+
### orSkipOnFail
69+
70+
*Introduced in: 1.6.0*
71+
72+
```typescript
73+
public get orSkipOnFail(): Check;
74+
```
75+
76+
- **Description:** Allows to skip an action on fail.
77+
- **Returns:** `Check` - Returns the current action.
78+
6779
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/Web/Actions/clear.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The `Clear` class is an action class in the Screenplay pattern designed for use
1313
- [performAs](#performas)
1414
- [cookies](#cookies)
1515
- [withAbilityAlias](#withabilityalias)
16+
- [orSkipOnFail](#orskiponfail)
1617

1718
## Class Overview
1819

@@ -49,4 +50,15 @@ public withAbilityAlias(alias: string): Clear;
4950
- `alias` - The alias.
5051
- **Returns:** `Clear` - Returns the current action.
5152

53+
### orSkipOnFail
54+
55+
*Introduced in: 1.6.0*
56+
57+
```typescript
58+
public get orSkipOnFail(): Clear;
59+
```
60+
61+
- **Description:** Allows to skip an action on fail.
62+
- **Returns:** `Clear` - Returns the current action.
63+
5264
[Back to overview](../../screenplay_elements.md)

docs/screenplay_elements/Web/Actions/click.md

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The `Click` class is an action class in the Screenplay pattern designed for use
1414
- [on](#on)
1515
- [inFrame](#inframe)
1616
- [withAbilityAlias](#withabilityalias)
17+
- [orSkipOnFail](#orskiponfail)
1718

1819
## Class Overview
1920

@@ -64,4 +65,15 @@ public withAbilityAlias(alias: string): Click;
6465
- `alias` - The alias.
6566
- **Returns:** `Click` - Returns the current action.
6667

68+
### orSkipOnFail
69+
70+
*Introduced in: 1.6.0*
71+
72+
```typescript
73+
public get orSkipOnFail(): Click;
74+
```
75+
76+
- **Description:** Allows to skip an action on fail.
77+
- **Returns:** `Click` - Returns the current action.
78+
6779
[Back to overview](../../screenplay_elements.md)

0 commit comments

Comments
 (0)