@qavajs/cypress 2.3.1 → 2.4.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,15 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
10
10
  :pencil: - chore
11
11
  :microscope: - experimental
12
12
 
13
+ ## [2.4.0]
14
+ - :rocket: added steps to work with custom properties (script results) in memory and validations
15
+ ```gherkin
16
+ When I save '$js(element => element.prop("value"))' custom property of 'Element' as 'value'
17
+ Then I expect '$js(element => element.prop("value"))' custom property of 'Element' to be equal '123'
18
+ When I save '$js(element => element.prop("value"))' custom property of every element of 'Collection' collection as 'nodeNames'
19
+ Then I expect '$js(element => element.prop("value"))' custom property of every element in 'Collection' collection to equal 'LI'
20
+ ```
21
+
13
22
  ## [2.3.1]
14
23
  - :x: removed alias assignment in page object
15
24
 
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/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.1",
3
+ "version": "2.4.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.3.0",
30
+ "@qavajs/cypress-runner-adapter": "^1.5.0",
31
31
  "@qavajs/memory": "^1.10.3",
32
- "cypress": "^15.4.0"
32
+ "cypress": "^15.8.1"
33
33
  }
34
34
  }