testaro 45.0.6 → 45.0.7
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/package.json +1 -1
- package/procs/identify.js +36 -26
package/package.json
CHANGED
package/procs/identify.js
CHANGED
|
@@ -170,35 +170,45 @@ exports.identify = async (instance, page) => {
|
|
|
170
170
|
}
|
|
171
171
|
// If either ID remains undefined and the instance specifies a tag name:
|
|
172
172
|
if (tagName && ! (elementID.boxID && elementID.pathID)) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
173
|
+
try {
|
|
174
|
+
// Get locators for elements with the tag name.
|
|
175
|
+
let locators = page.locator(tagName);
|
|
176
|
+
// If there is exactly 1 of them:
|
|
177
|
+
let locatorCount = await locators.count();
|
|
178
|
+
if (locatorCount === 1) {
|
|
179
|
+
// Add a box ID and a path ID to the result.
|
|
180
|
+
await addIDs(locators, elementID);
|
|
181
|
+
}
|
|
182
|
+
// If either ID remains undefined and the instance also specifies an excerpt:
|
|
183
|
+
if (excerpt && ! (elementID.boxID && elementID.pathID)) {
|
|
184
|
+
// Get the plain text parts of the excerpt, converting ... to an empty string.
|
|
185
|
+
const minTagExcerpt = excerpt.replace(/<[^>]+>/g, '<>');
|
|
186
|
+
const plainParts = (minTagExcerpt.match(/[^<>]+/g) || [])
|
|
187
|
+
.map(part => part === '...' ? '' : part);
|
|
188
|
+
// Get the longest of them.
|
|
189
|
+
const sortedPlainParts = plainParts.sort((a, b) => b.length - a.length);
|
|
190
|
+
const mainPart = sortedPlainParts.length ? sortedPlainParts[0] : '';
|
|
191
|
+
// If there is one:
|
|
192
|
+
if (mainPart.trim().replace(/\s+/g, '').length) {
|
|
193
|
+
// Get locators for elements with the tag name and the text.
|
|
194
|
+
const locators = page.locator(tagName.toLowerCase(), {hasText: mainPart});
|
|
195
|
+
// If there is exactly 1 of them:
|
|
196
|
+
const locatorCount = await locators.count();
|
|
197
|
+
if (locatorCount === 1) {
|
|
198
|
+
// Add a box ID and a path ID to the result.
|
|
199
|
+
await addIDs(locators, elementID);
|
|
200
|
+
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
203
|
}
|
|
204
|
+
// If the tag name is invalid:
|
|
205
|
+
catch(error) {
|
|
206
|
+
// Add this to the instance.
|
|
207
|
+
instance.invalidity = {
|
|
208
|
+
badProperty: 'tagName',
|
|
209
|
+
validityError: error.message
|
|
210
|
+
};
|
|
211
|
+
}
|
|
202
212
|
}
|
|
203
213
|
// Return the result (not yet getting IDs from Nu Html Checker lines and columns).
|
|
204
214
|
return elementID;
|