Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best approach to test home screen widget

What is the best approach to test android home screen widget ? Its very difficult to find any example code :/ What frameworks support that tests ?

  1. Espresso
  2. Robotium
  3. other
like image 327
Łukasz Woźniczka Avatar asked Sep 30 '22 22:09

Łukasz Woźniczka


1 Answers

try UIAutomator use android-sdk/tools/uiautomatorviewer to get widget properties

    import android.test.InstrumentationTestCase;
    import android.support.test.uiautomator.UiDevice;
    import android.support.test.uiautomator.By;

    public class CalculatorUiTest extends InstrumentationTestCase {

        private UiDevice mDevice;

        public void setUp() {
            // Initialize UiDevice instance
            mDevice = UiDevice.getInstance(getInstrumentation());

            // Start from the home screen
            mDevice.pressHome();

            UiObject widgetButton = mDevice.findObject(new UiSelector()
            .text("OK"))
            .className("android.widget.Button"));

            widgetButton.clickAndWaitForNewWindow();
        }
}

Android Testing Support Library

like image 105
Dmitry Gr Avatar answered Oct 04 '22 20:10

Dmitry Gr