Caso de prueba de UIautomator Android

Estoy trabajando con UiAutomator, pero no pude extender mi clase con UIAutomatorTestCase, También había añadido los archivos jar, por ejemplo, los archivos jar UIAutomator y JUnit3 lib. Estoy recibiendo error en esta clase Y también quiero saber cómo construir los testcases para esa aplicación más ¿Cómo puedo ejecutar los casos de prueba de mi aplicación de forma programática? Si no, entonces cómo puedo ejecutar estos casos de prueba.

package com.example.test; import junit.framework.TestCase; public class UiAutomatorTestCase extends TestCase { private static final String DISABLE_IME = "disable_ime"; private static final String DUMMY_IME_PACKAGE = "com.android.testing.dummyime"; private UiDevice mUiDevice; private Bundle mParams; private IAutomationSupport mAutomationSupport; private boolean mShouldDisableIme = false; @Override protected void setUp() throws Exception { super.setUp(); mShouldDisableIme = "true".equals(mParams.getString(DISABLE_IME)); if (mShouldDisableIme) { setDummyIme(); } } @Override protected void tearDown() throws Exception { if (mShouldDisableIme) { restoreActiveIme(); } super.tearDown(); } /** * Get current instance of {@link UiDevice}. Works similar to calling the static {@link UiDevice#getInstance()} from anywhere in the test classes. */ public UiDevice getUiDevice() { return mUiDevice; } /** * Get command line parameters. On the command line when passing <code>-e key value</code> pairs, the {@link Bundle} will have the key value pairs conveniently available to the * tests. */ public Bundle getParams() { return mParams; } /** * Provides support for running tests to report interim status * * @return */ public IAutomationSupport getAutomationSupport() { return mAutomationSupport; } /** * package private * * @param uiDevice */ void setUiDevice(UiDevice uiDevice) { mUiDevice = uiDevice; } /** * package private * * @param params */ void setParams(Bundle params) { mParams = params; } void setAutomationSupport(IAutomationSupport automationSupport) { mAutomationSupport = automationSupport; } /** * Calls {@link SystemClock#sleep(long)} to sleep * * @param ms * is in milliseconds. */ public void sleep(long ms) { SystemClock.sleep(ms); } protected void setDummyIme() throws RemoteException { IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager.getService(Context.INPUT_METHOD_SERVICE)); List<InputMethodInfo> infos = im.getInputMethodList(); String id = null; for (InputMethodInfo info : infos) { if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) { id = info.getId(); } } if (id == null) { throw new RuntimeException(String.format("Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE)); } im.setInputMethod(null, id); } protected void restoreActiveIme() throws RemoteException { // TODO: figure out a way to restore active IME // Currently retrieving active IME requires querying secure settings provider, which is hard // to do without a Context; so the caveat here is that to make the post test device usable, // the active IME needs to be manually switched. } } 

La siguiente clase es probar la calculadora. Pero no sé cómo usarlo .. Aquí está el enlace

 package com.example.test; import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiScrollable; import com.android.uiautomator.core.UiSelector; import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class DemoCalTest extends UiAutomatorTestCase { public void testingCalculator() throws UiObjectNotFoundException { // First we testing the press of the HOME button. getUiDevice().pressHome(); // using the uiautomatorviewer tool we found that the button for the "applications" has //the value “Apps” (screen9) // so we use this property to create a UiSelector to find the button. UiObject Applications = new UiObject(new UiSelector().description("Apps")); // testing the click to bring up the All Apps screen. Applications.clickAndWaitForNewWindow(); // In the All Apps screen, the "Calculator" application is located in // the Apps tab. So, we create a UiSelector to find a tab with the text // label “Apps”. UiObject apps = new UiObject(new UiSelector().text("Apps")); // and then testing the click to this tab in order to enter the Apps tab. apps.click(); // All the applications are in a scrollable list // so first we need to get a reference to that list UiScrollable ListOfapplications = new UiScrollable(new UiSelector().scrollable(true)); // and then trying to find the application // with the name Calculator UiObject Calculator = ListOfapplications.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Calculator"); Calculator.clickAndWaitForNewWindow(); // now the Calculator app is open // so we can test the press of button "7" using the ID "com.android.calculator2:id/digit7" //we found by using uiautomatorviewer UiObject seven = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/digit7")); seven.click(); // now we test the press of button "+" UiObject plus = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/plus")); plus.click(); // and then the press of button "1" UiObject one = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/digit1")); one.click(); // we test the press of button "=" UiObject result = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/equal")); result.click(); //and finally we test the press of "Back" button getUiDevice().pressBack(); } } 

Yo googled mucho pero podría encontrar cualquier explicación sobre él. Puede alguien ayudarme. Soy nuevo para ello gracias

Así es como debería extender su clase:

 public class <yourClassName> extends UiAutomatorTestCase { 

También necesitamos importar uiautomator.jar que normalmente reside en ~/sdk/platforms/android-xx/

Puede iniciar desde Link1 y Link2

Puesto que Gradle fue introducido como una nueva herramienta de la estructura, usted no tiene que incluir ningunos tarros. Solo agrega

 androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' 

Como una dependencia del archivo build.gradle .

Por ejemplo:

 dependencies { androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') { exclude module: 'support-annotations' } androidTestCompile 'com.android.support:support-annotations:24.2.1' androidTestCompile 'com.android.support.test:rules:0.5' androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' } 
  • UIAutomator en Android más bajo que 4.3
  • Cómo utilizar el espresso para presionar un botón AlertDialog
  • Ejecutar pruebas de automatización de la interfaz de usuario con gradle sin desinstalar
  • Construir UiAutomator 2.0 desde la línea de comandos
  • Cómo rellenar la contraseña EditText con Android uiautomator?
  • Java.lang.SecurityException: Permiso Denial: getIntentSender () cuando se utiliza UiAutomation en una prueba
  • Android: Espresso no espera hasta que se muestre fragmento o actividad para que cada prueba fallara
  • Escribir en la consola de salida de Android UI Automator
  • No se puede resolver el símbolo 'AndroidJUnit4'
  • UiAutomator falla en el dispositivo 4.1.2
  • ¿Cómo puedo obtener el padre de una vista usando uiautomator?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.