@qavajs/cypress 2.3.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/index.js +1 -0
- package/lib/actions.js +1 -1
- package/lib/http.js +177 -0
- package/lib/memory.js +35 -6
- package/lib/types.js +22 -0
- package/lib/validation.js +39 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
|
|
|
10
10
|
:pencil: - chore
|
|
11
11
|
:microscope: - experimental
|
|
12
12
|
|
|
13
|
+
## [2.5.0]
|
|
14
|
+
- :rocket: added http steps
|
|
15
|
+
|
|
16
|
+
## [2.4.0]
|
|
17
|
+
- :rocket: added steps to work with custom properties (script results) in memory and validations
|
|
18
|
+
```gherkin
|
|
19
|
+
When I save '$js(element => element.prop("value"))' custom property of 'Element' as 'value'
|
|
20
|
+
Then I expect '$js(element => element.prop("value"))' custom property of 'Element' to be equal '123'
|
|
21
|
+
When I save '$js(element => element.prop("value"))' custom property of every element of 'Collection' collection as 'nodeNames'
|
|
22
|
+
Then I expect '$js(element => element.prop("value"))' custom property of every element in 'Collection' collection to equal 'LI'
|
|
23
|
+
```
|
|
24
|
+
|
|
13
25
|
## [2.3.1]
|
|
14
26
|
- :x: removed alias assignment in page object
|
|
15
27
|
|
package/index.js
CHANGED
package/lib/actions.js
CHANGED
package/lib/http.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { When } from '@qavajs/cypress-runner-adapter';
|
|
2
|
+
import { dataTable2Object } from './utils';
|
|
3
|
+
|
|
4
|
+
export class GraphQl {
|
|
5
|
+
method = 'POST';
|
|
6
|
+
headers = {'Content-Type': 'application/json'}
|
|
7
|
+
_query = '';
|
|
8
|
+
_variables = {};
|
|
9
|
+
data = {};
|
|
10
|
+
|
|
11
|
+
updateBody() {
|
|
12
|
+
this.body = {query: this._query, variables: this._variables};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
set query(query) {
|
|
16
|
+
this._query = query;
|
|
17
|
+
this.updateBody();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
set variables(variables) {
|
|
21
|
+
this._variables = JSON.parse(variables);
|
|
22
|
+
this.updateBody();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create request template and save it to memory
|
|
28
|
+
* @param {string} method - should be named as one of the http methods (e.g. GET, POST, PUT, DELETE and etc.)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* When I create 'GET' request 'request'
|
|
32
|
+
*/
|
|
33
|
+
When('I create {string} request {value}', function (method, key) {
|
|
34
|
+
key.set({ method });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create GraphQL request template and save it to memory
|
|
39
|
+
* @example
|
|
40
|
+
* When I create GraphQL request 'request'
|
|
41
|
+
*/
|
|
42
|
+
When('I create GraphQL request {value}', function (key) {
|
|
43
|
+
key.set(new GraphQl());
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Add data table of headers to request
|
|
48
|
+
* @param {string} requestKey - memory key of request
|
|
49
|
+
* @param {Array<[string, string]>} headersDataTable - key value headers
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* When I add headers to '$request':
|
|
53
|
+
* | Content-Type | application/json |
|
|
54
|
+
*/
|
|
55
|
+
When('I add headers to {value}:', async function (requestKey, headersDataTable) {
|
|
56
|
+
const request = requestKey.value();
|
|
57
|
+
request.headers = Object.assign({}, request.headers, dataTable2Object(this, headersDataTable));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Add headers to request
|
|
62
|
+
* @param {string} requestKey - memory key of request
|
|
63
|
+
* @param {string} headersKey - memory key of headers that resolves to JS object
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* When I add '$headers' headers to '$request'
|
|
67
|
+
*/
|
|
68
|
+
When('I add {value} headers to {value}', async function (headersKey, requestKey) {
|
|
69
|
+
const request = requestKey.value();
|
|
70
|
+
request.headers = Object.assign({}, request.headers, headersKey.value());
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Add body to request
|
|
75
|
+
* @param {string} requestKey - memory key of request
|
|
76
|
+
* @param {string} body - body
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* When I add body to '$request':
|
|
80
|
+
* """
|
|
81
|
+
* {
|
|
82
|
+
* "message": "qavajs"
|
|
83
|
+
* }
|
|
84
|
+
* """
|
|
85
|
+
*/
|
|
86
|
+
When('I add body to {value}:', async function ( requestKey, body) {
|
|
87
|
+
const request = requestKey.value();
|
|
88
|
+
request.data = this.value(body);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Add query or variables to GraphQL request.
|
|
93
|
+
* @param {string} property - one of GraphQl specific properties "query" or "variables"
|
|
94
|
+
* @param {string} requestKey - memory key of request
|
|
95
|
+
* @param {string} valueString - multiline string to be set as GraphQl body value.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* When I add query to GraphQL '$request':
|
|
99
|
+
* """
|
|
100
|
+
* query {
|
|
101
|
+
* characters(page: 2, filter: { name: "rick" }) {
|
|
102
|
+
* results {
|
|
103
|
+
* name
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
**/
|
|
108
|
+
When('I add {gqlRequestProperty} to GraphQL {value}:', async function (property, requestKey, valueString) {
|
|
109
|
+
const request = requestKey.value();
|
|
110
|
+
request[property] = this.value(valueString);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Add form data body to request
|
|
115
|
+
* @param {string} requestKey - memory key of request
|
|
116
|
+
* @param {string} body - body
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* When I add body to '$request':
|
|
120
|
+
* | key | value | filename | contentType |
|
|
121
|
+
* | formKey | formValue | | application/json |
|
|
122
|
+
* | otherKey | otherValue | | text/plain |
|
|
123
|
+
* | fileKey | $file('./path/file.png') | file.png | image/png |
|
|
124
|
+
*/
|
|
125
|
+
When('I add form data body to {value}:', async function (requestKey, dataTable) {
|
|
126
|
+
const request = requestKey.value();
|
|
127
|
+
const formData = new FormData();
|
|
128
|
+
for (const record of dataTable.hashes()) {
|
|
129
|
+
const key = this.value(record.key);
|
|
130
|
+
const value = this.value(record.value);
|
|
131
|
+
const fileName = this.value(record.filename) ?? 'default';
|
|
132
|
+
const type = this.value(record.contentType);
|
|
133
|
+
formData.append(key, new Blob([value], { type }), fileName);
|
|
134
|
+
}
|
|
135
|
+
request.data = formData;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Add body to request
|
|
140
|
+
* @param {string} requestKey - memory key of request
|
|
141
|
+
* @param {string} body - body
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* When I add '$body' body to '$request'
|
|
145
|
+
*/
|
|
146
|
+
When('I add {value} body to {value}', async function (bodyKey, requestKey) {
|
|
147
|
+
const request = requestKey.value();
|
|
148
|
+
request.data = bodyKey.value();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Add url to request
|
|
153
|
+
* @param {string} requestKey - memory key of request
|
|
154
|
+
* @param {string} url - url
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* When I add 'https://qavajs.github.io/' url to '$request'
|
|
158
|
+
*/
|
|
159
|
+
When('I add {value} url to {value}', async function (urlKey, requestKey) {
|
|
160
|
+
const request = requestKey.value();
|
|
161
|
+
request.url = urlKey.value();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Send request and send response
|
|
166
|
+
* @param {string} requestKey - memory key of request
|
|
167
|
+
* @param {string} responseKey - memory key to save response
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* When I send '$request' request and save response as 'response'
|
|
171
|
+
*/
|
|
172
|
+
When('I send {value} request and save response as {value}', async function (requestKey, responseKey) {
|
|
173
|
+
const request = requestKey.value();
|
|
174
|
+
cy.request(request).then(response => {
|
|
175
|
+
responseKey.set(response);
|
|
176
|
+
});
|
|
177
|
+
});
|
package/lib/memory.js
CHANGED
|
@@ -43,6 +43,20 @@ When('I save {value} attribute of {locator} as {value}', function (attribute, lo
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Save custom property of element to memory
|
|
48
|
+
* @param {string} propertyGetter - property getter script
|
|
49
|
+
* @param {string} alias - element to get value
|
|
50
|
+
* @param {string} key - key to store value
|
|
51
|
+
* @example I save '$js(e => e.first().prop("nodeName"))' custom property of 'Checkbox' as 'INPUT'
|
|
52
|
+
*/
|
|
53
|
+
When('I save {value} custom property of {locator} as {value}', function (property, locator, key) {
|
|
54
|
+
const script = property.value();
|
|
55
|
+
locator.then(element => {
|
|
56
|
+
key.set(script(element));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
46
60
|
/**
|
|
47
61
|
* Save number of elements in collection to memory
|
|
48
62
|
* @param {string} alias - collection to get value
|
|
@@ -114,6 +128,27 @@ When(
|
|
|
114
128
|
}
|
|
115
129
|
);
|
|
116
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Save custom property of every element in collection to memory
|
|
133
|
+
* @param {string} propertyGetter - property getter script
|
|
134
|
+
* @param {string} alias - collection to get values
|
|
135
|
+
* @param {string} key - key to store value
|
|
136
|
+
* @example I save '$js(e => e.first().prop("nodeName"))' custom property of every element of 'Search Results' collection as 'LI'
|
|
137
|
+
*/
|
|
138
|
+
When(
|
|
139
|
+
'I save {value} custom property of every element of {locator} collection as {value}',
|
|
140
|
+
function (propertyGetter, collection, key) {
|
|
141
|
+
const script = propertyGetter.value();
|
|
142
|
+
collection.then(c => {
|
|
143
|
+
const values = [];
|
|
144
|
+
c.each(function () {
|
|
145
|
+
values.push(script(Cypress.$(this)));
|
|
146
|
+
});
|
|
147
|
+
key.set(values);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
|
|
117
152
|
/**
|
|
118
153
|
* Save current url to memory
|
|
119
154
|
* @param {string} key - key to store value
|
|
@@ -166,12 +201,6 @@ When('I save bounding rect of {locator} as {value}', function (locator, key) {
|
|
|
166
201
|
});
|
|
167
202
|
});
|
|
168
203
|
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* ##############################
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
204
|
/**
|
|
176
205
|
* Save value to memory
|
|
177
206
|
* @param {string} alias - value to save or alias for previously saved value
|
package/lib/types.js
CHANGED
|
@@ -58,3 +58,25 @@ defineParameterType({
|
|
|
58
58
|
regexp: /(back|forward)/,
|
|
59
59
|
useForSnippets: false
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Parse http response body
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
defineParameterType({
|
|
67
|
+
name: 'bodyParsingType',
|
|
68
|
+
regexp: /buffer|json|text/,
|
|
69
|
+
transformer: p => p === 'buffer' ? 'body' : p,
|
|
70
|
+
useForSnippets: false,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* GraphQL request property
|
|
75
|
+
* @returns {string}
|
|
76
|
+
*/
|
|
77
|
+
defineParameterType({
|
|
78
|
+
name: 'gqlRequestProperty',
|
|
79
|
+
regexp: /query|variables/,
|
|
80
|
+
transformer: s => s,
|
|
81
|
+
useForSnippets: false,
|
|
82
|
+
});
|
package/lib/validation.js
CHANGED
|
@@ -87,6 +87,26 @@ Then(
|
|
|
87
87
|
}
|
|
88
88
|
);
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Verify that custom property (script result) of element satisfies condition
|
|
92
|
+
* @param {string} property - element to verify
|
|
93
|
+
* @param {string} alias - element to verify
|
|
94
|
+
* @param {string} validation - validation
|
|
95
|
+
* @param {string} value - expected value
|
|
96
|
+
* @example I expect '$js(e => e.first().prop("nodeName"))' custom property of 'Search Result' to be equal 'LI'
|
|
97
|
+
* @example I expect '$js(e => e.first().prop("nodeName"))' property of 'Label' to contain 'span'
|
|
98
|
+
*/
|
|
99
|
+
Then(
|
|
100
|
+
'I expect {value} custom property of {locator} {validation} {value}',
|
|
101
|
+
function (property, locator, validation, value) {
|
|
102
|
+
const script = property.value();
|
|
103
|
+
const expectedValue = value.value();
|
|
104
|
+
locator.should(e => {
|
|
105
|
+
validation(script(e), expectedValue);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
|
|
90
110
|
/**
|
|
91
111
|
* Verify that current url satisfies condition
|
|
92
112
|
* @param {string} validation - validation
|
|
@@ -193,6 +213,25 @@ Then(
|
|
|
193
213
|
}
|
|
194
214
|
);
|
|
195
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Verify that custom property of all elements in collection satisfy condition
|
|
218
|
+
* @param {string} propertyGetter - property getter script
|
|
219
|
+
* @param {string} alias - collection to get props
|
|
220
|
+
* @param {string} validation - validation
|
|
221
|
+
* @param {string} value - expected result
|
|
222
|
+
* @example I expect '$js(e => e.first().prop("nodeName"))' property of every element in 'Search Results' collection to contain 'LI'
|
|
223
|
+
*/
|
|
224
|
+
Then(
|
|
225
|
+
'I expect {value} custom property of every element in {locator} collection {validation} {value}',
|
|
226
|
+
function (property, collection, validation, value) {
|
|
227
|
+
const expectedValue = value.value();
|
|
228
|
+
const script = property.value();
|
|
229
|
+
collection.each(element => {
|
|
230
|
+
validation(script(element), expectedValue);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
|
|
196
235
|
/**
|
|
197
236
|
* Verify that css property of element satisfies condition
|
|
198
237
|
* @param {string} property - element to verify
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qavajs/cypress",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "qavajs for cypress runner",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"author": "Alexandr Galichenko",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@qavajs/cypress-runner-adapter": "^1.
|
|
30
|
+
"@qavajs/cypress-runner-adapter": "^1.5.0",
|
|
31
31
|
"@qavajs/memory": "^1.10.3",
|
|
32
|
-
"cypress": "^15.
|
|
32
|
+
"cypress": "^15.8.1"
|
|
33
33
|
}
|
|
34
34
|
}
|