Skip to content

Commit f8e95c3

Browse files
brianhallShane OsbourneshakyShane
authored
add noResultsSelector to extract action (#967)
* Stub out initial noResultsSelector work * opt-out of the extract retry loop --------- Co-authored-by: Shane Osbourne <[email protected]> Co-authored-by: Shane Osbourne <[email protected]>
1 parent 420f044 commit f8e95c3

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

integration-test/playwright/broker-protection.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,25 @@ test.describe('Broker Protection communications', () => {
328328
}])
329329
dbp.responseContainsMetadata(response[0].payload.params.result.success.meta)
330330
})
331+
332+
test('returns an empty array when no profile selector matches but the no results selector is present', async ({ page }, workerInfo) => {
333+
const dbp = BrokerProtectionPage.create(page, workerInfo)
334+
await dbp.enabled()
335+
await dbp.navigatesTo('results-not-found.html')
336+
await dbp.receivesAction('results-not-found-valid.json')
337+
const response = await dbp.waitForMessage('actionCompleted')
338+
dbp.isSuccessMessage(response)
339+
dbp.isExtractMatch(response[0].payload.params.result.success.response, [])
340+
})
341+
342+
test('returns an error when no profile selector matches and the no results selector is not present', async ({ page }, workerInfo) => {
343+
const dbp = BrokerProtectionPage.create(page, workerInfo)
344+
await dbp.enabled()
345+
await dbp.navigatesTo('results.html')
346+
await dbp.receivesAction('results-not-found-invalid.json')
347+
const response = await dbp.waitForMessage('actionCompleted')
348+
dbp.isErrorMessage(response)
349+
})
331350
})
332351
test.describe('Executes action and sends success message', () => {
333352
test('buildUrl', async ({ page }, workerInfo) => {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "extract",
5+
"selector": ".search-item-invalid",
6+
"noResultsSelector": ".none",
7+
"retry": {
8+
"environment": "web",
9+
"interval": { "ms": 1000 },
10+
"maxAttempts": 1
11+
},
12+
"profile": {
13+
"name": {
14+
"selector": "h4"
15+
},
16+
"alternativeNamesList": {
17+
"selector": ".//div[@class='col-sm-24 col-md-16 name']//li",
18+
"findElements": true
19+
},
20+
"age": {
21+
"selector": ".age"
22+
},
23+
"addressCityStateList": {
24+
"selector": ".//div[@class='col-sm-24 col-md-8 location']//li",
25+
"findElements": true
26+
},
27+
"relativesList": {
28+
"selector": ".//div[@class='col-sm-24 col-md-8 relatives']//li",
29+
"beforeText": ","
30+
},
31+
"profileUrl": {
32+
"selector": "a"
33+
}
34+
}
35+
},
36+
"data": {
37+
"userProfile": {
38+
"firstName": "John",
39+
"lastName": "Smith",
40+
"age": "37",
41+
"addresses": [
42+
{
43+
"addressLine1": "123 Fake St",
44+
"city": "Chicago",
45+
"state": "IL",
46+
"zip": "60602"
47+
}
48+
]
49+
}
50+
}
51+
}
52+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "extract",
5+
"id": "efa321f2-f214-411f-a87b-bc42feff7931",
6+
"selector": "[class^='ResultsTable__Record-sc']",
7+
"noResultsSelector": "[class^=ResultNotFound__NoResults]",
8+
"profile": {
9+
"name": {
10+
"selector": "[class^='ResultsTable__Name-sc']"
11+
},
12+
"age": {
13+
"selector": "[class^='ResultsTable__Age-sc']"
14+
},
15+
"addressCityState": {
16+
"selector": ".MuiGrid-item:nth-child(3) [class^='ResultsTable__AddressAndLocation-sc']",
17+
"findElements": true
18+
},
19+
"relativesList": {
20+
"selector": ".MuiGrid-item:nth-child(4) [class^='ResultsTable__AddressAndLocation-sc']",
21+
"findElements": true
22+
},
23+
"profileUrl": {
24+
"identifierType": "hash"
25+
}
26+
}
27+
},
28+
"data": {
29+
"userProfile": {
30+
"firstName": "John",
31+
"lastName": "Smith",
32+
"age": "37",
33+
"addresses": [
34+
{
35+
"addressLine1": "123 Fake St",
36+
"city": "Chicago",
37+
"state": "IL",
38+
"zip": "60602"
39+
}
40+
]
41+
}
42+
}
43+
}
44+
}
45+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="Flow__Main-sc-1w6kigz-0 iKPrxE"><div class="ResultNotFound__NoResults-sc-eoe817-0 cLNexa"><div class="ResultNotFound__Form-sc-eoe817-1 dXkGWS"><div class="ResultNotFound__Top-sc-eoe817-2 cKySto"><div class="ResultNotFound__Headline1-sc-eoe817-3 kjPanq"><strong><span>No Records found</span></strong> for Johny Rogers</div><div class="ResultNotFound__Headline2-sc-eoe817-4 bSqKdu">Hmmm... That was awkward; let's try that again.</div><div class="ResultNotFound__Headline3-sc-eoe817-5 vQvVu">Don't worry! Sometimes this can happen due to a misspelling or trying to get too specific with your search. Try modifying your search and give it another go.</div></div><p class="ResultNotFound__Hint-sc-eoe817-6 gfKTXg">Let 's Try Another Search - Try searching a different state or in 'ALL' states.</p><div class="SearchForm__Form-sc-tuuxa2-0 kjmWuD"><form class="AdvancedSearch__SearchForm-sc-6nx8z2-0 jITUdW"><div class="AdvancedSearch__FirstName-sc-6nx8z2-2 glaLIw"><div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-feqhe6"><label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled MuiFormLabel-colorPrimary MuiFormLabel-filled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled css-1is24bj" data-shrink="true" for=":r0:" id=":r0:-label">First Name</label><div class="MuiInputBase-root MuiFilledInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-e5iuep"><input aria-invalid="false" autocomplete="off" id=":r0:" name="fn" type="text" class="MuiInputBase-input MuiFilledInput-input css-2bxn45" value="johny" data-ddg-inputtype="identities.firstName" data-ddg-autofill="true"></div></div></div><div class="AdvancedSearch__MiddleName-sc-6nx8z2-3 gdxeRj"><div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-feqhe6"><label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-filled MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-filled css-1xpkuh4" data-shrink="false" for=":r1:" id=":r1:-label">MI</label><div class="MuiInputBase-root MuiFilledInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-e5iuep"><input aria-invalid="false" autocomplete="off" id=":r1:" name="mn" type="text" maxlength="1" class="MuiInputBase-input MuiFilledInput-input css-2bxn45" value=""></div></div></div><div class="AdvancedSearch__LastName-sc-6nx8z2-4 eipWSi"><div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-feqhe6"><label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled MuiFormLabel-colorPrimary MuiFormLabel-filled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled css-1is24bj" data-shrink="true" for=":r2:" id=":r2:-label">Last Name</label><div class="MuiInputBase-root MuiFilledInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-e5iuep"><input aria-invalid="false" autocomplete="off" id=":r2:" name="ln" type="text" class="MuiInputBase-input MuiFilledInput-input css-2bxn45" value="rogers" data-ddg-inputtype="identities.lastName" data-ddg-autofill="true"></div></div></div><div class="AdvancedSearch__City-sc-6nx8z2-6 frUkyW"><div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-feqhe6"><label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled MuiFormLabel-colorPrimary MuiFormLabel-filled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled css-1is24bj" data-shrink="true" for=":r3:" id=":r3:-label">City</label><div class="MuiInputBase-root MuiFilledInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-e5iuep"><input aria-invalid="false" autocomplete="off" id=":r3:" name="city" type="text" class="MuiInputBase-input MuiFilledInput-input css-2bxn45" value="dallas" data-ddg-inputtype="identities.addressCity" data-ddg-autofill="true"></div></div></div><div class="AdvancedSearch__State-sc-6nx8z2-7 bTCBse"><div class="MuiFormControl-root MuiFormControl-fullWidth css-tzsjye"><label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled MuiFormLabel-colorPrimary MuiFormLabel-filled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled css-1is24bj" data-shrink="true" id="demo-simple-select-helper-label">State</label><div class="MuiInputBase-root MuiFilledInput-root MuiInputBase-colorPrimary MuiInputBase-formControl css-r68l2g"><select class="MuiNativeSelect-select MuiNativeSelect-filled MuiInputBase-input MuiFilledInput-input css-gbbys0" aria-invalid="false" name="state" data-ddg-inputtype="identities.addressProvince" data-ddg-autofill="true"><option value="ALL">ALL</option><option value="AL">AL</option><option value="AK">AK</option><option value="AZ">AZ</option><option value="AR">AR</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="IA">IA</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="ME">ME</option><option value="MD">MD</option><option value="MA">MA</option><option value="MI">MI</option><option value="MN">MN</option><option value="MS">MS</option><option value="MO">MO</option><option value="MT">MT</option><option value="NE">NE</option><option value="NV">NV</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NY">NY</option><option value="NC">NC</option><option value="ND">ND</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VT">VT</option><option value="VA">VA</option><option value="WA">WA</option><option value="WV">WV</option><option value="WI">WI</option><option value="WY">WY</option></select><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiNativeSelect-icon MuiNativeSelect-iconFilled css-1636szt" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="ArrowDropDownIcon"><path d="M7 10l5 5 5-5z"></path></svg></div></div></div><div class="AdvancedSearch__Age-sc-6nx8z2-5 jaOTMI"><div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-feqhe6"><label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled MuiFormLabel-colorPrimary MuiFormLabel-filled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled css-1is24bj" data-shrink="true" for=":r4:" id=":r4:-label">Age</label><div class="MuiInputBase-root MuiFilledInput-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl css-e5iuep"><input aria-invalid="false" autocomplete="off" id=":r4:" name="age" type="tel" maxlength="3" class="MuiInputBase-input MuiFilledInput-input css-2bxn45" value="88" data-ddg-inputtype="unknown"></div></div></div><div class="AdvancedSearch__SearchNow-sc-6nx8z2-1 flpeJM"><button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-disableElevation MuiButton-fullWidth MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-disableElevation MuiButton-fullWidth css-1vteyvf" tabindex="0" type="submit">Search Now<span class="MuiTouchRipple-root css-w0pj6f"></span></button></div></form></div></div><div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1 MuiAccordion-root MuiAccordion-rounded ResultNotFound__AccordionSection-sc-eoe817-8 jQqkjv css-v464i3"><div class="MuiButtonBase-root MuiAccordionSummary-root ResultNotFound__AccordionHeader-sc-eoe817-9 hEHgI css-1uaukoe" tabindex="0" role="button" aria-expanded="false"><div class="MuiAccordionSummary-content css-1n11r91"><div class="ResultNotFound__Heading-sc-eoe817-10 lmBIuE">Here are a few tips to improve your search</div></div><div class="MuiAccordionSummary-expandIconWrapper css-1fx8m19"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-yyyj7e" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="ExpandMoreOutlinedIcon"><path d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6-1.41-1.41z"></path></svg></div></div><div class="MuiCollapse-root MuiCollapse-vertical MuiCollapse-hidden css-a0y2e3" style="min-height: 0px;"><div class="MuiCollapse-wrapper MuiCollapse-vertical css-hboir5"><div class="MuiCollapse-wrapperInner MuiCollapse-vertical css-8atqhb"><div role="region" class="MuiAccordion-region"><div class="MuiAccordionDetails-root ResultNotFound__AccordionContent-sc-eoe817-11 ehUuUn css-u7qq7e"><div class="ResultNotFound__Tips-sc-eoe817-7 kSHqma"><ul><li>Double check you spelling</li><li>Start searching with only the information that you know for certain, then narrow down your results if needed.</li><li>Start search a person avoid using nicknames or shortened names (e.g. use Joseph not Joe). Use a nickname or shortened name as a second resort.</li><li>Try different variations of the same name (e.g. Cathryn, Katheryn, Kathy, or Cathy)</li><li>Try misspelling of their name</li><li>Try using their maiden name</li><li>Try using their first initial instead of their full first name</li><li>If the person has moved recently, try searching their previous home state</li></ul></div></div></div></div></div></div></div></div></div>

src/features/broker-protection/actions/extract.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,16 @@ export function extractProfiles (action, userData, root = document) {
8787
const profilesElementList = getElements(root, action.selector) ?? []
8888

8989
if (profilesElementList.length === 0) {
90-
return { error: 'no root elements found for ' + action.selector }
90+
if (!action.noResultsSelector) {
91+
return { error: 'no root elements found for ' + action.selector }
92+
}
93+
94+
// Look for the Results Not Found element
95+
const foundNoResultsElement = getElement(root, action.noResultsSelector)
96+
97+
if (!foundNoResultsElement) {
98+
return { error: 'no results found for ' + action.selector + ' or the no results selector ' + action.noResultsSelector }
99+
}
91100
}
92101

93102
return {

0 commit comments

Comments
 (0)