@camperaid/watest 2.4.0 → 2.4.3

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/.watestrc.js CHANGED
@@ -53,6 +53,12 @@ const cfg = {
53
53
  * Servicer module.
54
54
  */
55
55
  servicer: process.env.WATEST_SERVICER_MODULE,
56
+
57
+ /**
58
+ * Regular expression defining a file name pattern
59
+ * to exclude from the tests.
60
+ */
61
+ ignore_pattern: process.env.WATEST_IGNORE_PATTERN,
56
62
  };
57
63
 
58
64
  module.exports = cfg;
package/core/base.js CHANGED
@@ -123,7 +123,11 @@ function contains(
123
123
  })
124
124
  )
125
125
  ) {
126
- fail_(`${msg}, array has no expected item ${stringify(e)}`);
126
+ fail_(
127
+ `${msg}, array has no expected item ${stringify(e)}, got: ${stringify(
128
+ got
129
+ )}`
130
+ );
127
131
  return false;
128
132
  }
129
133
  }
package/core/series.js CHANGED
@@ -878,7 +878,11 @@ class Series {
878
878
  getTestFileList(folder) {
879
879
  return fs
880
880
  .readdirSync(path.join(root_dir, folder))
881
- .filter(n => n.startsWith('t_'));
881
+ .filter(
882
+ n =>
883
+ n.startsWith('t_') &&
884
+ (!settings.ignorePattern || !settings.ignorePattern.test(n))
885
+ );
882
886
  }
883
887
 
884
888
  performInChildProcess({ name, path, loader, webdriver }) {
package/core/settings.js CHANGED
@@ -46,6 +46,10 @@ class Settings {
46
46
  return this._invocation;
47
47
  }
48
48
 
49
+ get ignorePattern() {
50
+ return rc.ignore_pattern && new RegExp(rc.ignore_pattern);
51
+ }
52
+
49
53
  get debunkLimit() {
50
54
  return parseInt(rc.debunk_limit) || 5;
51
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camperaid/watest",
3
- "version": "2.4.0",
3
+ "version": "2.4.3",
4
4
  "description": "Web Application Testsuite",
5
5
  "engines": {
6
6
  "node": ">=14.15.1"
@@ -47,7 +47,7 @@ module.exports.test = async () => {
47
47
  await is_output(
48
48
  () => contains([0, 1], [1, 3], `Array contains`),
49
49
  [],
50
- [`Failed: Array contains, array has no expected item 3`],
50
+ [`Failed: Array contains, array has no expected item 3, got: [0, 1]`],
51
51
  `failure`
52
52
  );
53
53
  };
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ const { do_self_tests, is_failure_output, is_ok_output } = require('./test.js');
4
+
5
+ const snippet = `
6
+ <html><body>
7
+ <input id='input-not-visible' hidden>
8
+ <input id='input-visible' value='hey'>
9
+ </body></html>
10
+ `;
11
+
12
+ module.exports.test = do_self_tests(snippet, async ({ driver }) => {
13
+ // noElementsOrNotVisible: no elements: success
14
+ await is_ok_output(
15
+ () =>
16
+ driver.noElementsOrNotVisible(
17
+ '#input-doesnot-exist',
18
+ `noElementsOrNotVisible`
19
+ ),
20
+ [
21
+ `Test: noElementsOrNotVisible. Selector: '#input-doesnot-exist'`,
22
+ `Ok: noElementsOrNotVisible`,
23
+ ],
24
+ [],
25
+ `noElementsOrNotVisible:no elements: success`
26
+ );
27
+
28
+ // noElementsOrNotVisible: not visible: success
29
+ await is_ok_output(
30
+ () =>
31
+ driver.noElementsOrNotVisible(
32
+ '#input-not-visible',
33
+ `noElementsOrNotVisible`
34
+ ),
35
+ [
36
+ `Test: noElementsOrNotVisible. Selector: '#input-not-visible'`,
37
+ `Ok: noElementsOrNotVisible`,
38
+ ],
39
+ [],
40
+ `noElementsOrNotVisible:not visible:success`
41
+ );
42
+
43
+ // noElementsOrNotVisible: visible: failure
44
+ await is_failure_output(
45
+ driver,
46
+ () =>
47
+ driver.noElementsOrNotVisible('#input-visible', `noElementsOrNotVisible`),
48
+ [`Test: noElementsOrNotVisible. Selector: '#input-visible'`],
49
+ [
50
+ `Failed: noElementsOrNotVisible, timeout while waiting to meet criteria`,
51
+ `Failed: noElementsOrNotVisible. Failure details: Got elements count: 1, elements visibility [true], expected: not visible`,
52
+ ],
53
+ `noElementsOrNotVisible:visible:failure`
54
+ );
55
+ });
@@ -76,7 +76,7 @@ unexpected character: 'y' at 2 pos, expected: 'o' at '' line`,
76
76
  ),
77
77
  [`Test: scriptRetvalContains. Expected: ['heo']`],
78
78
  [
79
- `Failed: script retval contains ['heo'], array has no expected item 'heo'`,
79
+ `Failed: script retval contains ['heo'], array has no expected item 'heo', got: ['hey', 'bo']`,
80
80
  `Failed: scriptRetvalContains, timeout while waiting to meet criteria`,
81
81
  `Failed: scriptRetvalContains`,
82
82
  ],
@@ -486,21 +486,25 @@ class Driver extends DriverBase {
486
486
  * Picks file(s) in a file input.
487
487
  */
488
488
  pickFile(selector, path, msg) {
489
- assert(selector, `pickFile: no selector`);
490
- assert(path, `pickFile: no path`);
491
- assert(msg, `pickFile: no msg`);
492
- return this.waitForElementToInvoke(selector, el => el.sendKeys(path), msg);
489
+ return this.pickFiles(selector, [path], msg);
493
490
  }
494
491
 
495
492
  pickFiles(selector, paths, msg) {
496
493
  assert(selector, `pickFiles: no selector`);
497
494
  assert(paths, `pickFiles: no paths`);
498
495
  assert(msg, `pickFiles: no msg`);
499
- return this.waitForElementToInvoke(
500
- selector,
501
- el => el.sendKeys(paths.join('\n')),
502
- msg
503
- );
496
+
497
+ return this.chain(async () => {
498
+ // Clear previosly set value if any.
499
+ await this.setProperty(selector, 'value', '', msg);
500
+
501
+ // Send keys to upload files.
502
+ await this.waitForElementToInvoke(
503
+ selector,
504
+ el => el.sendKeys(paths.join('\n')),
505
+ msg
506
+ );
507
+ });
504
508
  }
505
509
 
506
510
  //
@@ -930,6 +934,39 @@ else {
930
934
  return this.elementsCount(selector, 0, msg);
931
935
  }
932
936
 
937
+ /**
938
+ * Waits until no elements in DOM or no elements is visible.
939
+ */
940
+ noElementsOrNotVisible(selector, msg) {
941
+ assert(selector, `noElementsOrNotVisible: no selector`);
942
+ assert(msg, `noElementsOrNotVisible: no msg`);
943
+
944
+ let breadcrumbs = '';
945
+ let cond = new Condition(`until no elements or not visible`, async () => {
946
+ let els = await this.dvr.findElements(By.css(selector));
947
+ breadcrumbs = `Got elements count: ${els.length}, expected 0`;
948
+ if (els.length == 0) {
949
+ return true;
950
+ }
951
+ let isDisplayedArray = await Promise.all(
952
+ Array.from(els).map(el => el.isDisplayed())
953
+ );
954
+ breadcrumbs = `Got elements count: ${
955
+ els.length
956
+ }, elements visibility [${isDisplayedArray.join(
957
+ ' ,'
958
+ )}], expected: not visible`;
959
+ return isDisplayedArray.every(isDisplayed => !isDisplayed);
960
+ });
961
+
962
+ return this.run(
963
+ () => this.waitForCondition(cond, () => breadcrumbs),
964
+ msg,
965
+ `Selector: '${selector}'`,
966
+ () => breadcrumbs
967
+ );
968
+ }
969
+
933
970
  /**
934
971
  * Waits until elements count is not zero.
935
972
  */
@@ -686,7 +686,7 @@ class DriverBase {
686
686
  e instanceof error.ScriptTimeoutError
687
687
  ) {
688
688
  this.checkBreadcrumbs(get_breadcrumbs);
689
- if (e.message.startsWith(`Waiting until meet criteria`)) {
689
+ if (e.message.startsWith(`Waiting until`)) {
690
690
  throw new CriteriaTimeoutError();
691
691
  }
692
692
  }