Upgrade to Pro — share decks privately, control downloads, hide ads and more …

テスト自動化ツールUI Automator 2.0で変わったこと / Notable Changes in UI Automator 2.0

テスト自動化ツールUI Automator 2.0で変わったこと / Notable Changes in UI Automator 2.0

「Android Bazaar and Conference 2015 Summer (ABC 2015 Summer)」の夏の大LT大会で発表した資料です。

2015年3月に、Androidのテスト自動化ツールUI Automatorのバージョン2.0が公開されました。
UI Automator 2.0は、以前のバージョンより使い勝手が向上した一方で、テストスクリプトの書き方も大きく変わっています。
本セッションでは、そのような以前のバージョンとの違いを、ポイントを絞ってご紹介します。

TOYAMA Sumio

July 20, 2015
Tweet

More Decks by TOYAMA Sumio

Other Decks in Programming

Transcript

  1. ςετࣗಈԽπʔϧ  
    UI  Automator  2.0  
    ͰมΘͬͨ͜ͱ
    2015.7.20  
    @sumio_tym  (TOYAMA  Sumio)
    Android  Bazaar  and  Conference  2015  Summer

    View Slide

  2. ࣗݾ঺հ
    •  ࢯ໊:  ֎ࢁ७ੜ(TOYAMA  Sumio)  
    @sumio_tym  (twitter),  @sumio  (github)  
    •  ॴଐ:  NTTιϑτ΢ΣΞגࣜձࣾ  
    •  ۀ຿಺༰:  
    – ࣾ಺Androidؔ࿈ϓϩδΣΫτٕज़ࢧԉ  
    •  ϓϥΠϕʔτ:  
    – STAR(ςετࣗಈԽݚڀձ)  
    – @IT࿈ࡌ  
    ʮεϚϗ޲͚ແྉγεςϜςετࣗಈԽπʔϧʯ  
    uiautomator/AppiumͷճΛॻ͖·ͨ͠  
    •  http://www.atmarkit.co.jp/ait/kw/smapho_testtool.html  
    2  

    View Slide

  3. •  Android  SDKඪ४ͷUIςετࣗಈԽπʔϧ  
    http://goo.gl/E5DH9y  (developer.android.com)  
    •  apk͕खݩʹແͯ͘΋ૢ࡞Ͱ͖Δ  
    – ΞϓϦʹ·͕ͨͬͨૢ࡞΋OK!  
    – ϓϦΠϯΞϓϦ΋OK!  
    •  uiautomator:  Android  4.1ΑΓ୺຤ʹόϯυϧ  
    •  UI  Automator  2.0  (ݱ࣌఺ͷ࠷৽൛͸2.1.1)  
    – 2015.3  Android  Testing  Support  Libraryͱͯ͠ൃද  
    https://plus.google.com/+AndroidDevelopers/posts/WCWANrPkRxg  
    – Android  4.3Ҏ্ରԠ  
    3  
    UI  Automatorͬͯ?

    View Slide

  4. ͓࿩͢͠Δ͜ͱ
    UI  Automator  2.xͷ৽ػೳɾ  
    uiautomator͔ΒมΘͬͨ఺Λɺ  
    ࣌ؒͷڐ͢ݶΓ঺հ͠·͢!
    4  

    View Slide

  5. ΞδΣϯμ
    •  Android  Studio/GradleରԠ  
    •  ΞʔΩςΫνϟͷมߋ  
    •  APIͷมߋ  
    •  ςΩετೖྗAPIͷଟݴޠରԠ  
    5  

    View Slide

  6. •  Android  Studio/GradleରԠ  
    •  ΞʔΩςΫνϟͷมߋ  
    •  APIͷมߋ  
    •  ςΩετೖྗAPIͷଟݴޠରԠ  
    6  

    View Slide

  7. Android  StudioɾGradleରԠ(1/2)
    7  
    uiautomator UI  Automator  2.0
    Ϗϧυ ant  
    (build.xmlΛఏڙ) gradle
    IDE ओʹEclipse Android  Studio
    ֎෦Jarͷ  
    ར༻
    º
    (build.xmlͷ੍ݶ)
    ˓
    gradleͷdependencies
    ςετ
    ίʔυ
    ର৅ΞϓϦͱ͸
    ಠཱ
    ର৅ΞϓϦͱϖΞ  
    (src/androidTest/ʹอଘ)
    ΃ΞҎ֎ͷΞϓϦ΋ૢ࡞Ͱ͖·͢

    View Slide

  8. Android  StudioɾGradleରԠ(2/2)
    8  
    android {
    ...
    defaultConfig {

    ...

    testInstrumentationRunner \
    "android.support.test.runner.AndroidJUnitRunner"
    }

    }
    dependencies {

    androidTestCompile 'com.android.support.test:runner:0.3'

    androidTestCompile \
    'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'

    }
    buildscript {

    dependencies {

    classpath 'com.android.tools.build:gradle:1.2.3'

    }

    }

    View Slide

  9. •  Android  Studio/GradleରԠ  
    •  ΞʔΩςΫνϟͷมߋ  
    •  APIͷมߋ  
    •  ςΩετೖྗAPIͷଟݴޠରԠ  
    9  

    View Slide

  10. uiautomator UI  Automator  2.0
    am  
    ίϚϯυ
    ˓
    ΞϓϦىಈOK
    º
    1FSNJTTJPOͳ͠

    Context
    ΞΫηε
    º
    ˓
    PackageManagerΛ࢖ͬͯ
    ΞϓϦΛىಈ͢Δ͜ͱ΋Մೳ
    ΞʔΩςΫνϟมߋ
    10  
    •  Instrumentation  Testͱͯ͠ಈ࡞͢ΔΑ͏ʹͳͬͨ  
    // ࣄલʹActivityManager#killBackgroundProcesses()
    // Ͱର৅ΞϓϦΛڧ੍ऴྃ͢ΔͱΑΓ࣮֬ɻ
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager()
    .getLaunchIntentForPackage(ىಈ͍ͨ͠ΞϓϦͷύοέʔδ);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    View Slide

  11. •  Android  Studio/GradleରԠ  
    •  ΞʔΩςΫνϟͷมߋ  
    •  APIͷมߋ  
    •  ςΩετೖྗAPIͷଟݴޠରԠ  
    11  

    View Slide

  12. uiautomator UI  Automator  2.0
    ݕࡧ৚݅Λද͢Ϋϥε UiSelector UiSelector
    UI෦඼ͷݕࡧํ๏
    APIͷมߋ(1/3)
    12  
    •  UiObject:  Ҏલ͔Β͋ΔΫϥε  
    Instrumentation inst;
    inst = InstrumentationRegistry.getInstrumentation();
    UiDevice dev = UiDevice.getInstance(inst);
    // dev.findObject().ΞΫγϣϯ
    dev.findObject(new UiSelector().text("OK")).click();
    // new UiObject().ΞΫγϣϯ
    new UiObject(new UiSelector().text("OK")).click();

    View Slide

  13. uiautomator UI  Automator  2.0
    ݕࡧ৚݅Λද͢Ϋϥε — BySelector, By
    UI෦඼ͷݕࡧํ๏ —
    APIͷมߋ(2/3)
    13  
    •  UiObject2:  ৽͍͠Ϋϥε  
    Instrumentation inst;
    inst = InstrumentationRegistry.getInstrumentation();
    UiDevice dev = UiDevice.getInstance(inst);
    // dev.findObject().ΞΫγϣϯ
    dev.findObject(By.text("OK")).click();

    View Slide

  14. UiObject UiObject2
    ݕࡧλΠϛϯά
    ΞΫγϣϯ click()

    ͳͲ
    ݺͼग़࣌͠
    findObject()

    ݺͼग़࣌͠
    ը໘֎ͷUI෦඼
    εΫϩʔϧΞ΢τͨ͠
    ෦඼΋ݕࡧ0,
    UiScrollable
    ʔ
    ৚݅Λຬͨ͢·Ͱ
    ΢ΣΠτ
    ݶΒΕͨ৚݅ͷΈ
    clickAndWaitForWind
    ow()
    ༷ʑͳ৚݅ΛࢦఆͰ͖Δ
    clickAndWait(৚݅)
    ҆ఆੑ ≤"1*

    ˚
    ςΩετೖྗલʹ
    ϑΥʔΧεҠಈ͕ඞཁ
    º
    ۭཝͷEditText΁ͷςΩ
    ετೖྗෆՄ /1&ൃੜ

    ҆ఆੑ ≥"1*
    ˓ ˓
    APIͷมߋ(3/3)
    14  
    •  UiObject  vs  UiObject2

    View Slide

  15. •  Android  Studio/GradleରԠ  
    •  ΞʔΩςΫνϟͷมߋ  
    •  APIͷมߋ  
    •  ςΩετೖྗAPIͷଟݴޠରԠ  
    15  

    View Slide

  16. ςΩετೖྗAPIͷଟݴޠରԠ
    16  
    uiautomator UI  Automator  2.0
    EditTextͷΫϦΞ  
    (୺຤ϩέʔϧ:  ӳޠ)
    ˓ ˓
    EditTextͷΫϦΞ  
    (୺຤ϩέʔϧ:  ӳޠҎ֎)
    º ˓
    ඇASCIIจࣈೖྗ(㱡  API  19) º º
    ඇASCIIจࣈೖྗ(㱢API  21) º ˓
    UnicodeจࣈΛೖྗͰ͖ΔπʔϧΛެ։͍ͯ͠·͢ɻ͝ར༻͍ͩ͘͞!  
    https://github.com/sumio/uiautomator-­‐unicode-­‐input-­‐helper  

    View Slide

  17. ·ͱΊ
    ৽͍͠UI  Automator͸  
    – Gradle/Android  StudioରԠʹͳΓ·ͨ͠  
    – ΑΓॊೈʹ࢖͑ΔAPI͕௥Ճ͞Ε·ͨ͠  
    – ೔ຊޠ͕ೖྗͰ͖ΔΑ͏ʹͳΓ·ͨ͠
    (LollipopҎ্ͷΈ)  
    – ͨͩ͠ɺLollipopະຬͩͱগ͠ෆ҆ఆ  
     
    LollipopҎ্Ͱ࢖͏ʹ͸͓͢͢Ί!  
    17  

    View Slide

  18. ࢀߟURL
    •  GoogleʹΑΔαϯϓϧίʔυ  
    –  https://github.com/googlesamples/android-­‐testing/tree/master/
    uiautomator/BasicSample  
    •  ެࣜυΩϡϝϯτ  
    –  http://developer.android.com/tools/testing-­‐support-­‐library/index.html  
    –  http://developer.android.com/training/testing/ui-­‐testing/uiautomator-­‐
    testing.html  
    •  APIϦϑΝϨϯε  
    –  http://developer.android.com/reference/android/support/test/package-­‐
    summary.html  
    18  

    View Slide