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<!DOCTYPE html> 120<html devsite> 121<head> 122 123 124 <meta name="top_category" value="develop" /> 125 126 <meta name="subcategory" value="reference" /> 127 128 129 <meta name="book_path" value="/reference/android/support/test/_book.yaml" /> 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145<title>UiController</title> 146 147 148</head> 149 150<body class="gc-documentation develop reference api apilevel-"> 151<div id="doc-api-level" class="" style="display:none"></div> 152 153 154 155 156<div id="naMessage"></div> 157 158<div id="api-info-block"> 159<div class="api-level"> 160 161 162 163 164</div> 165 166 167 168 169<div class="sum-details-links"> 170 171</div><!-- end sum-details-links --> 172</div><!-- end api-info-block --> 173 174<div class="api apilevel-" id="jd-content"> 175 176<!-- ======== START OF CLASS DATA ======== --> 177 178<h1 class="api-title">UiController</h1> 179<p> 180<code class="api-signature"> 181 public 182 183 184 185 interface 186 UiController 187</code> 188<br> 189 190 191<code class="api-signature"> 192 193 194 195</code> 196 197</p><table class="jd-inheritance-table"> 198 199 200 <tr> 201 202 <td colspan="1" class="jd-inheritance-class-cell">android.support.test.espresso.UiController 203 </td> 204 </tr> 205 206 207</table> 208 209 210 211 212<br><hr> 213 214 215 <p>Provides base-level UI operations (such as injection of <code><a href="/reference/android/view/MotionEvent.html">MotionEvent</a></code>s) that can be used to 216 build user actions such as clicks, scrolls, swipes, etc. This replaces parts of the android 217 Instrumentation class that provides similar functionality. However, it provides a more advanced 218 synchronization mechanism for test actions. The key differentiators are: 219 <ul> 220 <li>test actions are assumed to be called on the main thread 221 <li>after a test action is initiated, execution blocks until all messages in the main message 222 queue have been cleared. 223 </ul> 224</p> 225 226 227 228 229 230 231 232<h2 class="api-section">Summary</h2> 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<!-- ========== METHOD SUMMARY =========== --> 261<table id="pubmethods" class="responsive methods"> 262<tr><th colspan="2"><h3>Public methods</h3></th></tr> 263 264 265 266 267 <tr class="api apilevel-" > 268 269 270 <td><code> 271 abstract 272 273 274 275 276 boolean</code> 277 </td> 278 279 <td width="100%"> 280 <code> 281 <a href="/reference/android/support/test/espresso/UiController.html#injectKeyEvent(android.view.KeyEvent)">injectKeyEvent</a>(KeyEvent event) 282 </code> 283 284 <p>Injects a key event into the application. 285 286 287</p> 288 289 </td> 290 </tr> 291 292 293 294 <tr class="api apilevel-" > 295 296 297 <td><code> 298 abstract 299 300 301 302 303 boolean</code> 304 </td> 305 306 <td width="100%"> 307 <code> 308 <a href="/reference/android/support/test/espresso/UiController.html#injectMotionEvent(android.view.MotionEvent)">injectMotionEvent</a>(MotionEvent event) 309 </code> 310 311 <p>Injects a motion event into the application. 312 313 314</p> 315 316 </td> 317 </tr> 318 319 320 321 <tr class="api apilevel-" > 322 323 324 <td><code> 325 abstract 326 327 328 329 330 boolean</code> 331 </td> 332 333 <td width="100%"> 334 <code> 335 <a href="/reference/android/support/test/espresso/UiController.html#injectString(java.lang.String)">injectString</a>(String str) 336 </code> 337 338 <p>Types a string into the application using series of <code><a href="/reference/android/view/KeyEvent.html">KeyEvent</a></code>s. 339 340 341</p> 342 343 </td> 344 </tr> 345 346 347 348 <tr class="api apilevel-" > 349 350 351 <td><code> 352 abstract 353 354 355 356 357 void</code> 358 </td> 359 360 <td width="100%"> 361 <code> 362 <a href="/reference/android/support/test/espresso/UiController.html#loopMainThreadForAtLeast(long)">loopMainThreadForAtLeast</a>(long millisDelay) 363 </code> 364 365 <p>Loops the main thread for a specified period of time. 366 367 368</p> 369 370 </td> 371 </tr> 372 373 374 375 <tr class="api apilevel-" > 376 377 378 <td><code> 379 abstract 380 381 382 383 384 void</code> 385 </td> 386 387 <td width="100%"> 388 <code> 389 <a href="/reference/android/support/test/espresso/UiController.html#loopMainThreadUntilIdle()">loopMainThreadUntilIdle</a>() 390 </code> 391 392 <p>Loops the main thread until the application goes idle. 393 394 395</p> 396 397 </td> 398 </tr> 399 400 401 402</table> 403 404 405 406 407 408 409 410 411<!-- XML Attributes --> 412 413 414<!-- Enum Values --> 415 416 417<!-- Constants --> 418 419 420<!-- Fields --> 421 422 423<!-- Public ctors --> 424 425 426 427<!-- ========= CONSTRUCTOR DETAIL ======== --> 428<!-- Protected ctors --> 429 430 431 432<!-- ========= METHOD DETAIL ======== --> 433<!-- Public methdos --> 434 435<h2 class="api-section">Public methods</h2> 436 437 438 439<A NAME="injectKeyEvent(android.view.KeyEvent)"></A> 440 441<div class="api apilevel-"> 442 <h3 class="api-name">injectKeyEvent</h3> 443 <div class="api-level"> 444 <div></div> 445 446 447 448 </div> 449<pre class="api-signature no-pretty-print"> 450boolean injectKeyEvent (KeyEvent event)</pre> 451 452 453 454 455 <p>Injects a key event into the application.</p> 456 <table class="responsive"> 457 <tr><th colspan=2>Parameters</th></tr> 458 <tr> 459 <td><code>event</code></td> 460 <td width="100%"> 461 <code>KeyEvent</code>: 462 the (non-null!) event to inject</td> 463 </tr> 464 </table> 465 <table class="responsive"> 466 <tr><th colspan=2>Returns</th></tr> 467 <tr> 468 <td><code>boolean</code></td> 469 <td width="100%">true if the event was injected, false otherwise</td> 470 </tr> 471 </table> 472 <table class="responsive"> 473 <tr><th colspan=2>Throws</th></tr> 474 <tr> 475 <td><code><a href="/reference/android/support/test/espresso/InjectEventSecurityException.html">InjectEventSecurityException</a></code></td> 476 <td width="100%">if the event couldn't be injected because it would 477 interact with another application. 478</td> 479 </tr> 480 </table> 481 482 483</div> 484 485 486<A NAME="injectMotionEvent(android.view.MotionEvent)"></A> 487 488<div class="api apilevel-"> 489 <h3 class="api-name">injectMotionEvent</h3> 490 <div class="api-level"> 491 <div></div> 492 493 494 495 </div> 496<pre class="api-signature no-pretty-print"> 497boolean injectMotionEvent (MotionEvent event)</pre> 498 499 500 501 502 <p>Injects a motion event into the application.</p> 503 <table class="responsive"> 504 <tr><th colspan=2>Parameters</th></tr> 505 <tr> 506 <td><code>event</code></td> 507 <td width="100%"> 508 <code>MotionEvent</code>: 509 the (non-null!) event to inject</td> 510 </tr> 511 </table> 512 <table class="responsive"> 513 <tr><th colspan=2>Returns</th></tr> 514 <tr> 515 <td><code>boolean</code></td> 516 <td width="100%">true if the event was injected, false otherwise</td> 517 </tr> 518 </table> 519 <table class="responsive"> 520 <tr><th colspan=2>Throws</th></tr> 521 <tr> 522 <td><code><a href="/reference/android/support/test/espresso/InjectEventSecurityException.html">InjectEventSecurityException</a></code></td> 523 <td width="100%">if the event couldn't be injected because it would 524 interact with another application. 525</td> 526 </tr> 527 </table> 528 529 530</div> 531 532 533<A NAME="injectString(java.lang.String)"></A> 534 535<div class="api apilevel-"> 536 <h3 class="api-name">injectString</h3> 537 <div class="api-level"> 538 <div></div> 539 540 541 542 </div> 543<pre class="api-signature no-pretty-print"> 544boolean injectString (String str)</pre> 545 546 547 548 549 <p>Types a string into the application using series of <code><a href="/reference/android/view/KeyEvent.html">KeyEvent</a></code>s. It is up to the 550 implementor to decide how to map the string to <code><a href="/reference/android/view/KeyEvent.html">KeyEvent</a></code> objects. if you need specific 551 control over the key events generated use <code><a href="/reference/android/support/test/espresso/UiController.html#injectKeyEvent(android.view.KeyEvent)">injectKeyEvent(KeyEvent)</a></code>.</p> 552 <table class="responsive"> 553 <tr><th colspan=2>Parameters</th></tr> 554 <tr> 555 <td><code>str</code></td> 556 <td width="100%"> 557 <code>String</code>: 558 the (non-null!) string to type</td> 559 </tr> 560 </table> 561 <table class="responsive"> 562 <tr><th colspan=2>Returns</th></tr> 563 <tr> 564 <td><code>boolean</code></td> 565 <td width="100%">true if the string was injected, false otherwise</td> 566 </tr> 567 </table> 568 <table class="responsive"> 569 <tr><th colspan=2>Throws</th></tr> 570 <tr> 571 <td><code><a href="/reference/android/support/test/espresso/InjectEventSecurityException.html">InjectEventSecurityException</a></code></td> 572 <td width="100%">if the events couldn't be injected because it would 573 interact with another application. 574</td> 575 </tr> 576 </table> 577 578 579</div> 580 581 582<A NAME="loopMainThreadForAtLeast(long)"></A> 583 584<div class="api apilevel-"> 585 <h3 class="api-name">loopMainThreadForAtLeast</h3> 586 <div class="api-level"> 587 <div></div> 588 589 590 591 </div> 592<pre class="api-signature no-pretty-print"> 593void loopMainThreadForAtLeast (long millisDelay)</pre> 594 595 596 597 598 <p>Loops the main thread for a specified period of time. 599 600 Control may not return immediately, instead it'll return after the time has passed and the 601 queue is in an idle state again.</p> 602 <table class="responsive"> 603 <tr><th colspan=2>Parameters</th></tr> 604 <tr> 605 <td><code>millisDelay</code></td> 606 <td width="100%"> 607 <code>long</code>: 608 time to spend in looping the main thread 609</td> 610 </tr> 611 </table> 612 613</div> 614 615 616<A NAME="loopMainThreadUntilIdle()"></A> 617 618<div class="api apilevel-"> 619 <h3 class="api-name">loopMainThreadUntilIdle</h3> 620 <div class="api-level"> 621 <div></div> 622 623 624 625 </div> 626<pre class="api-signature no-pretty-print"> 627void loopMainThreadUntilIdle ()</pre> 628 629 630 631 632 <p>Loops the main thread until the application goes idle. 633 634 An empty task is immediately inserted into the task queue to ensure that if we're idle at this 635 moment we'll return instantly. 636</p> 637 638</div> 639 640 641 642 643 644<!-- ========= METHOD DETAIL ======== --> 645 646 647 648<!-- ========= END OF CLASS DATA ========= --> 649 650</div><!-- end jd-content --> 651 652 653 654<div class="data-reference-resources-wrapper"> 655 656 <ul data-reference-resources> 657 658 659 <li><h2>Interfaces</h2> 660 <ul> 661 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/BaseLayerComponent.html">BaseLayerComponent</a></li> 662 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/EspressoException.html">EspressoException</a></li> 663 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/FailureHandler.html">FailureHandler</a></li> 664 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingResource.html">IdlingResource</a></li> 665 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingResource.ResourceCallback.html">IdlingResource.ResourceCallback</a></li> 666 <li class="selected api apilevel-"><a href="/reference/android/support/test/espresso/UiController.html">UiController</a></li> 667 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewAction.html">ViewAction</a></li> 668 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewAssertion.html">ViewAssertion</a></li> 669 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewFinder.html">ViewFinder</a></li> 670 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewInteractionComponent.html">ViewInteractionComponent</a></li> 671 </ul> 672 </li> 673 674 <li><h2>Classes</h2> 675 <ul> 676 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/AmbiguousViewMatcherException.Builder.html">AmbiguousViewMatcherException.Builder</a></li> 677 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/DataInteraction.html">DataInteraction</a></li> 678 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/Espresso.html">Espresso</a></li> 679 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/GraphHolder.html">GraphHolder</a></li> 680 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingPolicies.html">IdlingPolicies</a></li> 681 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingPolicy.html">IdlingPolicy</a></li> 682 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoMatchingViewException.Builder.html">NoMatchingViewException.Builder</a></li> 683 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/PerformException.Builder.html">PerformException.Builder</a></li> 684 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/Root.html">Root</a></li> 685 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/Root.Builder.html">Root.Builder</a></li> 686 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewInteraction.html">ViewInteraction</a></li> 687 </ul> 688 </li> 689 690 691 <li><h2>Exceptions</h2> 692 <ul> 693 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/AmbiguousViewMatcherException.html">AmbiguousViewMatcherException</a></li> 694 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/AppNotIdleException.html">AppNotIdleException</a></li> 695 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingResourceTimeoutException.html">IdlingResourceTimeoutException</a></li> 696 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/InjectEventSecurityException.html">InjectEventSecurityException</a></li> 697 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoActivityResumedException.html">NoActivityResumedException</a></li> 698 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoMatchingRootException.html">NoMatchingRootException</a></li> 699 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoMatchingViewException.html">NoMatchingViewException</a></li> 700 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/PerformException.html">PerformException</a></li> 701 </ul> 702 </li> 703 704 </ul> 705 706</div> 707 708 709 710</body> 711</html> 712