Android Espresso, Wake up device before test. How to use a custom manifest for test?

前端 未结 8 1280
情书的邮戳
情书的邮戳 2020-12-09 03:52

I\'ve been writing tests with androids new espresso framework and find that it works well. One annoying thing (not particular to espresso) is that I have to make sure my scr

8条回答
  •  时光说笑
    2020-12-09 04:03

    I've created the src/debug/AndroidManifest.xml file as Matt suggested and added to following code to the testCase:

       @Override
        public void setUp() throws Exception {
            super.setUp();
            // Espresso will not launch our activity for us, we must launch it via getActivity().
            Activity activity = getActivity();
            KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
            KeyguardManager.KeyguardLock keyguardLock = km.newKeyguardLock("TAG");
            keyguardLock.disableKeyguard();
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    
        }
    

提交回复
热议问题