You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/heal.md
+32-5Lines changed: 32 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,40 @@ Browser and Mobile tests can fail for vareity of reasons. However, on a big proj
8
8
9
9

10
10
11
-
Let's start with an example the most basic healing recipe. If after a click test has failed, try to reload page, and continue.
11
+
Let's start with a common scenario. If a user suddenly becomes unauthorized and is moved to a sign-in page, or receives an unauthorized message on the page, we can heal by navigating to the `/login` page and trying to enter credentials again.
12
+
13
+
```js
14
+
heal.addRecipe('loginOnUnauthorized', {
15
+
priority:10,
16
+
steps: ['click', 'see', 'amOnPage'],
17
+
prepare: {
18
+
url: ({ I }) =>I.grabCurrentUrl(),
19
+
html: ({ I }) =>I.grabHTMLFrom('body'),
20
+
},
21
+
fn:async ({ url, error, step, html }) => {
22
+
if (!url.includes('/login') &&!error.message.toLowerCase().includes('unauthorized') &&!html.toLowerCase().includes('unauthorized')) return;
23
+
24
+
return ({ I }) => {
25
+
I.amOnPage('/login');
26
+
I.fillField('Email', 'test@example.com');
27
+
I.fillField('Password', '123456');
28
+
I.click('Sign in');
29
+
I[step.name](...step.args);
30
+
};
31
+
},
32
+
});
33
+
```
34
+
35
+
Another example is a very basic healing recipe. If after a click test has failed, try to reload page, and continue.
12
36
13
37
```js
14
38
heal.addRecipe('reload', {
15
39
priority:10,
16
40
steps: ['click'],
17
-
fn:async () => {
41
+
fn:async ({ step }) => {
18
42
return ({ I }) => {
19
43
I.refreshPage();
44
+
I[step.name](...step.args);
20
45
};
21
46
},
22
47
});
@@ -32,6 +57,7 @@ The example above is only one way a test can be healed. But you can define as ma
32
57
33
58
There are some ideas where healing can be useful to you:
34
59
60
+
***Authorization**. If a user suddenly becomes unauthorized and is moved to a sign-in page, or receives an unauthorized message on the page, we can heal by navigating to the `/login` page and trying to enter credentials.
35
61
***Networking**. If a test depends on a remote resource, and fails because this resource is not available, you may try to send API request to restore that resource before throwing an error.
36
62
***Data Consistency**. A test may fail because you noticed the data glitch in a system. Instead of failing a test you may try to clean up the data and try again to proceed.
37
63
***UI Change**. If there is a planned UI migration of a component, for instance Button was changed to Dropdown. You can prepare test so if it fails clicking Button it can try to do so with Dropdown.
@@ -67,9 +93,9 @@ Require `recipes` file and add `heal` plugin to `codecept.conf` file:
0 commit comments