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
- Ejecute UiAutomator API desde Android Studio (v0.8)
- Seleccione el elemento de AutoCompleteTextView en uiautomator
- ¿Cómo obtener el contexto en el caso de prueba uiautomator?
- Android recibe texto del navegador
- ¿Cualquier forma más rápida de volcar la jerarquía de la interfaz de usuario?
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
- Prueba de UiAutomator 2.0 desde la línea de comandos
- Cómo depurar las secuencias de comandos de UIAutomator con Eclipse
- uiautomator - no puede obtener ListView para desplazarse como validar el texto en cada elemento de la lista. sólo falla cuando golpeo el último elemento en la pantalla
- Android UIAutomator haga clic en el dispositivo
- Pruebas de Android: UIAutomator vs Espresso
- Necesidad de identificar xpath para el elemento android usando appium
- Establecer diferentes minSdkVersion para testAndroid que para la aplicación principal
- Android - Fragmento independiente herramienta de prueba de interfaz de usuario
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' }
- MonoGame vs Unity3D
- Facebook (OAuthException – # 100) Se ha intentado acceder al campo nonexisting (first_name) en el tipo de nodo (AnonymousUser)