@@ -41,16 +41,20 @@ const synthesisGestureUnsupportedHint = (device: DeviceInfo): string | undefined
4141const LINUX_DEVICE : KindMatrix = { device : true } ;
4242const LINUX_NONE : KindMatrix = { } ;
4343const WEB_DEVICE : KindMatrix = { device : true } ;
44+ const WEB_RUNTIME_COMMANDS = [ 'open' , 'close' ] as const ;
45+ const WEB_QUERY_COMMANDS = [ 'find' , 'get' , 'is' , 'screenshot' , 'snapshot' , 'wait' ] as const ;
46+ const WEB_INTERACTION_COMMANDS = [ 'click' , 'fill' , 'focus' , 'press' , 'scroll' , 'type' ] as const ;
47+ const WEB_SUPPORTED_COMMANDS = new Set < string > ( [
48+ ...WEB_RUNTIME_COMMANDS ,
49+ ...WEB_QUERY_COMMANDS ,
50+ ...WEB_INTERACTION_COMMANDS ,
51+ ] ) ;
4452const ALL_DEVICE_COMMAND_CAPABILITY = {
4553 apple : { simulator : true , device : true } ,
4654 android : { emulator : true , device : true , unknown : true } ,
4755 linux : LINUX_DEVICE ,
4856} as const satisfies CommandCapability ;
49- const WEB_COMMAND_CAPABILITY = {
50- ...ALL_DEVICE_COMMAND_CAPABILITY ,
51- web : WEB_DEVICE ,
52- } as const satisfies CommandCapability ;
53- const APP_RUNTIME_CAPABILITY = WEB_COMMAND_CAPABILITY ;
57+ const APP_RUNTIME_CAPABILITY = ALL_DEVICE_COMMAND_CAPABILITY ;
5458const APP_INVENTORY_CAPABILITY = {
5559 apple : { simulator : true , device : true } ,
5660 android : { emulator : true , device : true , unknown : true } ,
@@ -63,7 +67,7 @@ const APP_INSTALL_CAPABILITY = {
6367 supports : isNotMacOs ,
6468} as const satisfies CommandCapability ;
6569
66- const COMMAND_CAPABILITY_MATRIX : Record < string , CommandCapability > = {
70+ const BASE_COMMAND_CAPABILITY_MATRIX : Record < string , CommandCapability > = {
6771 // Apple simulator-only.
6872 alert : {
6973 // macOS desktop targets report kind=device, so this stays enabled here and the
@@ -130,7 +134,6 @@ const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
130134 apple : { simulator : true , device : true } ,
131135 android : { emulator : true , device : true , unknown : true } ,
132136 linux : LINUX_DEVICE ,
133- web : WEB_DEVICE ,
134137 } ,
135138 clipboard : {
136139 apple : { simulator : true , device : true } ,
@@ -154,20 +157,19 @@ const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
154157 apple : { simulator : true , device : true } ,
155158 android : { emulator : true , device : true , unknown : true } ,
156159 linux : LINUX_DEVICE ,
157- web : WEB_DEVICE ,
158160 } ,
159161 fling : {
160162 apple : { simulator : true , device : true } ,
161163 android : { emulator : true , device : true , unknown : true } ,
162164 linux : LINUX_NONE ,
163165 } ,
164- snapshot : WEB_COMMAND_CAPABILITY ,
166+ snapshot : ALL_DEVICE_COMMAND_CAPABILITY ,
165167 diff : ALL_DEVICE_COMMAND_CAPABILITY ,
166- screenshot : WEB_COMMAND_CAPABILITY ,
167- wait : WEB_COMMAND_CAPABILITY ,
168- get : WEB_COMMAND_CAPABILITY ,
169- find : WEB_COMMAND_CAPABILITY ,
170- is : WEB_COMMAND_CAPABILITY ,
168+ screenshot : ALL_DEVICE_COMMAND_CAPABILITY ,
169+ wait : ALL_DEVICE_COMMAND_CAPABILITY ,
170+ get : ALL_DEVICE_COMMAND_CAPABILITY ,
171+ find : ALL_DEVICE_COMMAND_CAPABILITY ,
172+ is : ALL_DEVICE_COMMAND_CAPABILITY ,
171173 focus : {
172174 apple : { simulator : true , device : true } ,
173175 android : { emulator : true , device : true , unknown : true } ,
@@ -208,7 +210,6 @@ const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
208210 apple : { simulator : true , device : true } ,
209211 android : { emulator : true , device : true , unknown : true } ,
210212 linux : LINUX_DEVICE ,
211- web : WEB_DEVICE ,
212213 } ,
213214 push : {
214215 apple : { simulator : true } ,
@@ -237,7 +238,6 @@ const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
237238 apple : { simulator : true , device : true } ,
238239 android : { emulator : true , device : true , unknown : true } ,
239240 linux : LINUX_DEVICE ,
240- web : WEB_DEVICE ,
241241 } ,
242242 swipe : {
243243 apple : { simulator : true , device : true } ,
@@ -256,9 +256,28 @@ const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
256256 android : { emulator : true , device : true , unknown : true } ,
257257 linux : LINUX_NONE ,
258258 } ,
259- type : WEB_COMMAND_CAPABILITY ,
259+ type : ALL_DEVICE_COMMAND_CAPABILITY ,
260260} ;
261261
262+ const COMMAND_CAPABILITY_MATRIX = addWebCommandCapabilities ( BASE_COMMAND_CAPABILITY_MATRIX ) ;
263+
264+ function addWebCommandCapabilities (
265+ matrix : Record < string , CommandCapability > ,
266+ ) : Record < string , CommandCapability > {
267+ const result : Record < string , CommandCapability > = { } ;
268+ for ( const [ command , capability ] of Object . entries ( matrix ) ) {
269+ result [ command ] = WEB_SUPPORTED_COMMANDS . has ( command )
270+ ? { ...capability , web : WEB_DEVICE }
271+ : capability ;
272+ }
273+ for ( const command of WEB_SUPPORTED_COMMANDS ) {
274+ if ( ! ( command in matrix ) ) {
275+ throw new Error ( `Web command "${ command } " missing from capability matrix` ) ;
276+ }
277+ }
278+ return result ;
279+ }
280+
262281export function isCommandSupportedOnDevice ( command : string , device : DeviceInfo ) : boolean {
263282 const capability = COMMAND_CAPABILITY_MATRIX [ command ] ;
264283 if ( ! capability ) return true ;
0 commit comments