chore: do not carry selector next to parsed selector (#10004)
This commit is contained in:
parent
9cebe60831
commit
2ae2136810
|
|
@ -19,10 +19,10 @@ import { CSSComplexSelectorList, parseCSS } from './cssParser';
|
|||
export type ParsedSelectorPart = {
|
||||
name: string,
|
||||
body: string | CSSComplexSelectorList,
|
||||
source: string,
|
||||
};
|
||||
|
||||
export type ParsedSelector = {
|
||||
selector: string,
|
||||
parts: ParsedSelectorPart[],
|
||||
capture?: number,
|
||||
};
|
||||
|
|
@ -43,18 +43,22 @@ export function parseSelector(selector: string): ParsedSelector {
|
|||
const parsedCSS = parseCSS(part.body, customCSSNames);
|
||||
return {
|
||||
name: 'css',
|
||||
body: parsedCSS.selector
|
||||
body: parsedCSS.selector,
|
||||
source: part.body
|
||||
};
|
||||
}
|
||||
return part;
|
||||
return { ...part, source: part.body };
|
||||
});
|
||||
return {
|
||||
selector,
|
||||
capture: result.capture,
|
||||
parts
|
||||
};
|
||||
}
|
||||
|
||||
export function stringifySelector(selector: ParsedSelector): string {
|
||||
return selector.parts.map((p, i) => `${i === selector.capture ? '*' : ''}${p.name}=${p.source}`).join(' >> ');
|
||||
}
|
||||
|
||||
function parseSelectorString(selector: string): ParsedSelectorStrings {
|
||||
let index = 0;
|
||||
let quote: string | undefined;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import { SelectorEngine, SelectorRoot } from './selectorEngine';
|
|||
import { XPathEngine } from './xpathSelectorEngine';
|
||||
import { ReactEngine } from './reactSelectorEngine';
|
||||
import { VueEngine } from './vueSelectorEngine';
|
||||
import { ParsedSelector, ParsedSelectorPart, parseSelector } from '../common/selectorParser';
|
||||
import { ParsedSelector, ParsedSelectorPart, parseSelector, stringifySelector } from '../common/selectorParser';
|
||||
import { SelectorEvaluatorImpl, isVisible, parentElementOrShadowHost, elementMatchesText, TextMatcher, createRegexTextMatcher, createStrictTextMatcher, createLaxTextMatcher } from './selectorEvaluator';
|
||||
import { CSSComplexSelectorList } from '../common/cssParser';
|
||||
import { generateSelector } from './selectorGenerator';
|
||||
|
|
@ -757,7 +757,7 @@ export class InjectedScript {
|
|||
const lines = infos.map((info, i) => `\n ${i + 1}) ${info.preview} aka playwright.$("${info.selector}")`);
|
||||
if (infos.length < matches.length)
|
||||
lines.push('\n ...');
|
||||
return this.createStacklessError(`strict mode violation: "${selector.selector}" resolved to ${matches.length} elements:${lines.join('')}\n`);
|
||||
return this.createStacklessError(`strict mode violation: "${stringifySelector(selector)}" resolved to ${matches.length} elements:${lines.join('')}\n`);
|
||||
}
|
||||
|
||||
createStacklessError(message: string): Error {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import { createGuid } from '../utils/utils';
|
|||
export type SelectorInfo = {
|
||||
parsed: ParsedSelector,
|
||||
world: types.World,
|
||||
selector: string,
|
||||
strict: boolean,
|
||||
};
|
||||
|
||||
|
|
@ -141,7 +140,6 @@ export class Selectors {
|
|||
}
|
||||
return {
|
||||
parsed,
|
||||
selector,
|
||||
world: needsMainWorld ? 'main' : 'utility',
|
||||
strict,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue