相关疑难解决方法(0)

我无法使ViewActions.closeSoftKeyboard()在Espresso 2.2.2中运行

我正在尝试测试应用程序,我需要隐藏键盘,因为我无法点击按钮.所以,我在build.gradle中添加了Espresso:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
Run Code Online (Sandbox Code Playgroud)

并试图从android.support.test.espresso.action.ViewActions库中使用它:

ViewActions.closeSoftKeyboard();
Run Code Online (Sandbox Code Playgroud)

测试成功运行,但在我的布局中的EditText中键入一些文本后失败.键盘仍在那里,显示出来.

PS我在读完这个答案后意识到这是键盘故障.

testing android unit-testing android-espresso

15
推荐指数
2
解决办法
5318
查看次数

Espresso - 在全屏活动上执行操作失败 - InjectEventSecurityException

我浪费了两天时间尝试在全屏活动上执行点击操作.

重现步骤

  1. 使用全屏活动代码模板在android studio中创建一个新项目
  2. 为活动写一个espresso测试以执行点击

    public class FullscreenActivityTest 
                  extends ActivityInstrumentationTestCase2<FullscreenActivity> {
    public FullscreenActivityTest() {
        super(FullscreenActivity.class);
    }
    
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        getActivity();
    }
    
    public void testClickingOnLayout() {
        onView(withId(R.id.fullscreen_content)).perform(click());
    }
    
    Run Code Online (Sandbox Code Playgroud)

    }

  3. 在模拟器上运行此测试(从姜面包到棒棒糖的任何Android版本).

失败

android.support.test.espresso.PerformException: 
Error performing 'click' on view 'with id: com.example.espressodefect:id/fullscreen_content'
...
Caused by: android.support.test.espresso.PerformException: 
Error performing 'Send down montion event' on view 'unknown'.
...
Caused by: android.support.test.espresso.InjectEventSecurityException: java.lang.SecurityException: 
Injecting to another application requires INJECT_EVENTS permission
Run Code Online (Sandbox Code Playgroud)

满堆栈在这里.

试着

我试过以下没有运气:

  • 模拟器上没有锁定屏幕.(还使用更新的活动WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
  • 所有动画都关闭了
  • 没有屏幕键盘,或任何覆盖在应用程序顶部的任何东西. …

android android-testing android-espresso

13
推荐指数
1
解决办法
3329
查看次数