热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

EspressoViewActions.java

2019独角兽企业重金招聘Python工程师标准摘抄地址:https:android.googlesource.complatformframeworkstes

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

摘抄地址: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> globalAssertions =new CopyOnWriteArraySet>();/*** Adds a {@code ViewAssertion} to be run every time a {@code ViewAction} in this class is* performed. The assertion will be run prior to performing the action.** @param name a name of the assertion to be added* @param viewAssertion a {@code ViewAssertion} to be added* @throws IllegalArgumentException if the name/viewAssertion pair is already contained in the*         global assertions.*/public static void addGlobalAssertion(String name, ViewAssertion viewAssertion) {checkNotNull(name);checkNotNull(viewAssertion);Pair vaPair = new Pair(name, viewAssertion);checkArgument(!globalAssertions.contains(vaPair),"ViewAssertion with name %s is already in the global assertions!", name);globalAssertions.add(vaPair);}/*** Removes the given assertion from the set of assertions to be run before actions are performed.** @param viewAssertion the assertion to remove* @throws IllegalArgumentException if the name/viewAssertion pair is not already contained in the*         global assertions.*/public static void removeGlobalAssertion(ViewAssertion viewAssertion) {boolean removed = false;for (Pair vaPair : globalAssertions) {if (viewAssertion != null && viewAssertion.equals(vaPair.second)) {removed = removed || globalAssertions.remove(vaPair);}}checkArgument(removed, "ViewAssertion was not in global assertions!");}public static void clearGlobalAssertions() {globalAssertions.clear();}/*** Performs all assertions before the {@code ViewAction}s in this class and then performs the* given {@code ViewAction}** @param viewAction the {@code ViewAction} to perform after the assertions*/public static ViewAction actionWithAssertions(final ViewAction viewAction) {if (globalAssertions.isEmpty()) {return viewAction;}return new ViewAction() {@Overridepublic String getDescription() {StringBuilder msg = new StringBuilder("Running view assertions[");for (Pair vaPair : globalAssertions) {msg.append(vaPair.first);msg.append(", ");}msg.append("] and then running: ");msg.append(viewAction.getDescription());return msg.toString();}@Overridepublic Matcher getConstraints() {return viewAction.getConstraints();}@Overridepublic void perform(UiController uic, View view) {for (Pair vaPair : globalAssertions) {Log.i("ViewAssertion", "Asserting " + vaPair.first);vaPair.second.check(view, null);}viewAction.perform(uic, view);}};}/*** Returns an action that clears text on the view.

* View constraints:* 

  • must be displayed on screen* 
      */public static ViewAction clearText() {return actionWithAssertions(new ReplaceTextAction(""));}/*** Returns an action that clicks the view.

      * View constraints:* 
      • must be displayed on screen* 
          */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:* 
          • must be displayed on screen
          • any constraints of the rollbackAction
            • */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:* 
              • must be displayed on screen* 
                  */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:* 
                  • must be displayed on screen* 
                      */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:* 
                      • must be displayed on screen* 
                          */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:* 
                          • must be displayed on screen* 
                              */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:* 
                              • must be displayed on screen* 
                                  */public static ViewAction doubleClick() {return actionWithAssertions(new GeneralClickAction(Tap.DOUBLE, GeneralLocation.CENTER, Press.FINGER));}/*** Returns an action that long clicks the view.
                                  ** 
                                  * View preconditions:* 
                                  • must be displayed on screen* 
                                      */public static ViewAction longClick() {return actionWithAssertions(new GeneralClickAction(Tap.LONG, GeneralLocation.CENTER, Press.FINGER));}/*** Returns an action that scrolls to the view.

                                      * View preconditions:* 
                                      • must be a descendant of ScrollView* 
                                      • must have visibility set to View.VISIBLE* 
                                          */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:* 
                                          • must be displayed on screen* 
                                          • must support input methods* 
                                          • must be already focused* 
                                              */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:* 
                                              • must be displayed on screen* 
                                              • must support input methods* 
                                                  */public static ViewAction typeText(String stringToBeTyped) {return actionWithAssertions(new TypeTextAction(stringToBeTyped));}/*** Returns an action that updates the text attribute of a view.* 

                                                  * View preconditions:* 
                                                  • must be displayed on screen* 
                                                  • must be assignable from EditText* 
                                                      */public static ViewAction replaceText(@Nonnull String stringToBeSet) {return actionWithAssertions(new ReplaceTextAction(stringToBeSet));}/*** Same as {@code openLinkWithText(Matcher linkTextMatcher)}, but uses* {@code is(linkText)} as the linkTextMatcher.*/public static ViewAction openLinkWithText(String linkText) {return openLinkWithText(is(linkText));}/*** Same as {@code openLink(Matcher linkTextMatcher, Matcher uriMatcher)}, but uses* {@code any(Uri.class)} as the uriMatcher.*/public static ViewAction openLinkWithText(Matcher linkTextMatcher) {return openLink(linkTextMatcher, any(Uri.class));}/*** Same as {@code openLinkWithUri(Matcher uriMatcher)}, but uses {@code is(uri)} as the* uriMatcher.*/public static ViewAction openLinkWithUri(String uri) {return openLinkWithUri(is(Uri.parse(uri)));}/*** Same as {@code openLink(Matcher linkTextMatcher, Matcher uriMatcher)}, but uses* {@code any(String.class)} as the linkTextMatcher.*/public static ViewAction openLinkWithUri(Matcher uriMatcher) {return openLink(any(String.class), uriMatcher);}/*** Returns an action that opens a link matching the given link text and uri matchers. The action* is performed by invoking the link's onClick method (as opposed to actually issuing a click on* the screen).* 

                                                      * View preconditions:* 
                                                      • must be displayed on screen* 
                                                      • must be assignable from TextView* 
                                                      • must have links* 
                                                          */public static ViewAction openLink(Matcher linkTextMatcher, Matcher uriMatcher) {checkNotNull(linkTextMatcher);checkNotNull(uriMatcher);return actionWithAssertions(new OpenLinkAction(linkTextMatcher, uriMatcher));}
                                                          }

                                                           


转:https://my.oschina.net/u/2253892/blog/619299



推荐阅读
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了在Win10上安装WinPythonHadoop的详细步骤,包括安装Python环境、安装JDK8、安装pyspark、安装Hadoop和Spark、设置环境变量、下载winutils.exe等。同时提醒注意Hadoop版本与pyspark版本的一致性,并建议重启电脑以确保安装成功。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • Google Play推出全新的应用内评价API,帮助开发者获取更多优质用户反馈。用户每天在Google Play上发表数百万条评论,这有助于开发者了解用户喜好和改进需求。开发者可以选择在适当的时间请求用户撰写评论,以获得全面而有用的反馈。全新应用内评价功能让用户无需返回应用详情页面即可发表评论,提升用户体验。 ... [详细]
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • 本文介绍了一些Java开发项目管理工具及其配置教程,包括团队协同工具worktil,版本管理工具GitLab,自动化构建工具Jenkins,项目管理工具Maven和Maven私服Nexus,以及Mybatis的安装和代码自动生成工具。提供了相关链接供读者参考。 ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • 一句话解决高并发的核心原则
    本文介绍了解决高并发的核心原则,即将用户访问请求尽量往前推,避免访问CDN、静态服务器、动态服务器、数据库和存储,从而实现高性能、高并发、高可扩展的网站架构。同时提到了Google的成功案例,以及适用于千万级别PV站和亿级PV网站的架构层次。 ... [详细]
author-avatar
布丁宝宝-_932
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有