(args: string[])
| 108 | } |
| 109 | |
| 110 | export function parseFindArgs(args: string[]): { |
| 111 | locator: FindLocator; |
| 112 | query: string; |
| 113 | action: FindAction['kind']; |
| 114 | value?: string; |
| 115 | timeoutMs?: number; |
| 116 | } { |
| 117 | let locator: FindLocator = 'any'; |
| 118 | let queryIndex = 0; |
| 119 | if (FIND_LOCATOR_TOKENS.includes(args[0] as (typeof FIND_LOCATOR_TOKENS)[number])) { |
| 120 | locator = args[0] as FindLocator; |
| 121 | queryIndex = 1; |
| 122 | } |
| 123 | const query = args[queryIndex] ?? ''; |
| 124 | const actionTokens = args.slice(queryIndex + 1); |
| 125 | if (actionTokens.length === 0) { |
| 126 | return { locator, query, action: 'click' }; |
| 127 | } |
| 128 | const action = actionTokens[0]?.toLowerCase(); |
| 129 | if (action === 'get') { |
| 130 | const sub = actionTokens[1]?.toLowerCase(); |
| 131 | if (sub === 'text') return { locator, query, action: 'get_text' }; |
| 132 | if (sub === 'attrs') return { locator, query, action: 'get_attrs' }; |
| 133 | throw new AppError('INVALID_ARGS', 'find get only supports text or attrs'); |
| 134 | } |
| 135 | if (action === 'wait') { |
| 136 | const timeoutMs = parseTimeout(actionTokens[1]); |
| 137 | return { locator, query, action: 'wait', timeoutMs: timeoutMs ?? undefined }; |
| 138 | } |
| 139 | if (action === 'exists') return { locator, query, action: 'exists' }; |
| 140 | if (action === 'click') return { locator, query, action: 'click' }; |
| 141 | if (action === 'focus') return { locator, query, action: 'focus' }; |
| 142 | if (action === 'fill') { |
| 143 | const value = actionTokens.slice(1).join(' '); |
| 144 | return { locator, query, action: 'fill', value }; |
| 145 | } |
| 146 | if (action === 'type') { |
| 147 | const value = actionTokens.slice(1).join(' '); |
| 148 | return { locator, query, action: 'type', value }; |
| 149 | } |
| 150 | throw new AppError('INVALID_ARGS', `Unsupported find action: ${actionTokens[0]}`); |
| 151 | } |
| 152 | |
| 153 | export function parseFindSelectorExpression( |
| 154 | locator: FindLocator, |
no test coverage detected