testaro 5.12.3 → 5.13.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/run.js +37 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "5.12.3",
3
+ "version": "5.13.0",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -24,9 +24,9 @@ const moves = {
24
24
  focus: true,
25
25
  link: 'a, [role=link]',
26
26
  radio: 'input[type=radio]',
27
- search: 'input[type=search], input[type=text][aria-label*=search i]',
27
+ search: 'input[type=search], input[aria-label*=search i], input[placeholder*=search i]',
28
28
  select: 'select',
29
- text: 'input[type=text]'
29
+ text: 'input[type=text], input:not([type])'
30
30
  };
31
31
  // Names and descriptions of tests.
32
32
  const tests = {
@@ -114,6 +114,7 @@ let actCount = 0;
114
114
  let browser;
115
115
  let browserContext;
116
116
  let browserTypeName;
117
+ let currentPage;
117
118
  let requestedURL = '';
118
119
 
119
120
  // ########## VALIDATORS
@@ -273,6 +274,8 @@ const browserClose = async () => {
273
274
  await browser.close();
274
275
  }
275
276
  };
277
+ // Returns the first line of an error message.
278
+ const errorStart = error => error.message.replace(/\n.+/s, '');
276
279
  // Launches a browser.
277
280
  const launch = async typeName => {
278
281
  const browserType = require('playwright')[typeName];
@@ -292,15 +295,15 @@ const launch = async typeName => {
292
295
  browser = await browserType.launch(browserOptions)
293
296
  .catch(error => {
294
297
  healthy = false;
295
- console.log(`ERROR launching browser: ${error.message.replace(/\n.+/s, '')}`);
298
+ console.log(`ERROR launching browser (${errorStart(error)})`);
296
299
  });
297
300
  // If the launch succeeded:
298
301
  if (healthy) {
299
302
  browserContext = await browser.newContext();
300
303
  // When a page (i.e. browser tab) is added to the browser context (i.e. browser window):
301
304
  browserContext.on('page', async page => {
302
- // Activate the page.
303
- await page.bringToFront();
305
+ // Make the page current.
306
+ currentPage = page;
304
307
  // Make abbreviations of its console messages get reported in the Playwright console.
305
308
  page.on('console', msg => {
306
309
  const msgText = msg.text();
@@ -335,11 +338,11 @@ const launch = async typeName => {
335
338
  });
336
339
  });
337
340
  // Open the first page of the context.
338
- const page = await browserContext.newPage();
341
+ currentPage = await browserContext.newPage();
339
342
  // Wait until it is stable.
340
- await page.waitForLoadState('domcontentloaded');
343
+ await currentPage.waitForLoadState('domcontentloaded', {timeout: 15000});
341
344
  // Update the name of the current browser type and store it in the page.
342
- page.browserTypeName = browserTypeName = typeName;
345
+ currentPage.browserTypeName = browserTypeName = typeName;
343
346
  }
344
347
  }
345
348
  };
@@ -450,7 +453,7 @@ const goto = async (page, url, timeout, waitUntil, isStrict) => {
450
453
  waitUntil
451
454
  })
452
455
  .catch(error => {
453
- console.log(`ERROR: Visit to ${url} timed out before ${waitUntil} (${error.message})`);
456
+ console.log(`ERROR: Visit to ${url} timed out before ${waitUntil} (${errorStart(error)})`);
454
457
  visitTimeoutCount++;
455
458
  return 'error';
456
459
  });
@@ -1023,33 +1026,36 @@ const doActs = async (report, actIndex, page) => {
1023
1026
  // If a match was found:
1024
1027
  if (act.result.found) {
1025
1028
  // FUNCTION DEFINITION START
1026
- // Perform a click or Enter keypress and wait for a page load.
1027
- const doAndWait = async actionIsClick => {
1029
+ // Perform a click or Enter keypress and wait for the network to be idle.
1030
+ const doAndWait = async isClick => {
1031
+ const move = isClick ? 'click' : 'Enter keypress';
1028
1032
  try {
1029
- const [newPage] = await Promise.all([
1030
- page.context().waitForEvent('page', {timeout: 15000}),
1031
- actionIsClick ? selection.click({timeout: 4000}) : selection.press('Enter')
1032
- ]);
1033
- // Wait for the new page to load.
1034
- await newPage.waitForLoadState('domcontentloaded', {timeout: 15000});
1035
- // Make the new page the current page.
1036
- page = newPage;
1033
+ await isClick
1034
+ ? selection.click({timeout: 4000})
1035
+ : selection.press('Enter', {timeout: 4000});
1037
1036
  act.result.success = true;
1038
- act.result.move = actionIsClick ? 'clicked' : 'Enter pressed';
1039
- act.result.newURL = page.url();
1037
+ act.result.move = move;
1040
1038
  }
1041
- // If the action, event, or load failed:
1042
1039
  catch(error) {
1043
- // Quit and report the failure.
1044
- const action = actionIsClick ? 'clicking' : 'pressing Enter';
1045
- console.log(
1046
- `ERROR ${action} (${error.message.replace(/\n.+/s, '')})`
1047
- );
1048
1040
  act.result.success = false;
1049
1041
  act.result.error = 'moveFailure';
1050
- act.result.message = 'ERROR: move, navigation, or load timed out';
1042
+ act.result.message = `ERROR: ${move} failed`;
1043
+ console.log(`ERROR: ${move} failed (${errorStart(error)})`);
1051
1044
  actIndex = -2;
1052
1045
  }
1046
+ if (act.result.success) {
1047
+ try {
1048
+ await page.context().waitForEvent('networkidle', {timeout: 10000});
1049
+ act.result.idleTimely = true;
1050
+ }
1051
+ catch(error) {
1052
+ console.log(`ERROR: Network busy after ${move} (${errorStart(error)})`);
1053
+ act.result.idleTimely = false;
1054
+ }
1055
+ // If the move created a new page, make it current.
1056
+ page = currentPage;
1057
+ act.result.newURL = page.url();
1058
+ }
1053
1059
  };
1054
1060
  // FUNCTION DEFINITION END
1055
1061
  // If the move is a button click, perform it.
@@ -1105,7 +1111,7 @@ const doActs = async (report, actIndex, page) => {
1105
1111
  act.result.target = target || 'DEFAULT';
1106
1112
  // If the destination is a new page:
1107
1113
  if (target && target !== '_self') {
1108
- // Click the link and wait for the resulting page event.
1114
+ // Click the link and wait for the network to be idle.
1109
1115
  doAndWait(true);
1110
1116
  }
1111
1117
  // Otherwise, i.e. if the destination is in the current page:
@@ -1122,9 +1128,7 @@ const doActs = async (report, actIndex, page) => {
1122
1128
  // If the click or load failed:
1123
1129
  catch(error) {
1124
1130
  // Quit and report the failure.
1125
- console.log(
1126
- `ERROR clicking link (${error.message.replace(/\n.+/s, '')})`
1127
- );
1131
+ console.log(`ERROR clicking link (${errorStart(error)})`);
1128
1132
  act.result.success = false;
1129
1133
  act.result.error = 'unclickable';
1130
1134
  act.result.message = 'ERROR: click or load timed out';
@@ -1185,7 +1189,7 @@ const doActs = async (report, actIndex, page) => {
1185
1189
  act.result.move = 'entered';
1186
1190
  // If the input is a search input:
1187
1191
  if (act.type === 'search') {
1188
- // Press the Enter key and wait for a new page to load.
1192
+ // Press the Enter key and wait for a network to be idle.
1189
1193
  doAndWait(false);
1190
1194
  }
1191
1195
  }