Skip to content

Commit 1cd9856

Browse files
author
Oleksandr_Halichenko
committed
added memory validation steps
1 parent d02b3df commit 1cd9856

File tree

13 files changed

+565
-452
lines changed

13 files changed

+565
-452
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
:pencil: - chore
1111
:microscope: - experimental
1212

13+
## [2.0.0]
14+
- :rocket: implemented new page object approach
15+
1316
## [0.2.0]
1417
- :rocket: added memory write logs support
1518

lib/memory.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { When } from '@qavajs/cypress-runner-adapter';
2+
import { dataTable2Object } from './utils';
23

34
/**
45
* Save text of element to memory
@@ -164,3 +165,79 @@ When('I save bounding rect of {locator} as {value}', function (locator, key) {
164165
key.set(node.get(0).getBoundingClientRect());
165166
});
166167
});
168+
169+
170+
/**
171+
* ##############################
172+
*/
173+
174+
175+
/**
176+
* Save value to memory
177+
* @param {string} alias - value to save or alias for previously saved value
178+
* @param {string} key - key to store value
179+
* @example I save 'value' to memory as 'key'
180+
* @example I save '$getRandomUser()' to memory as 'user'
181+
*/
182+
When(
183+
'I save {value} to memory as {value}',
184+
function (expression, key) {
185+
key.set(expression.value());
186+
}
187+
);
188+
189+
When(
190+
'I save multiline string to memory as {value}:',
191+
function (key, multilineString) {
192+
const value = this.value(multilineString);
193+
key.set(value);
194+
}
195+
);
196+
197+
/**
198+
* Save value to memory
199+
* @param {string} key - key to store value
200+
* @param {string} value - value to save or alias for previously saved value
201+
* @example I set 'key' = 'value'
202+
*/
203+
When(
204+
'I set {value} = {value}',
205+
function (key, expression) {
206+
key.set(expression.value());
207+
}
208+
);
209+
210+
/**
211+
* Save json value to memory
212+
* @param {string} key - key to store value
213+
* @param {string} json - multiline string
214+
* @example I save json to memory as 'key':
215+
* """
216+
* {
217+
* "someKey": "someValue"
218+
* }
219+
* """
220+
*/
221+
When(
222+
'I save json to memory as {value}:',
223+
function (key, json) {
224+
const value = this.value(json);
225+
key.set(JSON.parse(value));
226+
}
227+
);
228+
229+
/**
230+
* Save key-value pairs to memory
231+
* @param {string} key - key to store value
232+
* @param {string} kv - key-value
233+
* @example I save key-value pairs to memory as 'key':
234+
* | someKey | 42 |
235+
* | someOtherKey | $valueFromMemory |
236+
*/
237+
When(
238+
'I save key-value pairs to memory as {value}:',
239+
function (key, kv) {
240+
const value = dataTable2Object(this, kv);
241+
key.set(value);
242+
}
243+
);

lib/pageObjects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ChainItem {
4242
export function query(root, path) {
4343
const elements = path.split(/\s*>\s*/);
4444
const tokens = [];
45-
let currentComponent = new root();
45+
let currentComponent = typeof root === 'function' ? new root() : root;
4646
let currentAlias = 'App';
4747
for (const element of elements) {
4848
const groups = element.match(/^(?<alias>.+?)(?:\((?<argument>.+)\))?$/)?.groups;

lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export function parseCoords(coords) {
1313
* @param dataTable
1414
* @return {Object}
1515
*/
16-
export async function dataTable2Object(ctx, dataTable) {
16+
export function dataTable2Object(ctx, dataTable) {
1717
const obj = {};
1818
for (const [key, value] of dataTable.raw()) {
19-
obj[key] = await ctx.value(value);
19+
obj[key] = ctx.value(value);
2020
}
2121
return obj;
2222
}

lib/validation.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,28 @@ Then(
223223
'I expect text of alert {validation} {value}',
224224
function (validation, expectedValue) {
225225
const alertHandler = new Cypress.Promise((resolve) => {
226-
cy.on('window:alert', (alertText)=> {
226+
cy.on('window:alert', (alertText) => {
227227
resolve(alertText)
228228
});
229-
cy.on('window:confirm', (alertText)=> {
229+
cy.on('window:confirm', (alertText) => {
230230
resolve(alertText)
231231
});
232232
});
233-
return alertHandler.then(alertText => { validation(alertText, expectedValue) })
233+
return alertHandler.then(alertText => {
234+
validation(alertText, expectedValue)
235+
})
234236
}
235237
);
236238

239+
/**
240+
* Verify collection condition
241+
* @param {string} alias - collection to wait condition
242+
* @param {string} condition - wait condition
243+
* @example I expect every element in 'Header' collection to be visible
244+
* @example I expect every element in 'Search Bar > Submit Button' collection not to be present
245+
*/
246+
Then('I expect every element in {locator} collection {condition}', function (collection, chainer) {
247+
collection.each(locator => {
248+
cy.wrap(locator).should(chainer);
249+
});
250+
});

0 commit comments

Comments
 (0)