Skip to content

Commit fe748ee

Browse files
author
DavertMik
committed
Improved debugging
1 parent 5814e1d commit fe748ee

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ package-lock.json
2626
yarn.lock
2727
/.vs
2828
typings/types.d.ts
29-
typings/promiseBasedTypes.d.ts
29+
typings/promiseBasedTypes.d.ts
30+
reflection/

docs/heal.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,40 @@ Browser and Mobile tests can fail for vareity of reasons. However, on a big proj
88

99
![](/img/healing.png)
1010

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.
1236

1337
```js
1438
heal.addRecipe('reload', {
1539
priority: 10,
1640
steps: ['click'],
17-
fn: async () => {
41+
fn: async ({ step }) => {
1842
return ({ I }) => {
1943
I.refreshPage();
44+
I[step.name](...step.args);
2045
};
2146
},
2247
});
@@ -32,6 +57,7 @@ The example above is only one way a test can be healed. But you can define as ma
3257

3358
There are some ideas where healing can be useful to you:
3459

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.
3561
* **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.
3662
* **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.
3763
* **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:
6793

6894
```js
6995

70-
require('./heal')
96+
import './heal';
7197

72-
exports.config = {
98+
export const config = {
7399
// ...
74100
plugins: {
75101
heal: {
@@ -134,7 +160,8 @@ heal.addRecipe('reloadPageOnUserAccount', {
134160
// probably you should do something more sophisticated
135161
// to heal the test
136162
I.reloadPage();
137-
I.wait(1);
163+
I.wait(1);
164+
I[step.name](...stepArgs);
138165
};
139166
},
140167
});

lib/plugin/aiTrace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ export default function (config) {
438438
const traceFile = path.join(dir, 'trace.md')
439439
fs.writeFileSync(traceFile, markdown)
440440

441-
output.print(`🤖 AI Trace: ${colors.white.bold(`file://${traceFile}`)}`)
441+
output.print(`Trace Saved: file://${traceFile}`)
442442

443443
if (!test.artifacts) test.artifacts = {}
444444
test.artifacts.aiTrace = traceFile

0 commit comments

Comments
 (0)