testaro 5.11.0 → 5.11.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/run.js +41 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "5.11.0",
3
+ "version": "5.11.3",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -12,7 +12,7 @@ const {commands} = require('./commands');
12
12
 
13
13
  // ########## CONSTANTS
14
14
 
15
- // Set DEBUG environment variable to 'true,' to add debugging features.
15
+ // Set DEBUG environment variable to 'true' to add debugging features.
16
16
  const debug = process.env.DEBUG === 'true';
17
17
  // Set WAITS environment variable to a positive number to insert delays (in ms).
18
18
  const waits = Number.parseInt(process.env.WAITS) || 0;
@@ -492,11 +492,11 @@ const visit = async (act, page, isStrict) => {
492
492
  // Identify the URL.
493
493
  const resolved = act.which.replace('__dirname', __dirname);
494
494
  requestedURL = resolved;
495
- // Visit it and wait 15 seconds or until the network is idle.
495
+ // Visit it and wait until the network is idle.
496
496
  let response = await goto(page, requestedURL, 15000, 'networkidle', isStrict);
497
497
  // If the visit fails:
498
498
  if (response === 'error') {
499
- // Try again, but waiting 10 seconds or until the DOM is loaded.
499
+ // Try again until the DOM is loaded.
500
500
  response = await goto(page, requestedURL, 10000, 'domcontentloaded', isStrict);
501
501
  // If the visit fails:
502
502
  if (response === 'error') {
@@ -507,15 +507,15 @@ const visit = async (act, page, isStrict) => {
507
507
  await launch(newBrowserName);
508
508
  // Identify its only page as current.
509
509
  page = browserContext.pages()[0];
510
- // Try again, waiting 10 seconds or until the network is idle.
510
+ // Try again until the network is idle.
511
511
  response = await goto(page, requestedURL, 10000, 'networkidle', isStrict);
512
512
  // If the visit fails:
513
513
  if (response === 'error') {
514
- // Try again, but waiting 5 seconds or until the DOM is loaded.
514
+ // Try again until the DOM is loaded.
515
515
  response = await goto(page, requestedURL, 5000, 'domcontentloaded', isStrict);
516
516
  // If the visit fails:
517
517
  if (response === 'error') {
518
- // Try again, waiting 5 seconds or until a load.
518
+ // Try again or until a load.
519
519
  response = await goto(page, requestedURL, 5000, 'load', isStrict);
520
520
  // If the visit fails:
521
521
  if (response === 'error') {
@@ -619,14 +619,15 @@ const doActs = async (report, actIndex, page) => {
619
619
  console.log(`>>>> ${act.type}${whichSuffix}`);
620
620
  // Increment the count of commands performed.
621
621
  actCount++;
622
+ act.startTime = Date.now();
622
623
  // If the command is an index changer:
623
624
  if (act.type === 'next') {
624
625
  const condition = act.if;
625
626
  const logSuffix = condition.length === 3 ? ` ${condition[1]} ${condition[2]}` : '';
626
627
  console.log(`>> ${condition[0]}${logSuffix}`);
627
628
  // Identify the act to be checked.
628
- const ifActIndex = report.acts.map(act => act.type !== 'next').lastIndexOf(true,);
629
- // Determine whether its jump condition is true,.
629
+ const ifActIndex = report.acts.map(act => act.type !== 'next').lastIndexOf(true);
630
+ // Determine whether its jump condition is true.
630
631
  const truth = isTrue(report.acts[ifActIndex].result, condition);
631
632
  // Add the result to the act.
632
633
  act.result = {
@@ -636,7 +637,7 @@ const doActs = async (report, actIndex, page) => {
636
637
  value: truth[0],
637
638
  jumpRequired: truth[1]
638
639
  };
639
- // If the condition is true,:
640
+ // If the condition is true:
640
641
  if (truth[1]) {
641
642
  // If the performance of commands is to stop:
642
643
  if (act.jump === 0) {
@@ -676,7 +677,7 @@ const doActs = async (report, actIndex, page) => {
676
677
  const result = act.result = {};
677
678
  // If the text is to be the URL:
678
679
  if (what === 'url') {
679
- // Wait for it up to 15 seconds and quit on failure.
680
+ // Wait for it and quit on failure.
680
681
  try {
681
682
  await page.waitForURL(which, {timeout: 15000});
682
683
  result.found = true;
@@ -689,7 +690,7 @@ const doActs = async (report, actIndex, page) => {
689
690
  }
690
691
  // Otherwise, if the text is to be a substring of the page title:
691
692
  else if (what === 'title') {
692
- // Wait for it up to 5 seconds and quit on failure.
693
+ // Wait for it and quit on failure.
693
694
  try {
694
695
  await page.waitForFunction(
695
696
  text => document
@@ -711,7 +712,7 @@ const doActs = async (report, actIndex, page) => {
711
712
  }
712
713
  // Otherwise, if the text is to be a substring of the text of the page body:
713
714
  else if (what === 'body') {
714
- // Wait for it up to 10 seconds and quit on failure.
715
+ // Wait for it and quit on failure.
715
716
  try {
716
717
  await page.waitForFunction(
717
718
  text => document
@@ -733,10 +734,10 @@ const doActs = async (report, actIndex, page) => {
733
734
  }
734
735
  // Otherwise, if the act is a wait for a state:
735
736
  else if (act.type === 'state') {
736
- // Wait for it up to 5 or 10 seconrds, and quit on failure.
737
+ // Wait for it and quit on failure.
737
738
  const stateIndex = ['loaded', 'idle'].indexOf(act.which);
738
739
  await page.waitForLoadState(
739
- ['domcontentloaded', 'networkidle'][stateIndex], {timeout: [10000, 5000][stateIndex]}
740
+ ['domcontentloaded', 'networkidle'][stateIndex], {timeout: [10000, 15000][stateIndex]}
740
741
  )
741
742
  .catch(error => {
742
743
  console.log(`ERROR waiting for page to be ${act.which} (${error.message})`);
@@ -757,8 +758,8 @@ const doActs = async (report, actIndex, page) => {
757
758
  else if (act.type === 'page') {
758
759
  // Wait for a page to be created and identify it as current.
759
760
  page = await browserContext.waitForEvent('page');
760
- // Wait up to 20 seconds until it is idle.
761
- await page.waitForLoadState('networkidle', {timeout: 20000});
761
+ // Wait until it is idle.
762
+ await page.waitForLoadState('networkidle', {timeout: 15000});
762
763
  // Add the resulting URL to the act.
763
764
  const result = {
764
765
  url: page.url()
@@ -777,7 +778,7 @@ const doActs = async (report, actIndex, page) => {
777
778
  // Make all elements in the page visible.
778
779
  await require('./procs/allVis').allVis(page);
779
780
  act.result = {
780
- success: true,
781
+ success: true
781
782
  };
782
783
  }
783
784
  // Otherwise, if the act is a tenon request:
@@ -943,7 +944,7 @@ const doActs = async (report, actIndex, page) => {
943
944
  // Otherwise, if the act is a move:
944
945
  else if (moves[act.type]) {
945
946
  const selector = typeof moves[act.type] === 'string' ? moves[act.type] : act.what;
946
- // Try for up to 10 seconds to identify the element to perform the move on.
947
+ // Try to identify the element to perform the move on.
947
948
  act.result = {found: false};
948
949
  let selection = {};
949
950
  let tries = 0;
@@ -1085,7 +1086,7 @@ const doActs = async (report, actIndex, page) => {
1085
1086
  selection.click({timeout: 5000})
1086
1087
  ]);
1087
1088
  // Wait for the new page to load.
1088
- await newPage.waitForLoadState('domcontentloaded', {timeout: 6000});
1089
+ await newPage.waitForLoadState('domcontentloaded', {timeout: 10000});
1089
1090
  // Make the new page the current page.
1090
1091
  page = newPage;
1091
1092
  act.result.success = true;
@@ -1100,34 +1101,32 @@ const doActs = async (report, actIndex, page) => {
1100
1101
  );
1101
1102
  act.result.success = false;
1102
1103
  act.result.error = 'unclickable';
1103
- act.result.message = 'ERROR: click and new-page navigation timed out';
1104
+ act.result.message = 'ERROR: click, navigation, or load timed out';
1104
1105
  actIndex = -2;
1105
1106
  }
1106
1107
  }
1107
1108
  // Otherwise, i.e. if the destination is in the current page:
1108
1109
  else {
1109
1110
  // Click the link and wait for the resulting navigation.
1110
- await selection.click({timeout: 5000})
1111
- // If the click and navigation time out:
1112
- .catch(async error => {
1113
- // Try to force-click it and wait for the navigation.
1114
- const errorSummary = error.message.replace(/\n.+/s, '');
1115
- console.log(`ERROR: Link to ${href} not clickable (${errorSummary})`);
1116
- await selection.click({
1117
- force: true,
1118
- timeout: 3000
1119
- })
1120
- // If it cannot be force-clicked:
1121
- .catch(error => {
1122
- // Quit and report the failure.
1123
- actIndex = -2;
1124
- const errorSummary = error.message.replace(/\n.+/s, '');
1125
- console.log(`ERROR: Link to ${href} not force-clickable (${errorSummary})`);
1126
- act.result.success = false;
1127
- act.result.error = 'unclickable';
1128
- act.result.message = 'ERROR: Normal and forced click attempts timed out';
1129
- });
1130
- });
1111
+ try {
1112
+ await selection.click({timeout: 5000});
1113
+ // Wait for the new content to load.
1114
+ await page.waitForLoadState('domcontentloaded', {timeout: 6000});
1115
+ act.result.success = true;
1116
+ act.result.move = 'clicked';
1117
+ act.result.newURL = page.url();
1118
+ }
1119
+ // If the click or load failed:
1120
+ catch(error) {
1121
+ // Quit and report the failure.
1122
+ console.log(
1123
+ `ERROR clicking link (${error.message.replace(/\n.+/s, '')})`
1124
+ );
1125
+ act.result.success = false;
1126
+ act.result.error = 'unclickable';
1127
+ act.result.message = 'ERROR: click or load timed out';
1128
+ actIndex = -2;
1129
+ }
1131
1130
  // If the link click succeeded:
1132
1131
  if (! act.result.error) {
1133
1132
  act.result.success = true;
@@ -1386,6 +1385,7 @@ const doActs = async (report, actIndex, page) => {
1386
1385
  // Add an error result to the act.
1387
1386
  addError(act, 'noPage', 'ERROR: No page identified');
1388
1387
  }
1388
+ act.endTime = Date.now();
1389
1389
  }
1390
1390
  // Otherwise, i.e. if the command is invalid:
1391
1391
  else {