Android Testing: UIAutomator vs Espresso

后端 未结 7 1295
醉酒成梦
醉酒成梦 2020-12-04 15:32

I was seeking for test frameworks for Android UI automation and I stumbled upon UI Automator and Espresso and this is the part I am confused about

7条回答
  •  [愿得一人]
    2020-12-04 15:34

    To get a quick notion how both things work let's give an example. Let's try to find and click a button with title "Start" on Lollipop using UIAutomator and Espresso:

    • UIAutomator: You have to search for uppercase "START" because on Lollipop buttons are rendered uppercase. device.findObject(new UiSelector().text("START")).click();
    • Espresso: You would just use R.string.start and wouldn't need to care how the string is actually rendered by the platform. You don't care if the view has textAllCaps=true or it is ellipsized. onView(withText(R.string.start)).perform(click());

    TL:DR;

    UIAutomator searches views in lower-level style than Espresso - via the Instrumentation mechanism and traversing the AccessibilityNodeInfo tree of the view hierarchy. Espresso on its turn typically traverses the view hierarchy itself.

提交回复
热议问题