2019独角兽企业重金招聘Python工程师标准>>>
摘抄地址:https://android.googlesource.com/platform/frameworks/testing/+/android-support-test/espresso/core/src/main/java/android/support/test/espresso/action/ViewActions.java
因为需要链接vpn才能看到。为了方便。直接down下来了
具体的文件地址:
android / platform / frameworks / testing / android-support-test / . / espresso / core / src / main / java / android /support / test / espresso / action / ViewActions.java
/** Copyright (C) 2014 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package android.support.test.espresso.action;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.hamcrest.Matchers.any;
import static org.hamcrest.Matchers.is;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewAssertion;
import android.net.Uri;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.View;
import org.hamcrest.Matcher;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.annotation.Nonnull;
/*** A collection of common {@link ViewActions}.*/
public final class ViewActions {private ViewActions() {}/*** The distance of a swipe's start position from the view's edge, in terms of the view's length.* We do not start the swipe exactly on the view's edge, but somewhat more inward, since swiping* from the exact edge may behave in an unexpected way (e.g. may open a navigation drawer).*/private static final float EDGE_FUZZ_FACTOR = 0.083f;/*** A set of {@code ViewAssertion}s to be executed before the ViewActions in this class.*/private static Set
*
* View constraints:* *
*/public static ViewAction clearText() {return actionWithAssertions(new ReplaceTextAction(""));}/*** Returns an action that clicks the view.
*
* View constraints:* *
*/public static ViewAction click() {return actionWithAssertions(new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER));}/*** Returns an action that performs a single click on the view.** If the click takes longer than the 'long press' duration (which is possible) the provided* rollback action is invoked on the view and a click is attempted again.** This is only necessary if the view being clicked on has some different behaviour for long press* versus a normal tap.** For example - if a long press on a particular view element opens a popup menu -* ViewActions.pressBack() may be an acceptable rollback action.**
* View constraints:* *
*/public static ViewAction click(ViewAction rollbackAction) {checkNotNull(rollbackAction);return actionWithAssertions(new GeneralClickAction(Tap.SINGLE, GeneralLocation.CENTER, Press.FINGER, rollbackAction));}/*** Returns an action that performs a swipe right-to-left across the vertical center of the* view. The swipe doesn't start at the very edge of the view, but is a bit offset.
*
* View constraints:* *
*/public static ViewAction swipeLeft() {return actionWithAssertions(new GeneralSwipeAction(Swipe.FAST,GeneralLocation.translate(GeneralLocation.CENTER_RIGHT, -EDGE_FUZZ_FACTOR, 0),GeneralLocation.CENTER_LEFT, Press.FINGER));}/*** Returns an action that performs a swipe left-to-right across the vertical center of the* view. The swipe doesn't start at the very edge of the view, but is a bit offset.
*
* View constraints:* *
*/public static ViewAction swipeRight() {return actionWithAssertions(new GeneralSwipeAction(Swipe.FAST,GeneralLocation.translate(GeneralLocation.CENTER_LEFT, EDGE_FUZZ_FACTOR, 0),GeneralLocation.CENTER_RIGHT, Press.FINGER));}/*** Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.* The swipe doesn't start at the very edge of the view, but has a bit of offset.
*
* View constraints:* *
*/public static ViewAction swipeDown() {return actionWithAssertions(new GeneralSwipeAction(Swipe.FAST,GeneralLocation.translate(GeneralLocation.TOP_CENTER, 0, EDGE_FUZZ_FACTOR),GeneralLocation.BOTTOM_CENTER, Press.FINGER));}/*** Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.* The swipe doesn't start at the very edge of the view, but has a bit of offset.
*
* View constraints:* *
*/public static ViewAction swipeUp() {return actionWithAssertions(new GeneralSwipeAction(Swipe.FAST,GeneralLocation.translate(GeneralLocation.BOTTOM_CENTER, 0, -EDGE_FUZZ_FACTOR),GeneralLocation.TOP_CENTER, Press.FINGER));}/*** Returns an action that closes soft keyboard. If the keyboard is already closed, it is a no-op.*/public static ViewAction closeSoftKeyboard() {return actionWithAssertions(new CloseKeyboardAction());}/*** Returns an action that presses the current action button (next, done, search, etc) on the IME* (Input Method Editor). The selected view will have its onEditorAction method called.*/public static ViewAction pressImeActionButton() {return actionWithAssertions(new EditorAction());}/*** Returns an action that clicks the back button.*/public static ViewAction pressBack() {return pressKey(KeyEvent.KEYCODE_BACK);}/*** Returns an action that presses the hardware menu key.*/public static ViewAction pressMenuKey() {return pressKey(KeyEvent.KEYCODE_MENU);}/*** Returns an action that presses the key specified by the keyCode (eg. Keyevent.KEYCODE_BACK).*/public static ViewAction pressKey(int keyCode) {return actionWithAssertions(new KeyEventAction(new EspressoKey.Builder().withKeyCode(keyCode).build()));}/*** Returns an action that presses the specified key with the specified modifiers.*/public static ViewAction pressKey(EspressoKey key) {return actionWithAssertions(new KeyEventAction(key));}/*** Returns an action that double clicks the view.
*
* View preconditions:* *
*/public static ViewAction doubleClick() {return actionWithAssertions(new GeneralClickAction(Tap.DOUBLE, GeneralLocation.CENTER, Press.FINGER));}/*** Returns an action that long clicks the view.
**
* View preconditions:* *
*/public static ViewAction longClick() {return actionWithAssertions(new GeneralClickAction(Tap.LONG, GeneralLocation.CENTER, Press.FINGER));}/*** Returns an action that scrolls to the view.
*
* View preconditions:* *
*/public static ViewAction scrollTo() {return actionWithAssertions(new ScrollToAction());}/*** Returns an action that types the provided string into the view.* Appending a \n to the end of the string translates to a ENTER key event. Note: this method* does not change cursor position in the focused view - text is inserted at the location where* the cursor is currently pointed.
*
* View preconditions:* *
*/public static ViewAction typeTextIntoFocusedView(String stringToBeTyped) {return actionWithAssertions(new TypeTextAction(stringToBeTyped, false /* tapToFocus */));}/*** Returns an action that selects the view (by clicking on it) and types the provided string into* the view. Appending a \n to the end of the string translates to a ENTER key event. Note: this* method performs a tap on the view before typing to force the view into focus, if the view* already contains text this tap may place the cursor at an arbitrary position within the text.*
*
* View preconditions:* *
*/public static ViewAction typeText(String stringToBeTyped) {return actionWithAssertions(new TypeTextAction(stringToBeTyped));}/*** Returns an action that updates the text attribute of a view.*
*
* View preconditions:* *
*/public static ViewAction replaceText(@Nonnull String stringToBeSet) {return actionWithAssertions(new ReplaceTextAction(stringToBeSet));}/*** Same as {@code openLinkWithText(Matcher
*
* View preconditions:* *
*/public static ViewAction openLink(Matcher
}