@camperaid/watest 2.3.6 → 2.3.9

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.
@@ -54,7 +54,7 @@ module.exports.test = async () => {
54
54
  {
55
55
  name: 'mac/ui',
56
56
  path: 'tests/ui/',
57
- loader: '/Users/me/projects/camperaid/watest/tests/ui/meta.mjs',
57
+ loader: v => v.endsWith('tests/ui/meta.mjs'),
58
58
  webdriver: '',
59
59
  run_in_child_process: true,
60
60
  },
@@ -25,7 +25,7 @@ module.exports.test = do_self_tests(snippet, async session => {
25
25
  `Test: Input is shown. Selector: '#input'`,
26
26
  `Ok: '#input' has to be unique, got: 1`,
27
27
  `Ok: Input is shown`,
28
- `Action: Input.type into Type hello`,
28
+ `Action: Input.type 'hello' into Type hello`,
29
29
  `Test: Focus. Selector: '#input'`,
30
30
  `Ok: '#input' has to be unique, got: 1`,
31
31
  `Ok: Focus`,
@@ -47,7 +47,7 @@ module.exports.test = do_self_tests(snippet, async session => {
47
47
  `Test: Input is shown. Selector: '#input'`,
48
48
  `Ok: '#input' has to be unique, got: 1`,
49
49
  `Ok: Input is shown`,
50
- `Action: Input.type into Type hello`,
50
+ `Action: Input.type 'hello' into Type hello`,
51
51
  `Test: Focus. Selector: '#input'`,
52
52
  `Ok: '#input' has to be unique, got: 1`,
53
53
  `Ok: Focus`,
@@ -73,7 +73,7 @@ class AppDriver {
73
73
 
74
74
  type(selector, value, field) {
75
75
  return this.chain(() =>
76
- this.action(`${this.uiname}.type into ${field}`)
76
+ this.action(`${this.uiname}.type '${value}' into ${field}`)
77
77
  .sendKeys(selector, '', `Focus`)
78
78
  .elementFocused(selector, 'Focused')
79
79
  .selectAll(selector, `Select all text`)
@@ -82,6 +82,14 @@ class AppDriver {
82
82
  );
83
83
  }
84
84
 
85
+ clear(selector, field) {
86
+ return this.chain(() =>
87
+ this.action(`${this.uiname}.clear ${field}`)
88
+ .clear(selector, `Clear text`)
89
+ .textIs(selector, '', `Check ${field} text`)
90
+ );
91
+ }
92
+
85
93
  setValue(selector, value, field) {
86
94
  return this.chain(() =>
87
95
  this.action(`${this.uiname}.setValue for ${field}`)
@@ -100,7 +108,7 @@ class AppDriver {
100
108
 
101
109
  uncheck(selector, field) {
102
110
  return this.chain(() =>
103
- this.action(`${this.constructor.name}.uncheck ${field}`)
111
+ this.action(`${this.uiname}.uncheck ${field}`)
104
112
  .click(selector, `Click at ${field}`)
105
113
  .hasElements(
106
114
  `${selector}:not(:checked)`,
@@ -109,6 +117,13 @@ class AppDriver {
109
117
  );
110
118
  }
111
119
 
120
+ execute(script, descr) {
121
+ return this.chain(() =>
122
+ this.action(`${this.uiname}.execute ${descr}`)
123
+ .executeScript(script, `Execute script`)
124
+ );
125
+ }
126
+
112
127
  // Returns a name for the tested class. Typically the name convension for
113
128
  // UI drivers is a test class name postixed by Driver.
114
129
  get uiname() {
@@ -169,13 +169,47 @@ class Driver extends DriverBase {
169
169
  );
170
170
  }
171
171
 
172
+ /**
173
+ * Waits untils an element defined by a selector has attribute.
174
+ */
175
+ hasAttribute(selector, attr, msg) {
176
+ assert(selector, `hasAttribute: no selector`);
177
+ assert(attr, `hasAttribute: no attr`);
178
+ assert(msg, `hasAttribute: no msg`);
179
+
180
+ return this.matchAttribute({
181
+ selector,
182
+ attr,
183
+ msg,
184
+ test: got => got !== null,
185
+ expected_stringified: stringify(null),
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Waits untils an element defined by a selector has no attribute.
191
+ */
192
+ noAttribute(selector, attr, msg) {
193
+ assert(selector, `noAttribute: no selector`);
194
+ assert(attr, `noAttribute: no attr`);
195
+ assert(msg, `noAttribute: no msg`);
196
+
197
+ return this.matchAttribute({
198
+ selector,
199
+ attr,
200
+ msg,
201
+ test: got => got === null,
202
+ expected_stringified: stringify(null),
203
+ });
204
+ }
205
+
172
206
  /**
173
207
  * Waits untils an element defined by a selector has attribute of a given value.
174
208
  */
175
209
  attributeIs(selector, attr, value, msg) {
176
210
  assert(selector, `attributeIs: no selector`);
177
211
  assert(attr, `attributeIs: no attr`);
178
- assert(value != undefined, `attributeIs: no value`);
212
+ assert(value !== undefined, `attributeIs: no value`);
179
213
  assert(msg, `attributeIs: no msg`);
180
214
 
181
215
  return this.matchAttribute({
@@ -65,6 +65,26 @@ function warn_if_stale(e, msg) {
65
65
 
66
66
  class TestExecutionError extends Error {}
67
67
 
68
+ class CriteriaTimeoutError extends Error {
69
+ constructor() {
70
+ super(`timeout while waiting to meet criteria`);
71
+ }
72
+ }
73
+
74
+ class NoElementsError extends Error {
75
+ constructor(selector) {
76
+ super(`no elements matching '${selector}' selector`);
77
+ }
78
+ }
79
+
80
+ class UnexpectedElementCountError extends Error {
81
+ constructor(selector, gotCount, expectedCount) {
82
+ super(
83
+ `ambigious '${selector}' selector, got ${gotCount} elements, expected ${expectedCount}`
84
+ );
85
+ }
86
+ }
87
+
68
88
  /**
69
89
  * A chainable wrapper around selenium web driver, provides barebone methods
70
90
  * to build webdrivers upon.
@@ -424,15 +444,17 @@ class DriverBase {
424
444
  'Waiting for at least one element to be located'
425
445
  )
426
446
  ) {
427
- throw new Error(`no elements matching '${selector}' selector`);
447
+ throw new NoElementsError(selector);
428
448
  }
429
449
  }
430
450
  throw e;
431
451
  })
432
452
  .then(els => {
433
453
  if (els.length > count) {
434
- throw new Error(
435
- `ambigious '${selector}' selector, got ${els.length} elements, expected ${count}`
454
+ throw new UnexpectedElementCountError(
455
+ selector,
456
+ els.length,
457
+ count
436
458
  );
437
459
  }
438
460
  return els;
@@ -665,7 +687,7 @@ class DriverBase {
665
687
  ) {
666
688
  this.checkBreadcrumbs(get_breadcrumbs);
667
689
  if (e.message.startsWith(`Waiting until meet criteria`)) {
668
- throw new Error(`timeout while waiting to meet criteria`);
690
+ throw new CriteriaTimeoutError();
669
691
  }
670
692
  }
671
693
  throw e;
@@ -803,9 +825,7 @@ class DriverBase {
803
825
 
804
826
  return this.chain(() =>
805
827
  Promise.resolve()
806
- .then(() =>
807
- log(`Test: ${msg}${(details && `. ${details}`) || ''}`)
808
- )
828
+ .then(() => log(`Test: ${msg}${(details && `. ${details}`) || ''}`))
809
829
  .then(() => chain())
810
830
  .then(v => this.browserLogs().then(() => v))
811
831
  .then(v => {
@@ -830,6 +850,13 @@ class DriverBase {
830
850
  }`;
831
851
  }
832
852
  report(`${msg}${fdetails}`);
853
+ if (
854
+ !(e instanceof CriteriaTimeoutError) &&
855
+ !(e instanceof NoElementsError) &&
856
+ !(e instanceof UnexpectedElementCountError)
857
+ ) {
858
+ log_error(e);
859
+ }
833
860
  })
834
861
  .then(() => this.captureScreenshot())
835
862
  .catch(e => {