@qavajs/cypress 0.1.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 +15 -0
- package/README.md +50 -0
- package/defineQavajs.js +2 -0
- package/index.js +9 -0
- package/lib/actions.js +274 -0
- package/lib/conditionExpect.js +54 -0
- package/lib/defineQavajs.js +4 -0
- package/lib/execute.js +69 -0
- package/lib/memory.js +171 -0
- package/lib/mouseActions.js +58 -0
- package/lib/setup.js +46 -0
- package/lib/storage.js +59 -0
- package/lib/types.js +32 -0
- package/lib/utils.js +49 -0
- package/lib/validation.js +259 -0
- package/lib/valueExpect.js +84 -0
- package/lib/valueValidation.js +192 -0
- package/package.json +25 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Then } from '@qavajs/cypress-runner-adapter';
|
|
2
|
+
import {getValidation} from './valueExpect';
|
|
3
|
+
import {dataTable2Array} from './utils';
|
|
4
|
+
// simple validation
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Verify that value from memory satisfies validation against other value
|
|
8
|
+
* @param {string} value1 - first value
|
|
9
|
+
* @param {string} validation - validation
|
|
10
|
+
* @param {string} value2 - second value
|
|
11
|
+
* @example I expect '$value' equals to '$anotherValue'
|
|
12
|
+
* @example I expect '$value' does not contain '56'
|
|
13
|
+
*/
|
|
14
|
+
Then(
|
|
15
|
+
'I expect {string} {validation} {string}',
|
|
16
|
+
function (value1, validationType, value2) {
|
|
17
|
+
const val1 = this.value(value1);
|
|
18
|
+
const val2 = this.value(value2);
|
|
19
|
+
const validation = getValidation(validationType);
|
|
20
|
+
validation(val1, val2);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Verify that at least x elements in array pass validation
|
|
25
|
+
* @param {string} arr - arr
|
|
26
|
+
* @param {string} validation - validation
|
|
27
|
+
* @param {string} expectedValue - expected value
|
|
28
|
+
* @example I expect at least 1 element in '$arr' array to be above '$expectedValue'
|
|
29
|
+
* @example I expect at least 2 elements in '$arr' array to be above '50'
|
|
30
|
+
*/
|
|
31
|
+
Then(
|
|
32
|
+
'I expect at least {int} element(s) in {string} array {validation} {string}',
|
|
33
|
+
function (expectedNumber, arr, validationType, expectedValue) {
|
|
34
|
+
const array = this.value(arr);
|
|
35
|
+
const val = this.value(expectedValue);
|
|
36
|
+
const failCounter = { fail: 0, pass: 0 };
|
|
37
|
+
const validation = getValidation(validationType);
|
|
38
|
+
for (const value of array) {
|
|
39
|
+
try {
|
|
40
|
+
validation(value, val);
|
|
41
|
+
failCounter.pass++;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
failCounter.fail++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (failCounter.pass < expectedNumber) {
|
|
47
|
+
throw new Error(`Less than ${expectedNumber} pass ${validationType} verification`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Verify that every element in array satisfies validation against other value
|
|
54
|
+
* @param {string} arr - arr
|
|
55
|
+
* @param {string} validation - validation
|
|
56
|
+
* @param {string} expectedValue - expected value
|
|
57
|
+
* @example I expect every element in '$arr' array to be above '$expectedValue'
|
|
58
|
+
* @example I expect every element in '$arr' array to be above '50'
|
|
59
|
+
*/
|
|
60
|
+
Then(
|
|
61
|
+
'I expect every element in {string} array {validation} {string}',
|
|
62
|
+
function (arr, validationType, expectedValue) {
|
|
63
|
+
const array = this.value(arr);
|
|
64
|
+
const val = this.value(expectedValue);
|
|
65
|
+
const validation = getValidation(validationType);
|
|
66
|
+
for (const value of array) {
|
|
67
|
+
validation(value, val);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Verify that array is sorted by
|
|
74
|
+
* @param {string} arr - memory key of array
|
|
75
|
+
* @param {string} comparator - memory key of sort comparator function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description
|
|
76
|
+
* Important module does not include implementation of sorting function,
|
|
77
|
+
* as it may have various implementations for different types of compared data
|
|
78
|
+
* @example I expect '$arr' array to be sorted by '$ascending'
|
|
79
|
+
*/
|
|
80
|
+
Then(
|
|
81
|
+
'I expect {string} array to be sorted by {string}',
|
|
82
|
+
function (arr, comparator) {
|
|
83
|
+
const array = this.value(arr);
|
|
84
|
+
if (!Array.isArray(array)) throw new Error(`'${arr}' is not an array`);
|
|
85
|
+
const comparatorFn = this.value(comparator);
|
|
86
|
+
if (typeof comparatorFn !== 'function') throw new Error(`'${comparator}' is not implemented`);
|
|
87
|
+
const arrayCopy = [...array];
|
|
88
|
+
arrayCopy.sort(comparatorFn);
|
|
89
|
+
const validation = getValidation('to deeply equal');
|
|
90
|
+
validation(array, arrayCopy);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Verify that array value from memory satisfies validation against other array in form of data table
|
|
96
|
+
* @param {string} arr - memory key of array
|
|
97
|
+
* @param {string} validation - validation
|
|
98
|
+
* @param {DataTable} expected - expected array
|
|
99
|
+
* @example
|
|
100
|
+
* When I expect '$arr' array to have members:
|
|
101
|
+
* | uno |
|
|
102
|
+
* | dos |
|
|
103
|
+
* | tres |
|
|
104
|
+
*/
|
|
105
|
+
Then(
|
|
106
|
+
'I expect {string} array {validation}:',
|
|
107
|
+
function (arr, validationType, members) {
|
|
108
|
+
const array = this.value(arr);
|
|
109
|
+
const membersArray = dataTable2Array(this, members);
|
|
110
|
+
const validation = getValidation(validationType);
|
|
111
|
+
validation(array, membersArray);
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Verify that the value satisfies validation with at least one value from the array
|
|
117
|
+
* @param {string} actual - value to verify
|
|
118
|
+
* @param {string} validation - validation
|
|
119
|
+
* @param {string} expected - array of expected values
|
|
120
|
+
* @example
|
|
121
|
+
* When I expect '$text' to equal at least one of '$js(["free", "11.99"])'
|
|
122
|
+
*/
|
|
123
|
+
Then(
|
|
124
|
+
'I expect {string} {validation} at least one of {string}',
|
|
125
|
+
function (actual, validationType, expected) {
|
|
126
|
+
const actualValue = this.value(actual);
|
|
127
|
+
const expectedValues = this.value(expected);
|
|
128
|
+
if (!(expectedValues instanceof Array)) throw new Error(`'${expected}' parameter is not an array`);
|
|
129
|
+
const validation = getValidation(validationType);
|
|
130
|
+
const validate = (AR, ER) => validation(AR, ER);
|
|
131
|
+
validateAnyOf(actualValue, expectedValues, validate);
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Verify that the value satisfies validation with at least one value from the array
|
|
137
|
+
* @param {string} actual - value to verify
|
|
138
|
+
* @param {string} validation - validation
|
|
139
|
+
* @param {string} expected - array of expected values
|
|
140
|
+
* @example
|
|
141
|
+
* When I expect '$text' to equal at least one of:
|
|
142
|
+
* | free |
|
|
143
|
+
* | 11.99 |
|
|
144
|
+
*/
|
|
145
|
+
Then(
|
|
146
|
+
'I expect {string} {validation} at least one of:',
|
|
147
|
+
function (actual, validationType, expected) {
|
|
148
|
+
const actualValue = this.value(actual);
|
|
149
|
+
const expectedValues = dataTable2Array(this, expected);
|
|
150
|
+
const validation = (AR, ER) => valueExpect(AR, ER, validationType);
|
|
151
|
+
validateAnyOf(actualValue, expectedValues, validation);
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Verify that the value satisfies validation with all values from the array
|
|
157
|
+
* @param {string} actual - value to verify
|
|
158
|
+
* @param {string} validation - validation
|
|
159
|
+
* @param {string} expected - array of expected values
|
|
160
|
+
* @example
|
|
161
|
+
* When I expect '$text' not to equal all of '$js(["free", "10.00"])'
|
|
162
|
+
*/
|
|
163
|
+
Then(
|
|
164
|
+
'I expect {string} {validation} all of {string}',
|
|
165
|
+
function (actual, validationType, expected) {
|
|
166
|
+
const actualValue = this.value(actual);
|
|
167
|
+
const expectedValues = this.value(expected);
|
|
168
|
+
if (!(expectedValues instanceof Array)) throw new Error(`'${expected}' parameter is not an array`);
|
|
169
|
+
const validation = (AR, ER) => valueExpect(AR, ER, validationType);
|
|
170
|
+
validateAllOf(actualValue, expectedValues, validation);
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Verify that the value satisfies validation with all values from the array
|
|
176
|
+
* @param {string} actual - value to verify
|
|
177
|
+
* @param {string} validation - validation
|
|
178
|
+
* @param {string} expected - array of expected values
|
|
179
|
+
* @example
|
|
180
|
+
* When I expect '$text' not to equal all of:
|
|
181
|
+
* | free |
|
|
182
|
+
* | 10.00 |
|
|
183
|
+
*/
|
|
184
|
+
Then(
|
|
185
|
+
'I expect {string} {validation} all of:',
|
|
186
|
+
function (actual, validationType, expected) {
|
|
187
|
+
const actualValue = this.value(actual);
|
|
188
|
+
const expectedValues = dataTable2Array(this, expected);
|
|
189
|
+
const validation = (AR, ER) => valueExpect(AR, ER, validationType);
|
|
190
|
+
validateAllOf(actualValue, expectedValues, validation);
|
|
191
|
+
}
|
|
192
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qavajs/cypress",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "qavajs compatible framework on cypress runner",
|
|
5
|
+
"main": "",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"debug": "cypress open --config-file test-e2e/cypress.config.js",
|
|
8
|
+
"test": "cypress run --config-file test-e2e/cypress.config.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"QA",
|
|
12
|
+
"Testing"
|
|
13
|
+
],
|
|
14
|
+
"author": "Alexandr Galichenko",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@qavajs/cypress-runner-adapter": "^0.1.1",
|
|
18
|
+
"@qavajs/memory": "^1.7.0",
|
|
19
|
+
"@qavajs/po-cypress": "^0.2.0",
|
|
20
|
+
"cypress": "^13.11.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@qavajs/validation": "^0.8.0"
|
|
24
|
+
}
|
|
25
|
+
}
|