Skip to content

Commit 21d2c58

Browse files
authored
3.3.4 release (#3357)
* updated changelog * fixed tests, added changelog and docs * version bump, docs updated
1 parent 9ca6f73 commit 21d2c58

File tree

8 files changed

+85
-9
lines changed

8 files changed

+85
-9
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
## 3.3.4
2+
3+
* Added support for masking fields in objects via `secret` function:
4+
5+
```js
6+
I.sendPostRequest('/auth', secret({ name: 'jon', password: '123456' }, 'password'));
7+
```
8+
* Added [a guide about using of `secret`](/secrets) function
9+
* [Appium] Use `touchClick` when interacting with elements in iOS. See #3317 by @mikk150
10+
* [Playwright] Added `cdpConnection` option to connect over CDP. See #3309 by @Hmihaly
11+
* [customLocator plugin] Allowed to specify multiple attributes for custom locator. Thanks to @aruiz-caritsqa
12+
13+
```js
14+
plugins: {
15+
customLocator: {
16+
enabled: true,
17+
prefix: '$',
18+
attribute: ['data-qa', 'data-test'],
19+
}
20+
}
21+
```
22+
* [retryTo plugin] Fixed #3147 using `pollInterval` option. See #3351 by @cyonkee
23+
* [Playwright] Fixed grabbing of browser console messages and window resize in new tab. Thanks to @mirao
24+
* [REST] Added `prettyPrintJson` option to print JSON in nice way by @PeterNgTr
25+
* [JSONResponse] Updated response validation to iterate over array items if response is array. Thanks to @PeterNgTr
26+
27+
```js
28+
// response.data == [
29+
// { user: { name: 'jon', email: '[email protected]' } },
30+
// { user: { name: 'matt', email: '[email protected]' } },
31+
//]
32+
33+
I.seeResponseContainsKeys(['user']);
34+
I.seeResponseContainsJson({ user: { email: '[email protected]' } });
35+
I.seeResponseContainsJson({ user: { email: '[email protected]' } });
36+
I.dontSeeResponseContainsJson({ user: 2 });
37+
```
38+
139
## 3.3.3
240

341
* Fixed `DataCloneError: () => could not be cloned` when running data tests in run-workers

docs/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ The most basic thing to check in response is existence of keys in JSON object. U
263263
I.seeResponseContainsKeys(['name', 'email']);
264264
```
265265

266+
> ℹ️ If response is an array, it will check that every element in array have provided keys
267+
266268
However, this is a very naive approach. It won't work for arrays or nested objects.
267269
To check complex JSON structures `JSONResponse` helper uses [`joi`](https://joi.dev) library.
268270
It has rich API to validate JSON by the schema defined using JavaScript.
@@ -296,6 +298,8 @@ I.seeResponseContainsJson({
296298
})
297299
```
298300

301+
> ℹ️ If response is an array, it will check that at least one element in array matches JSON
302+
299303
To perform arbitrary assertions on a response object use `seeResponseValidByCallback`.
300304
It allows you to do any kind of assertions by using `expect` from [`chai`](https://www.chaijs.com) library.
301305

docs/helpers/JSONResponse.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ Checks for deep inclusion of a provided json in a response data.
9292
I.dontSeeResponseContainsJson({ user: 2 });
9393
```
9494

95+
If an array is received, checks that no element of array contains json:
96+
9597
```js
96-
// response.data == [{ data: { user: 1 } }]
98+
// response.data == [{ user: 1 }, { user: 3 }]
9799

98100
I.dontSeeResponseContainsJson({ user: 2 });
99101
```
@@ -145,6 +147,8 @@ Checks for deep inclusion of a provided json in a response data.
145147
I.seeResponseContainsJson({ user: { email: '[email protected]' } });
146148
```
147149

150+
If an array is received, checks that at least one element contains JSON
151+
148152
```js
149153
// response.data == [{ user: { name: 'jon', email: '[email protected]' } }]
150154

@@ -165,8 +169,10 @@ Checks for deep inclusion of a provided json in a response data.
165169
I.seeResponseContainsKeys(['user']);
166170
```
167171

172+
If an array is received, check is performed for each element of array:
173+
168174
```js
169-
// response.data == [{ user: { name: 'jon', email: '[email protected]' } }]
175+
// response.data == [{ user: 'jon' }, { user: 'matt'}]
170176

171177
I.seeResponseContainsKeys(['user']);
172178
```

docs/plugins.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
---
2+
permalink: plugins
3+
sidebarDepth:
4+
sidebar: auto
5+
title: Plugins
6+
---
7+
18
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
29

310
## allure

docs/secrets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ I.sendPostRequest('/login', secret({
2727

2828
The object created from `secret` is as Proxy to the object passed in. When printed password will be replaced with ****.
2929

30-
> ⚠️ Currently, properties of nested objects can't be masked via `secret`
30+
> ⚠️ Only direct properties of the object can be masked via `secret`

lib/helper/JSONResponse.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const assert = require('assert');
12
const chai = require('chai');
23
const joi = require('joi');
34
const chaiDeepMatch = require('chai-deep-match');
@@ -173,6 +174,7 @@ class JSONResponse extends Helper {
173174
*
174175
* I.seeResponseContainsJson({ user: { email: 'jon@doe.com' } });
175176
* ```
177+
* If an array is received, checks that at least one element contains JSON
176178
* ```js
177179
* // response.data == [{ user: { name: 'jon', email: 'jon@doe.com' } }]
178180
*
@@ -184,7 +186,15 @@ class JSONResponse extends Helper {
184186
seeResponseContainsJson(json = {}) {
185187
this._checkResponseReady();
186188
if (Array.isArray(this.response.data)) {
187-
this.response.data.forEach(data => expect(data).to.deep.match(json));
189+
let fails = 0;
190+
for (const el of this.response.data) {
191+
try {
192+
expect(el).to.deep.match(json);
193+
} catch (err) {
194+
fails++;
195+
}
196+
}
197+
assert.ok(fails < this.response.data.length, `No elements in array matched ${JSON.stringify(json)}`);
188198
} else {
189199
expect(this.response.data).to.deep.match(json);
190200
}
@@ -198,8 +208,9 @@ class JSONResponse extends Helper {
198208
*
199209
* I.dontSeeResponseContainsJson({ user: 2 });
200210
* ```
211+
* If an array is received, checks that no element of array contains json:
201212
* ```js
202-
* // response.data == [{ data: { user: 1 } }]
213+
* // response.data == [{ user: 1 }, { user: 3 }]
203214
*
204215
* I.dontSeeResponseContainsJson({ user: 2 });
205216
* ```
@@ -224,8 +235,10 @@ class JSONResponse extends Helper {
224235
* I.seeResponseContainsKeys(['user']);
225236
* ```
226237
*
238+
* If an array is received, check is performed for each element of array:
239+
*
227240
* ```js
228-
* // response.data == [{ user: { name: 'jon', email: 'jon@doe.com' } }]
241+
* // response.data == [{ user: 'jon' }, { user: 'matt'}]
229242
*
230243
* I.seeResponseContainsKeys(['user']);
231244
* ```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs",
3-
"version": "3.3.3",
3+
"version": "3.3.4",
44
"description": "Supercharged End 2 End Testing Framework for NodeJS",
55
"keywords": [
66
"acceptance",

test/helper/JSONResponse_test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ describe('JSONResponse', () => {
9999
{ id: 1, author: 'davert' },
100100
],
101101
});
102-
expect(() => I.seeResponseContainsJson({ posts: [{ id: 2, author: 'boss' }] })).to.throw('expected { …(2) } to deeply match { Object (posts) }');
102+
expect(() => I.seeResponseContainsJson({ posts: [{ id: 2, author: 'boss' }] })).to.throw('No elements in array matched {"posts":[{"id":2,"author":"boss"}]}');
103+
});
104+
105+
it('should check for json inclusion - returned Array of 2 items', () => {
106+
const arrayData = [{ ...data }, { posts: { id: 3 } }];
107+
restHelper.config.onResponse({ data: arrayData });
108+
I.seeResponseContainsJson({
109+
posts: { id: 3 },
110+
});
103111
});
104112

105113
it('should simply check for json inclusion', () => {
@@ -123,7 +131,7 @@ describe('JSONResponse', () => {
123131

124132
it('should simply check for json equality - returned Array', () => {
125133
restHelper.config.onResponse({ data: [{ user: 1 }] });
126-
I.seeResponseEquals({ user: 1 });
134+
I.seeResponseEquals([{ user: 1 }]);
127135
});
128136

129137
it('should check json contains keys', () => {

0 commit comments

Comments
 (0)