Files
parcer/server/src/workflow-management/utils.ts

37 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-06-06 05:42:23 +05:30
import { Action, ActionType, TagName } from "../types";
/**
* A helper function to get the best selector for the specific user action.
* @param action The user action.
* @returns {string|null}
* @category WorkflowManagement-Selectors
*/
export const getBestSelectorForAction = (action: Action) => {
switch (action.type) {
case ActionType.Click:
case ActionType.Hover:
case ActionType.DragAndDrop: {
const selectors = action.selectors;
// less than 25 characters, and element only has text inside
const textSelector =
selectors?.text?.length != null &&
selectors?.text?.length < 25 &&
action.hasOnlyText
? `text=${selectors.text}`
: null;
2024-06-06 05:43:16 +05:30
if (action.tagName === TagName.Input) {
return (
selectors.testIdSelector ??
selectors?.id ??
selectors?.formSelector ??
selectors?.accessibilitySelector ??
selectors?.generalSelector ??
selectors?.attrSelector ??
null
);
}
2024-06-06 05:42:23 +05:30
}