@qavajs/cypress 2.4.0 → 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 CHANGED
@@ -10,6 +10,9 @@ 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
+
13
16
  ## [2.4.0]
14
17
  - :rocket: added steps to work with custom properties (script results) in memory and validations
15
18
  ```gherkin
package/index.js CHANGED
@@ -7,3 +7,4 @@ import './lib/valueValidation.js';
7
7
  import './lib/execute.js';
8
8
  import './lib/storage.js';
9
9
  import './lib/mouseActions.js';
10
+ import './lib/http.js';
package/lib/actions.js CHANGED
@@ -20,7 +20,7 @@ When('I open {value} url', function (url) {
20
20
  When('I type {value} (in)to {locator}', function (type, locator) {
21
21
  locator.type(type.value());
22
22
  });
23
- //
23
+
24
24
  /**
25
25
  * Click element
26
26
  * @param {string} alias - element to click
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/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qavajs/cypress",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "qavajs for cypress runner",
5
5
  "main": "index.js",
6
6
  "scripts": {