Repository navigation
Expand file tree
/
Copy pathjava.json
More file actions
817 lines (817 loc) · 26.8 KB
/
Copy pathjava.json
File metadata and controls
817 lines (817 loc) · 26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
{
"tools": {
"app_accessibility": [
{
"code": "Map<String, String> settings = device.accessibility();\nSystem.out.println(settings.get(\"bold_text\"));"
},
{
"code": "String now = device.setAccessibility(\"bold_text\", \"on\"); // \"on\", read back"
}
],
"app_alert": [
{
"code": "String says = device.alert(); // \"\" when no dialog is up\nif (!says.isEmpty()) System.out.println(says);"
},
{
"code": "device.answerAlert(true);"
},
{
"code": "String pressed = device.pressAlertButton(\"Don't Save\");\nSystem.out.println(\"pressed \" + pressed);"
}
],
"app_appearance": [
{
"code": "String mode = device.appearance(\"dark\"); // \"dark\", read back"
}
],
"app_audio": [
{
"code": "device.audioStart(\"dev.mobium.mobiumapp\");"
},
{
"code": "Map<String, Object> heard = device.audioExpect(\"heard.wav\", List.of(Map.of(\"hz\", 440)), null);\nSystem.out.println(heard.get(\"timeline\"));"
}
],
"app_background": [
{
"code": "device.background(5); // back in front, resumed, when this returns"
}
],
"app_batch": [
{
"code": "List<Map<String, Object>> results = device.batch(List.of(\n Mobium.step(\"app_tap\", Map.of(\"target\", \"text=Network & internet\")),\n Mobium.step(\"app_wait_for\", Map.of(\"target\", \"text=Internet\"))));"
}
],
"app_battery": [
{
"code": "Map<String, Object> battery = device.battery();\nSystem.out.println(battery.get(\"level\") + \"% \" + battery.get(\"state\"));"
}
],
"app_call": [
{
"code": "device.incomingCall(\"ring\", \"5551234\");"
},
{
"code": "device.incomingCall(\"hang\");"
}
],
"app_set": [
{
"code": "device.set(\"testid=termsCheck\", true); // does nothing if it is already ticked"
},
{
"code": "device.unset(\"@e4\");"
}
],
"app_clear_data": [
{
"code": "Map<String, Object> result = device.clearData(\"com.example.shop\");\nSystem.out.println(result.get(\"emptied\"));"
}
],
"app_clipboard": [
{
"code": "device.setClipboard(\"hello there\");"
},
{
"code": "String held = device.clipboard();"
}
],
"app_context": [
{
"code": "device.context(\"WEBVIEW_com.example.shop\");"
},
{
"code": "device.context(\"NATIVE_APP\");"
}
],
"app_contexts": [
{
"code": "List<String> contexts = device.contexts(); // e.g. [NATIVE_APP, WEBVIEW_com.example.shop]"
}
],
"app_cookies": [
{
"code": "for (Map<String, Object> cookie : device.cookies()) {\n System.out.println(cookie.get(\"name\") + \"=\" + cookie.get(\"value\"));\n}"
},
{
"code": "device.clearCookies(\"session\");"
}
],
"app_crashes": [
{
"code": "List<Map<String, Object>> crashes = device.crashes(\"com.example.shop\", 0); // 0: the default limit\nfor (var c : crashes) System.out.println(c.get(\"time\") + \" \" + c.get(\"summary\"));"
}
],
"app_current": [
{
"code": "String app = device.current(); // e.g. \"com.android.settings\""
}
],
"app_devices": [
{
"code": "for (DeviceInfo d : device.devices()) {\n System.out.println(d.id() + \" \" + d.platform() + \" \" + d.state());\n}"
}
],
"app_dialogs": [
{
"code": "device.addDialogRule(\"Save password\", \"Not now\");"
},
{
"code": "device.clearDialogRules();"
}
],
"app_doctor": [
{
"code": "System.out.println(device.doctor());"
}
],
"app_download": [
{
"code": "Map<String, Object> saved = device.download(\"mobium-report.txt\", \"report.txt\");\nSystem.out.println(saved.get(\"path\"));\n\n// Or the file itself, as bytes\nbyte[] report = device.download(\"mobium-report.txt\");"
},
{
"code": "for (Map<String, Object> f : device.downloads()) {\n System.out.println(f.get(\"name\") + \" \" + f.get(\"bytes\"));\n}"
},
{
"code": "Map<String, Object> got = device.pullPath(\"/sdcard/seed\", \"seed-copy\");\nSystem.out.println(got.get(\"files\") + \" \" + got.get(\"path\"));"
}
],
"app_drag": [
{
"code": "device.drag(\"@e3\", \"@e7\");"
}
],
"app_eval": [
{
"code": "String title = device.eval(\"document.title\");"
}
],
"app_fill": [
{
"code": "device.fill(\"testid=search\", \"coffee\");"
},
{
"code": "device.fill(\"label=Volume\", \"0.3\"); // a slider: its position, from 0 to 1"
}
],
"app_find": [
{
"code": "List<Element> buttons = device.find(\"role=button\");\nfor (Element b : buttons) System.out.println(b.ref() + \" \" + b.label());"
}
],
"app_grant": [
{
"code": "device.grant(\"com.example.shop\", \"camera\", \"location\");"
}
],
"app_install": [
{
"code": "String installed = device.install(Path.of(\"./build/app-debug.apk\")); // the absolute path"
}
],
"app_keyboard": [
{
"code": "device.keyboard(\"coffee\", \"enter\", false);"
},
{
"code": "device.keyboard(null, null, true);"
}
],
"app_launch": [
{
"code": "device.launch(\"com.android.settings\"); // returns once it is in front"
},
{
"code": "device.launchWithGrayBox(\"dev.mobium.mobiumapp\");"
}
],
"app_list_apps": [
{
"code": "for (App app : device.apps()) System.out.println(app.id() + \" \" + app.version());"
}
],
"app_locale": [
{
"code": "List<String> pinned = device.appLocale(\"org.wikipedia\", \"ja-JP\"); // [ja-JP]"
}
],
"app_location": [
{
"code": "device.setLocation(51.5074, -0.1278);"
},
{
"code": "device.clearLocation();"
}
],
"app_lock": [
{
"code": "boolean locked = device.screenLocked(true); // true, read back"
},
{
"code": "device.screenLocked(false);"
}
],
"app_logs": [
{
"code": "Map<String, Object> log = device.deviceLogs(\"com.example.shop\", \"error\", 0); // 0: the default line limit\nSystem.out.println(log.get(\"entries\"));"
}
],
"app_long_press": [
{
"code": "device.longPress(\"@e4\", Duration.ofSeconds(2));"
}
],
"app_map": [
{
"code": "for (Element e : device.map()) {\n System.out.println(e.ref() + \" \" + e.role() + \" \" + e.label());\n}"
},
{
"code": "Map<String, Object> diff = device.mapDiff();\nSystem.out.println(diff.get(\"added\"));\nSystem.out.println(diff.get(\"changed\"));"
}
],
"app_network": [
{
"code": "Map<String, Object> network = device.setOffline(true); // read back once airplane mode holds"
},
{
"code": "device.shapeNetwork(300, 500, 0); // 0: no upload limit"
}
],
"app_notifications": [
{
"code": "device.postNotification(\"Your code is 123456\");"
},
{
"code": "device.shade(true);"
}
],
"app_open_url": [
{
"code": "String app = device.openUrl(\"myapp://cart\"); // the app that ended up in front"
}
],
"app_orientation": [
{
"code": "String now = device.orientation(\"landscape\");"
}
],
"app_press": [
{
"code": "device.press(\"back\");"
},
{
"code": "device.press(\"home\");"
},
{
"code": "device.press(\"dpad-down\");"
},
{
"code": "Map<String, Object> went = device.back(true);\nSystem.out.println(went.get(\"foreground\") + \" \" + went.get(\"confirmed\"));"
}
],
"app_press_drag": [
{
"code": "device.pressDrag(\"@e3\", \"@e5\", \"@e9\");"
}
],
"app_press_tap": [
{
"code": "device.pressTap(\"@e3\", \"@e7\");"
}
],
"app_record": [
{
"code": "device.record(\"start\", null);"
},
{
"code": "Map<String, Object> video = device.record(\"stop\", \"flow.mp4\");\nSystem.out.println(video.get(\"frames\") + \" frames\");"
}
],
"app_reset_permissions": [
{
"code": "device.resetPermissions(\"com.example.shop\");"
}
],
"app_revoke": [
{
"code": "device.revoke(\"com.example.shop\", \"location\");"
}
],
"app_rotate": [
{
"code": "device.rotate(90, \"@e2\");"
}
],
"app_screen": [
{
"code": "Map<String, Object> screen = device.screen();\nSystem.out.println(screen);"
},
{
"code": "device.screen(\"small-phone\", false);\n// ... check the layout ...\ndevice.screen(\"reset\", false);"
}
],
"app_screenshot": [
{
"code": "byte[] png = device.screenshot(Path.of(\"screen.png\"));"
}
],
"app_scroll_to": [
{
"code": "Element row = device.scrollTo(\"text=System\"); // down is the default"
},
{
"code": "Element card = device.scrollTo(\"label=Card 8\", \"right\");"
}
],
"app_session": [
{
"code": "Mobium phone = Mobium.builder().app(\"com.android.settings\").start();\nSystem.out.println(phone.session().device());"
},
{
"code": "device.quit(); // also closes the connection"
}
],
"app_shake": [
{
"code": "device.shake();"
}
],
"app_sms": [
{
"code": "device.sms(\"Your code is 123456\", \"5559876\");"
}
],
"app_source": [
{
"code": "Map<String, Object> source = device.source();\nFiles.writeString(Path.of(\"screen.xml\"), (String) source.get(\"source\"));"
}
],
"app_state": [
{
"code": "Map<String, Object> state = device.appState(\"com.android.settings\");\nboolean running = !\"not_running\".equals(state.get(\"state\"));"
}
],
"app_storage": [
{
"code": "Map<String, Object> state = device.storage(); // cookies, and each origin's storage"
},
{
"code": "device.setStorage(Map.of(\"cookies\", List.of(), \"origins\", List.of()));"
}
],
"app_swipe": [
{
"code": "device.swipe(\"up\");"
}
],
"app_tap": [
{
"code": "device.tap(\"text=Network & internet\");"
},
{
"code": "device.tap(\"@e2\");"
},
{
"code": "device.doubleTap(\"@e2\");"
},
{
"code": "device.launchWithGrayBox(\"dev.mobium.mobiumapp\");\ndevice.tap(\"testid=busyQuiet\");\ndevice.tap(\"testid=busyRowB\"); // waits for the app to say it is idle"
}
],
"app_terminate": [
{
"code": "device.terminate(\"com.android.settings\");"
}
],
"app_text": [
{
"code": "String screen = device.text();"
},
{
"code": "String title = device.text(\"testid=title\");"
}
],
"app_time": [
{
"code": "Map<String, Object> clock = device.deviceTime();\nSystem.out.println(clock.get(\"time\") + \" \" + clock.get(\"zone\"));"
}
],
"app_timezone": [
{
"code": "String zone = device.timezone(\"Asia/Tokyo\"); // read back"
}
],
"app_trace": [
{
"code": "device.traceStart(\"sign in\");"
},
{
"code": "Map<String, Object> saved = device.traceStop(\"sign-in.zip\");\nSystem.out.println(saved.get(\"calls\") + \" \" + saved.get(\"path\"));"
}
],
"app_type": [
{
"code": "device.type(\"testid=email\", \"hello@example.com\");"
}
],
"app_uninstall": [
{
"code": "device.uninstall(\"com.example.shop\");"
}
],
"app_upload": [
{
"code": "Map<String, Object> sent = device.upload(\"invoice-42.txt\");\nSystem.out.println(sent.get(\"where\") + \" \" + sent.get(\"bytes\"));"
},
{
"code": "Map<String, Object> sent = device.pushPath(\"seed\", \"/sdcard/seed\");\nSystem.out.println(sent.get(\"files\") + \" \" + sent.get(\"checked\"));"
}
],
"app_wait_for": [
{
"code": "Element welcome = device.waitFor(\"text=Welcome back\");\ndevice.tap(welcome.ref());"
},
{
"code": "device.waitFor(\"role=progressbar\", WaitFor.hidden()); // returns null: nothing left to point at"
},
{
"code": "device.waitFor(\"testid=termsCheck\", WaitFor.checked().timeout(Duration.ofSeconds(5)));"
},
{
"code": "device.waitFor(\"label=Cart\", WaitFor.selected());"
}
],
"app_zoom": [
{
"code": "device.zoom(\"in\", \"\"); // \"\": about the middle of the screen"
}
],
"app_audit": [
{
"code": "Map<String, Object> found = device.audit();\nSystem.out.println(found.get(\"findings\"));"
}
],
"app_assistant": [
{
"code": "Map<String, Object> got = device.assistant(\"Open Clock\", \"com.google.android.deskclock\", 0);\nif (!Boolean.TRUE.equals(got.get(\"reached\"))) throw new AssertionError(\"in front: \" + got.get(\"front\"));"
},
{
"code": "Map<String, Object> got = device.assistant(\"What is 15 times 3\", null, 20);\nSystem.out.println(got.get(\"answer\"));"
}
],
"app_speech": [
{
"code": "Map<String, Object> said = device.speech(null, false, 0);\nSystem.out.println(said.get(\"steps\"));"
},
{
"code": "Map<String, Object> walk = device.speech(null, true, 20);\nSystem.out.println(walk.get(\"steps\") + \" ended \" + walk.get(\"ended\"));"
},
{
"code": "Map<String, Object> said = device.speech(\"label=Pro\", false, 0);\nSystem.out.println(said.get(\"steps\"));"
},
{
"code": "device.listenStart();\ndevice.tap(\"testid=addLive\");"
},
{
"code": "Map<String, Object> heard = device.listenStop();\nSystem.out.println(heard.get(\"steps\"));"
}
],
"app_hit_test": [
{
"code": "Map<String, Object> hit = device.hitTest(\"testid=submit\");\nSystem.out.println(hit.get(\"reaches\"));"
}
],
"app_biometric": [
{
"code": "device.biometric(\"enroll\");"
},
{
"code": "Map<String, Object> said = device.biometric(\"match\");\nSystem.out.println(said.get(\"outcome\"));"
}
],
"app_boot": [
{
"code": "Map<String, Object> booted = device.boot(\"mobium-test\");\nSystem.out.println(booted.get(\"device\"));"
}
],
"app_shutdown": [
{
"code": "device.shutdown(\"mobium-test\");"
}
],
"app_hook": [
{
"code": "device.launchWithGrayBox(\"dev.mobium.mobiumapp\");\nObject answer = device.hook(\"raiseToast\", \"Toast raised by test script\"); // \"shown\""
}
]
},
"members": {
"builder": [
{
"title": "Configure, then start or connect",
"code": "try (Mobium phone = Mobium.builder().platform(\"android\").app(\"com.example.shop\").start()) {\n phone.tap(\"text=Sign in\");\n}"
}
],
"start": [
{
"title": "Open a session and launch the app fresh",
"code": "try (Mobium phone = Mobium.builder().platform(\"ios\").app(\"com.example.shop\").start()) {\n Session s = phone.session();\n System.out.println(s.device() + \" \" + s.driver());\n} // try-with-resources quits: the session ends here"
}
],
"connect": [
{
"title": "Connect without touching the device",
"code": "try (Mobium phone = Mobium.connect()) {\n System.out.println(phone.current());\n} // close() leaves the session open for whoever started it"
},
{
"title": "Connect with options",
"code": "try (Mobium phone = Mobium.builder().device(\"emulator-5554\").connect()) {\n phone.map();\n}"
}
],
"platform": [
{
"title": "Pick iOS when both are attached",
"code": "try (Mobium phone = Mobium.builder().platform(\"ios\").start()) {\n phone.launch(\"com.apple.Preferences\");\n}"
}
],
"app": [
{
"title": "Launch an app as the session starts",
"code": "try (Mobium phone = Mobium.builder().app(\"com.android.settings\").start()) {\n phone.waitFor(\"text=Network & internet\");\n}"
}
],
"binary": [
{
"title": "Use a mobium binary that is not on PATH",
"code": "try (Mobium phone = Mobium.builder().binary(\"/opt/mobium/bin/mobium\").connect()) {\n System.out.println(phone.doctor());\n}"
}
],
"device": [
{
"title": "Target one of several devices",
"code": "try (Mobium phone = Mobium.builder().device(\"emulator-5556\").start()) {\n phone.press(\"home\");\n}"
}
],
"driver": [
{
"title": "Use the zero-install Android driver",
"code": "try (Mobium phone = Mobium.builder().driver(\"uiautomator\").connect()) {\n System.out.println(phone.text());\n}"
}
],
"callTimeout": [
{
"title": "Bound every call",
"code": "try (Mobium phone = Mobium.builder().callTimeout(Duration.ofMinutes(2)).connect()) {\n phone.map(); // a call past two minutes ends the connection\n}"
}
],
"session": [
{
"title": "Name a session of your own",
"code": "try (Mobium phone = Mobium.builder().session(\"checkout\").connect()) {\n phone.map();\n}"
},
{
"title": "Read what start() opened",
"code": "try (Mobium phone = Mobium.builder().start()) {\n Session s = phone.session(); // null from connect()\n System.out.println(s.platform() + \" \" + s.device());\n}"
}
],
"quit": [
{
"title": "End the session explicitly",
"code": "Mobium phone = Mobium.builder().app(\"com.example.shop\").start();\ntry {\n phone.tap(\"text=Sign in\");\n} finally {\n phone.quit(); // puts back what the session changed\n}"
}
],
"close": [
{
"title": "Close a connection, leaving the session open",
"code": "Mobium phone = Mobium.connect();\nphone.tap(\"@e2\");\nphone.close(); // safe to call twice"
}
],
"sessions": [
{
"title": "List the sessions open on the daemon",
"code": "for (Map<String, Object> s : device.sessions()) {\n System.out.println(s.get(\"device\") + \" \" + s.get(\"platform\"));\n}"
}
],
"call": [
{
"title": "Call any tool by name",
"code": "Map<String, Object> result = device.call(\"app_tap\", Map.of(\"target\", \"@e2\", \"fingers\", 2));"
}
],
"step": [
{
"title": "Build steps for a batch",
"code": "var steps = List.of(\n Mobium.step(\"app_launch\", Map.of(\"app\", \"com.android.settings\")),\n Mobium.step(\"app_map\", null));\ndevice.batch(steps);"
}
],
"MobiumException": [
{
"title": "Read what failed and what to do",
"code": "try {\n device.tap(\"text=Continue\");\n} catch (MobiumException e) {\n System.err.println(e.tool() + \" \" + e.code() + \": \" + e.remedy());\n if (!e.retryable()) throw e;\n}"
}
],
"details": [
{
"title": "Find the step a batch stopped at",
"code": "try {\n device.batch(List.of(Mobium.step(\"app_tap\", Map.of(\"target\", \"text=Sign in\"))));\n} catch (MobiumException e) {\n System.err.println(\"stopped at step \" + e.details().get(\"step\"));\n}"
}
],
"NoSuchElementException": [
{
"title": "Scroll when a tap finds nothing",
"code": "try {\n device.tap(\"text=Continue\");\n} catch (dev.mobium.NoSuchElementException e) { // not java.util's\n device.scrollTo(\"text=Continue\", \"down\");\n}"
}
],
"TimedOutException": [
{
"title": "Handle a wait that never held",
"code": "try {\n device.waitFor(\"text=Welcome\", WaitFor.visible().timeout(Duration.ofSeconds(3)));\n} catch (TimedOutException e) {\n System.err.println(e.getMessage()); // says what was on screen instead\n}"
}
],
"AmbiguousLocatorException": [
{
"title": "Narrow a locator that matched twice",
"code": "try {\n device.tap(\"text=OK\");\n} catch (AmbiguousLocatorException e) {\n device.tap(device.find(\"text=OK\").get(0).ref());\n}"
}
],
"UnsupportedException": [
{
"title": "Skip what a platform lacks",
"code": "try {\n device.press(\"back\");\n} catch (UnsupportedException e) { // iOS has no back button\n System.err.println(e.remedy());\n}"
}
],
"DeviceNotReadyException": [
{
"title": "Unlock before launching",
"code": "try {\n device.launch(\"com.example.shop\");\n} catch (DeviceNotReadyException e) {\n device.screenLocked(false);\n device.launch(\"com.example.shop\");\n}"
}
],
"NoDeviceException": [
{
"title": "Report that nothing is attached",
"code": "try {\n device.map();\n} catch (NoDeviceException e) {\n System.err.println(\"start an emulator first: \" + e.remedy());\n}"
}
],
"NoSuchAlertException": [
{
"title": "Answer a dialog only if one is up",
"code": "try {\n device.answerAlert(false);\n} catch (NoSuchAlertException e) {\n // nothing was up\n}"
}
],
"NoSuchContextException": [
{
"title": "Switch to a WebView that may not be there",
"code": "try {\n device.context(\"WEBVIEW_com.example.shop\");\n} catch (NoSuchContextException e) {\n System.err.println(device.contexts());\n}"
}
],
"ElementNotReachableException": [
{
"title": "Handle a target that cannot be reached",
"code": "try {\n device.tap(\"text=Delete\");\n} catch (ElementNotReachableException e) {\n System.err.println(e.remedy());\n}"
}
],
"NotConfirmedException": [
{
"title": "Handle a change the device did not confirm",
"code": "try {\n device.timezone(\"Asia/Tokyo\");\n} catch (NotConfirmedException e) {\n System.err.println(e.getMessage());\n}"
}
],
"InvalidArgumentException": [
{
"title": "A null is refused before anything is sent",
"code": "try {\n device.tap(null);\n} catch (InvalidArgumentException e) {\n System.err.println(e.getMessage()); // names the argument\n}"
}
],
"ToolchainMissingException": [
{
"title": "Report a missing toolchain",
"code": "try {\n device.launch(\"com.example.shop\");\n} catch (ToolchainMissingException e) {\n System.err.println(e.remedy());\n}"
}
],
"DeviceServerException": [
{
"title": "Retry once when the device server says so",
"code": "try {\n device.tap(\"@e2\");\n} catch (DeviceServerException e) {\n if (e.retryable()) device.tap(\"@e2\");\n}"
}
],
"InternalException": [
{
"title": "Report an internal failure",
"code": "try {\n device.map();\n} catch (InternalException e) {\n System.err.println(\"mobium bug: \" + e.getMessage());\n}"
}
],
"visible": [
{
"title": "Wait for an element to appear",
"code": "Element e = device.waitFor(\"text=Sign in\", WaitFor.visible());"
}
],
"hidden": [
{
"title": "Wait for a spinner to go",
"code": "device.waitFor(\"role=progressbar\", WaitFor.hidden());"
}
],
"text": [
{
"title": "Wait until an element's text contains a string",
"code": "device.waitFor(\"testid=status\", WaitFor.text(\"Done\"));"
}
],
"exactText": [
{
"title": "Wait for an exact text",
"code": "device.waitFor(\"testid=total\", WaitFor.exactText(\"$12.00\"));"
}
],
"value": [
{
"title": "Wait for a field's value",
"code": "device.waitFor(\"testid=email\", WaitFor.value(\"hello@example.com\"));"
}
],
"enabled": [
{
"title": "Wait for a button to become tappable",
"code": "device.waitFor(\"text=Continue\", WaitFor.enabled());"
}
],
"disabled": [
{
"title": "Wait for a button to be disabled",
"code": "device.waitFor(\"text=Submit\", WaitFor.disabled());"
}
],
"checked": [
{
"title": "Wait for a checkbox to be checked",
"code": "device.waitFor(\"testid=termsCheck\", WaitFor.checked());"
}
],
"unchecked": [
{
"title": "Wait for a switch to be off",
"code": "device.waitFor(\"@e4\", WaitFor.unchecked());"
}
],
"focused": [
{
"title": "Wait for a field to take focus",
"code": "device.waitFor(\"testid=search\", WaitFor.focused());"
}
],
"count": [
{
"title": "Wait for exactly three rows",
"code": "device.waitFor(\"role=cell\", WaitFor.count(3));"
}
],
"not": [
{
"title": "Wait for a text to stop matching",
"code": "device.waitFor(\"testid=status\", WaitFor.text(\"Loading\").not());"
}
],
"timeout": [
{
"title": "Wait longer than ten seconds",
"code": "device.waitFor(\"text=Done\", WaitFor.visible().timeout(Duration.ofSeconds(30)));"
}
],
"centerX": [
{
"title": "Tap the middle of an element's bounds",
"code": "Bounds b = device.find(\"testid=map\").get(0).bounds();\ndevice.tap(b.centerX(), b.centerY());"
}
],
"width": [
{
"title": "Measure an element",
"code": "Bounds b = device.waitFor(\"testid=banner\").bounds();\nSystem.out.println(b.width() + \"x\" + b.height() + \" px\");"
}
],
"Element": [
{
"title": "Read what map hands out",
"code": "Element e = device.find(\"text=Sign in\").get(0);\nSystem.out.println(e.ref() + \" \" + e.role() + \" \" + e.bounds() + \" checked=\" + e.checked());"
}
],
"Location": [
{
"title": "Read where the device believes it is",
"code": "Location here = device.location();\nif (here.mock) System.out.println(here.latitude + \", \" + here.longitude);"
}
],
"answerAlert": [
{
"title": "Fill a prompt's field and accept it, in one call",
"code": "device.answerAlert(true, \"Groceries\");"
}
]
},
"intro": {
"install": "git clone https://github.com/mobiumdev/mobium.git\ncd mobium/clients/java && ./mvnw -q install -DskipTests",
"code": "try (Mobium device = Mobium.builder().platform(\"android\").app(\"com.android.settings\").start()) {\n for (Element el : device.map()) System.out.println(el.ref() + \" \" + el.label());\n}",
"note": "`device` below is a `dev.mobium.Mobium` from `Mobium.builder()...start()` or `Mobium.connect()`."
}
}