chore: generate get by title (#19119)
This commit is contained in:
Родитель
65b0fb055d
Коммит
85467d1b7d
|
@ -35,6 +35,7 @@ const kLabelScore = 3;
|
|||
const kRoleWithNameScore = 5;
|
||||
const kAltTextScore = 10;
|
||||
const kTextScore = 15;
|
||||
const kTitleScore = 20;
|
||||
const kCSSIdScore = 100;
|
||||
const kRoleWithoutNameScore = 140;
|
||||
const kCSSInputTypeNameScore = 150;
|
||||
|
@ -193,6 +194,9 @@ function buildCandidates(injectedScript: InjectedScript, element: Element, testI
|
|||
if (element.getAttribute('name') && ['BUTTON', 'FORM', 'FIELDSET', 'FRAME', 'IFRAME', 'INPUT', 'KEYGEN', 'OBJECT', 'OUTPUT', 'SELECT', 'TEXTAREA', 'MAP', 'META', 'PARAM'].includes(element.nodeName))
|
||||
candidates.push({ engine: 'css', selector: `${cssEscape(element.nodeName.toLowerCase())}[name=${quoteAttributeValue(element.getAttribute('name')!)}]`, score: kCSSInputTypeNameScore });
|
||||
|
||||
if (element.getAttribute('title'))
|
||||
candidates.push({ engine: 'internal:attr', selector: `[title=${escapeForAttributeSelector(element.getAttribute('title')!, false)}]`, score: kTitleScore });
|
||||
|
||||
if (['INPUT', 'TEXTAREA'].includes(element.nodeName) && element.getAttribute('type') !== 'hidden') {
|
||||
if (element.getAttribute('type'))
|
||||
candidates.push({ engine: 'css', selector: `${cssEscape(element.nodeName.toLowerCase())}[type=${quoteAttributeValue(element.getAttribute('type')!)}]`, score: kCSSInputTypeNameScore });
|
||||
|
|
|
@ -406,4 +406,12 @@ it.describe('selector generator', () => {
|
|||
await page.setContent(`<input type=checkbox><div data-testid=wrapper><input type=checkbox></div>`);
|
||||
expect(await generate(page, '[data-testid=wrapper] > input')).toBe('internal:testid=[data-testid="wrapper"s] >> internal:role=checkbox');
|
||||
});
|
||||
|
||||
it('should generate title selector', async ({ page }) => {
|
||||
await page.setContent(`<div>
|
||||
<button title="Send to">Send</button>
|
||||
<button>Send</button>
|
||||
</div>`);
|
||||
expect(await generate(page, 'button')).toBe('internal:attr=[title=\"Send to\"i]');
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче