00ec454/Ask

Android UI/Espresso test recording/playing

devjta opened this issue · 1 comments

Hi!

When I try to record a test with Android Studio and Espresso UI, the clicks on the Permission dialog of ASK will NEVER be recorded and therefore never be replayed, so the test cannot start at all.

Is there a way to bypass it for tests only?

Ok, this is a general espresso UI test problem, as I tried Dexter and the problem was there too.
Workaround is to use UiAutomator package.

This code-snippet while accept 3 runtime-permissions.
UiDevice mDevice = UiDevice.getInstance(getInstrumentation()); if (Build.VERSION.SDK_INT >= 23) { UiObject permission = mDevice.findObject(new UiSelector().resourceId("com.android.packageinstaller:id/permission_allow_button")); if(permission.exists()){ try { permission.click(); Thread.currentThread().sleep(150); permission = mDevice.findObject(new UiSelector().resourceId("com.android.packageinstaller:id/permission_allow_button")); if(permission.exists()) { permission.click(); Thread.currentThread().sleep(150); permission = mDevice.findObject(new UiSelector().resourceId("com.android.packageinstaller:id/permission_allow_button")); if(permission.exists()){ permission.click(); } Thread.currentThread().sleep(150); } } catch (Exception e) { e.printStackTrace(); } } }

Add gradle dependencies:
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'