Skip to content

Commit

Permalink
fix: wait selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pgagnidze committed Mar 19, 2024
1 parent e42de87 commit ada3555
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@ node_modules
recordings/*
yarn-error.log
.DS_Store
dist
dist
owloops/e2e
31 changes: 6 additions & 25 deletions src/OwloopsStringifyExtension.ts
Expand Up @@ -281,14 +281,6 @@ function filterArrayByString(selectors: Schema.Selector[], value: string) {
);
}

function filterArrayByStringForWaitForElementStep(selectors: string[], value: string) {
return selectors.filter((selector) =>
value === "aria/"
? !selector.includes(value)
: selector.includes(value)
);
}

function handleSelectors(
selectors: Schema.Selector[],
flow?: Schema.UserFlow
Expand All @@ -312,27 +304,16 @@ function handleSelectors(
}

function handleSelectorsForWaitForElementStep(
selectors: string[],
selectors: Array<string[] | string>,
flow?: Schema.UserFlow
): string | undefined {
// Remove Aria selectors in favor of DOM selectors
const nonAriaSelectors = filterArrayByStringForWaitForElementStep(selectors, "aria/");

let preferredSelector;
const allSelectors = selectors.flat().filter(Boolean);

// Give preference to user-specified selectors
if (flow?.selectorAttribute) {
preferredSelector = filterArrayByStringForWaitForElementStep(
nonAriaSelectors,
flow.selectorAttribute
);
}
const chosenSelector = allSelectors.find(selector =>
selector.startsWith(flow?.selectorAttribute ?? '')
) ?? allSelectors[0];

if (preferredSelector && preferredSelector.length > 0) {
return formatAsJSLiteral(preferredSelector[0]);
} else {
return formatAsJSLiteral(nonAriaSelectors[0]);
}
return formatAsJSLiteral(chosenSelector);
}

function ariaSelectors(selectors: Schema.Selector[]): string | undefined {
Expand Down

0 comments on commit ada3555

Please sign in to comment.