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>ViewAction</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 171Summary: 172 173 174 175 176 177 178 179 180 181 182 183 <a href="#pubmethods">Methods</a> 184 185 186 187 188| <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a> 189 190</div><!-- end sum-details-links --> 191</div><!-- end api-info-block --> 192 193<div class="api apilevel-" id="jd-content"> 194 195<!-- ======== START OF CLASS DATA ======== --> 196 197<h1 class="api-title">ViewAction</h1> 198<p> 199<code class="api-signature"> 200 public 201 202 203 204 interface 205 ViewAction 206</code> 207<br> 208 209 210<code class="api-signature"> 211 212 213 214</code> 215 216</p><table class="jd-inheritance-table"> 217 218 219 <tr> 220 221 <td colspan="1" class="jd-inheritance-class-cell">android.support.test.espresso.ViewAction 222 </td> 223 </tr> 224 225 226</table> 227 228 <table class="jd-sumtable jd-sumtable-subclasses"><tr><td colspan="2" style="border:none;margin:0;padding:0;"> 229 230 <a href="#" onclick="return toggleInherited(this, null)" id="subclasses-indirect" class="jd-expando-trigger closed" 231 ><img height="34" id="subclasses-indirect-trigger" 232 src="/assets/images/styles/disclosure_down.png" 233 class="jd-expando-trigger-img" /></a>Known Indirect Subclasses 234 235 <div id="subclasses-indirect"> 236 <div id="subclasses-indirect-list" 237 class="jd-inheritedlinks" 238 239 > 240 241 242 <a href="/reference/android/support/test/espresso/action/AdapterDataLoaderAction.html">AdapterDataLoaderAction</a>, 243 244 <a href="/reference/android/support/test/espresso/web/action/AtomAction.html">AtomAction</a><E>, 245 246 <a href="/reference/android/support/test/espresso/action/CloseKeyboardAction.html">CloseKeyboardAction</a>, 247 248 <a href="/reference/android/support/test/espresso/action/EditorAction.html">EditorAction</a>, 249 250 <a href="/reference/android/support/test/espresso/web/action/EnableJavascriptAction.html">EnableJavascriptAction</a>, 251 252 <a href="/reference/android/support/test/espresso/action/GeneralClickAction.html">GeneralClickAction</a>, 253 254 <a href="/reference/android/support/test/espresso/action/GeneralSwipeAction.html">GeneralSwipeAction</a>, 255 256 <a href="/reference/android/support/test/espresso/action/KeyEventAction.html">KeyEventAction</a>, 257 258 <a href="/reference/android/support/test/espresso/action/OpenLinkAction.html">OpenLinkAction</a>, 259 260 <a href="/reference/android/support/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction.html">RecyclerViewActions.PositionableRecyclerViewAction</a>, 261 262 <a href="/reference/android/support/test/espresso/action/ReplaceTextAction.html">ReplaceTextAction</a>, 263 264 <a href="/reference/android/support/test/espresso/action/ScrollToAction.html">ScrollToAction</a>, 265 266 <a href="/reference/android/support/test/espresso/action/TypeTextAction.html">TypeTextAction</a> 267 268 269 </div> 270 <div id="subclasses-indirect-summary" 271 style="display: none;" 272 > 273 274 <table class="jd-sumtable-expando"> 275 276 <tr class="alt-color api apilevel-" > 277 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/AdapterDataLoaderAction.html">AdapterDataLoaderAction</a></td> 278 <td class="jd-descrcol" width="100%"> 279 Forces an AdapterView to ensure that the data matching a provided data matcher 280 is loaded into the current view hierarchy. 281 282 283 284 </td> 285 </tr> 286 287 288 <tr class=" api apilevel-" > 289 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/web/action/AtomAction.html">AtomAction</a><E></td> 290 <td class="jd-descrcol" width="100%"> 291 A ViewAction which causes the provided Atom to be evaluated within a webview. 292 293 294 295 </td> 296 </tr> 297 298 299 <tr class="alt-color api apilevel-" > 300 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/CloseKeyboardAction.html">CloseKeyboardAction</a></td> 301 <td class="jd-descrcol" width="100%"> 302 Closes soft keyboard. 303 304 305 306 </td> 307 </tr> 308 309 310 <tr class=" api apilevel-" > 311 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/EditorAction.html">EditorAction</a></td> 312 <td class="jd-descrcol" width="100%"> 313 Performs whatever editor (IME) action is available on a view. 314 315 316 317 </td> 318 </tr> 319 320 321 <tr class="alt-color api apilevel-" > 322 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/web/action/EnableJavascriptAction.html">EnableJavascriptAction</a></td> 323 <td class="jd-descrcol" width="100%"> 324 Forcibly enables Javascript on a WebView. 325 326 327 328 </td> 329 </tr> 330 331 332 <tr class=" api apilevel-" > 333 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/GeneralClickAction.html">GeneralClickAction</a></td> 334 <td class="jd-descrcol" width="100%"> 335 Enables clicking on views. 336 337 338 339 </td> 340 </tr> 341 342 343 <tr class="alt-color api apilevel-" > 344 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/GeneralSwipeAction.html">GeneralSwipeAction</a></td> 345 <td class="jd-descrcol" width="100%"> 346 Enables swiping across a view. 347 348 349 350 </td> 351 </tr> 352 353 354 <tr class=" api apilevel-" > 355 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/KeyEventAction.html">KeyEventAction</a></td> 356 <td class="jd-descrcol" width="100%"> 357 Enables pressing KeyEvents on views. 358 359 360 361 </td> 362 </tr> 363 364 365 <tr class="alt-color api apilevel-" > 366 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/OpenLinkAction.html">OpenLinkAction</a></td> 367 <td class="jd-descrcol" width="100%"> 368 Invokes onClick of a link within a TextView (made with Linkify or via another method). 369 370 371 372 </td> 373 </tr> 374 375 376 <tr class=" api apilevel-" > 377 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction.html">RecyclerViewActions.PositionableRecyclerViewAction</a></td> 378 <td class="jd-descrcol" width="100%"> 379 Most RecyclerViewActions are given a matcher to select a particular view / viewholder within 380 the RecyclerView. 381 382 383 384 </td> 385 </tr> 386 387 388 <tr class="alt-color api apilevel-" > 389 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/ReplaceTextAction.html">ReplaceTextAction</a></td> 390 <td class="jd-descrcol" width="100%"> 391 Replaces view text by setting <code><a href="/reference/android/widget/EditText.html">EditText</a></code>s text property to given String. 392 393 394 395 </td> 396 </tr> 397 398 399 <tr class=" api apilevel-" > 400 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/ScrollToAction.html">ScrollToAction</a></td> 401 <td class="jd-descrcol" width="100%"> 402 Enables scrolling to the given view. 403 404 405 406 </td> 407 </tr> 408 409 410 <tr class="alt-color api apilevel-" > 411 <td class="jd-linkcol"><a href="/reference/android/support/test/espresso/action/TypeTextAction.html">TypeTextAction</a></td> 412 <td class="jd-descrcol" width="100%"> 413 Enables typing text on views. 414 415 416 417 </td> 418 </tr> 419 420 421 </table> 422 423 </div> 424 </div> 425 </td></tr></table> 426 427 428 429<br><hr> 430 431 432 <p>Responsible for performing an interaction on the given View element.<br> 433 <p> 434 This is part of the test framework public API - developers are free to write their own ViewAction 435 implementations when necessary. When implementing a new ViewAction, follow these rules: 436 <ul> 437 <li>Inject motion events or key events via the UiController to simulate user interactions. 438 <li>Do not mutate the view directly via setter methods and other state changing methods on the 439 view parameter. 440 <li>Do not throw AssertionErrors. Assertions belong in ViewAssertion classes. 441 <li>View action code will executed on the UI thread, therefore you should not block, perform 442 sleeps, or perform other expensive computations. 443 <li>The test framework will wait for the UI thread to be idle both before and after perform() is 444 called. This means that the action is guaranteed to be synchronized with any other view 445 operations. 446 <li>Downcasting the View object to an expected subtype is allowed, so long as the object 447 expresses the subtype matches the constraints as specified in <code>getConstraints</code>. 448 </ul> 449</p> 450 451 452 453 454 455 456 457<h2 class="api-section">Summary</h2> 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<!-- ========== METHOD SUMMARY =========== --> 486<table id="pubmethods" class="responsive methods"> 487<tr><th colspan="2"><h3>Public methods</h3></th></tr> 488 489 490 491 492 <tr class="api apilevel-" > 493 494 495 <td><code> 496 abstract 497 498 499 500 501 Matcher<View></code> 502 </td> 503 504 <td width="100%"> 505 <code> 506 <a href="/reference/android/support/test/espresso/ViewAction.html#getConstraints()">getConstraints</a>() 507 </code> 508 509 <p>A mechanism for ViewActions to specify what type of views they can operate on. 510 511 512</p> 513 514 </td> 515 </tr> 516 517 518 519 <tr class="api apilevel-" > 520 521 522 <td><code> 523 abstract 524 525 526 527 528 String</code> 529 </td> 530 531 <td width="100%"> 532 <code> 533 <a href="/reference/android/support/test/espresso/ViewAction.html#getDescription()">getDescription</a>() 534 </code> 535 536 <p>Returns a description of the view action. 537 538 539</p> 540 541 </td> 542 </tr> 543 544 545 546 <tr class="api apilevel-" > 547 548 549 <td><code> 550 abstract 551 552 553 554 555 void</code> 556 </td> 557 558 <td width="100%"> 559 <code> 560 <a href="/reference/android/support/test/espresso/ViewAction.html#perform(android.support.test.espresso.UiController, android.view.View)">perform</a>(<a href="/reference/android/support/test/espresso/UiController.html">UiController</a> uiController, View view) 561 </code> 562 563 <p>Performs this action on the given view. 564 565 566</p> 567 568 </td> 569 </tr> 570 571 572 573</table> 574 575 576 577 578 579 580 581 582<!-- XML Attributes --> 583 584 585<!-- Enum Values --> 586 587 588<!-- Constants --> 589 590 591<!-- Fields --> 592 593 594<!-- Public ctors --> 595 596 597 598<!-- ========= CONSTRUCTOR DETAIL ======== --> 599<!-- Protected ctors --> 600 601 602 603<!-- ========= METHOD DETAIL ======== --> 604<!-- Public methdos --> 605 606<h2 class="api-section">Public methods</h2> 607 608 609 610<A NAME="getConstraints()"></A> 611 612<div class="api apilevel-"> 613 <h3 class="api-name">getConstraints</h3> 614 <div class="api-level"> 615 <div></div> 616 617 618 619 </div> 620<pre class="api-signature no-pretty-print"> 621Matcher<View> getConstraints ()</pre> 622 623 624 625 626 <p>A mechanism for ViewActions to specify what type of views they can operate on. 627 628 A ViewAction can demand that the view passed to perform meets certain constraints. For example 629 it may want to ensure the view is already in the viewable physical screen of the device or is 630 of a certain type.</p> 631 <table class="responsive"> 632 <tr><th colspan=2>Returns</th></tr> 633 <tr> 634 <td><code>Matcher<View></code></td> 635 <td width="100%">a <a href="http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html"> 636 <code>Matcher</code></a> that will be tested prior to calling perform. 637</td> 638 </tr> 639 </table> 640 641</div> 642 643 644<A NAME="getDescription()"></A> 645 646<div class="api apilevel-"> 647 <h3 class="api-name">getDescription</h3> 648 <div class="api-level"> 649 <div></div> 650 651 652 653 </div> 654<pre class="api-signature no-pretty-print"> 655String getDescription ()</pre> 656 657 658 659 660 <p>Returns a description of the view action. The description should not be overly long and should 661 fit nicely in a sentence like: "performing %description% action on view with id ..." 662</p> 663 <table class="responsive"> 664 <tr><th colspan=2>Returns</th></tr> 665 <tr> 666 <td><code>String</code></td> 667 <td width="100%"><!-- no returns description in source --></td> 668 </tr> 669 </table> 670 671</div> 672 673 674<A NAME="perform(android.support.test.espresso.UiController, android.view.View)"></A> 675 676<div class="api apilevel-"> 677 <h3 class="api-name">perform</h3> 678 <div class="api-level"> 679 <div></div> 680 681 682 683 </div> 684<pre class="api-signature no-pretty-print"> 685void perform (<a href="/reference/android/support/test/espresso/UiController.html">UiController</a> uiController, 686 View view)</pre> 687 688 689 690 691 <p>Performs this action on the given view.</p> 692 <table class="responsive"> 693 <tr><th colspan=2>Parameters</th></tr> 694 <tr> 695 <td><code>uiController</code></td> 696 <td width="100%"> 697 <code>UiController</code>: 698 the controller to use to interact with the UI.</td> 699 </tr> 700 <tr> 701 <td><code>view</code></td> 702 <td width="100%"> 703 <code>View</code>: 704 the view to act upon. never null. 705</td> 706 </tr> 707 </table> 708 709</div> 710 711 712 713 714 715<!-- ========= METHOD DETAIL ======== --> 716 717 718 719<!-- ========= END OF CLASS DATA ========= --> 720 721</div><!-- end jd-content --> 722 723 724 725<div class="data-reference-resources-wrapper"> 726 727 <ul data-reference-resources> 728 729 730 <li><h2>Interfaces</h2> 731 <ul> 732 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/BaseLayerComponent.html">BaseLayerComponent</a></li> 733 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/EspressoException.html">EspressoException</a></li> 734 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/FailureHandler.html">FailureHandler</a></li> 735 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingResource.html">IdlingResource</a></li> 736 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingResource.ResourceCallback.html">IdlingResource.ResourceCallback</a></li> 737 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/UiController.html">UiController</a></li> 738 <li class="selected api apilevel-"><a href="/reference/android/support/test/espresso/ViewAction.html">ViewAction</a></li> 739 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewAssertion.html">ViewAssertion</a></li> 740 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewFinder.html">ViewFinder</a></li> 741 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewInteractionComponent.html">ViewInteractionComponent</a></li> 742 </ul> 743 </li> 744 745 <li><h2>Classes</h2> 746 <ul> 747 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/AmbiguousViewMatcherException.Builder.html">AmbiguousViewMatcherException.Builder</a></li> 748 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/DataInteraction.html">DataInteraction</a></li> 749 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/Espresso.html">Espresso</a></li> 750 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/GraphHolder.html">GraphHolder</a></li> 751 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingPolicies.html">IdlingPolicies</a></li> 752 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingPolicy.html">IdlingPolicy</a></li> 753 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoMatchingViewException.Builder.html">NoMatchingViewException.Builder</a></li> 754 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/PerformException.Builder.html">PerformException.Builder</a></li> 755 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/Root.html">Root</a></li> 756 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/Root.Builder.html">Root.Builder</a></li> 757 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/ViewInteraction.html">ViewInteraction</a></li> 758 </ul> 759 </li> 760 761 762 <li><h2>Exceptions</h2> 763 <ul> 764 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/AmbiguousViewMatcherException.html">AmbiguousViewMatcherException</a></li> 765 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/AppNotIdleException.html">AppNotIdleException</a></li> 766 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/IdlingResourceTimeoutException.html">IdlingResourceTimeoutException</a></li> 767 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/InjectEventSecurityException.html">InjectEventSecurityException</a></li> 768 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoActivityResumedException.html">NoActivityResumedException</a></li> 769 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoMatchingRootException.html">NoMatchingRootException</a></li> 770 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/NoMatchingViewException.html">NoMatchingViewException</a></li> 771 <li class="api apilevel-"><a href="/reference/android/support/test/espresso/PerformException.html">PerformException</a></li> 772 </ul> 773 </li> 774 775 </ul> 776 777</div> 778 779 780 781</body> 782</html> 783