Basic using espresso

การใช้งาน Espresso หรือ Automate testing tools อื่น มีสองข้อหลักๆ คือ

  1. หาของที่ต้องการ
  2. ต้องการทำอะไร

สำหรับในข้อ 1 Espresso ได้เตรียม ViewInteraction และ ViewMatchers ไว้ให้แล้ว โดยจะหาจาก Id ของ Element หรือ Value ต่างที่อยู่ภายใน Element ก็ได้

ตัวอย่าง การค้นหา element ด้วย id

onView(withId(R.id.scoreInput))

ตัวอย่าง การค้นหา Element ด้วย text

onView(withText("Please tell me your score."))

สำหรับในส่วนที่ 2 จะเป็นการกำหนดว่าจะให้ element ทำอะไร เช่น กดปุ่ม, ใส่ข้อความ หรือจะเป้นตรวจสอบเงื่อนไขต่างๆ

ตัวอย่าง การตรวจสอบว่ามีข้อความนี้อยู่ในจอภาพหรือไม่

onView(withText("Please tell me your score.")).check(matches(isDisplayed()));

ตัวอย่าง การพิมพ์ข้อความ

onView(withId(R.id.scoreInput)).perform(typeText("0"));

ตัวอย่าง การกดปุ่ม

onView(withId(R.id.button)).perform(click());

ทำการศึกษาเพิ่มเติมได้ที่ https://developer.android.com/training/testing/espresso/basics.html https://developer.android.com/training/testing/espresso/cheat-sheet.html

results matching ""

    No results matching ""