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

uiautomatorを使うためのひと工夫

TOYAMA Sumio
December 13, 2013

 uiautomatorを使うためのひと工夫

Android Test Casual Talk #1 の発表資料です。
uiautomatorを日本語環境下で快適に使うための工夫について発表しました。
補足を以下の記事に書いていますので、あわせてご覧ください。
http://sumio.hatenablog.com/entry/2013/12/15/115406

TOYAMA Sumio

December 13, 2013
Tweet

More Decks by TOYAMA Sumio

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ •  ࢯ໊:  ֎ࢁ७ੜ(TOYAMA  Sumio)   @sumio_tym  (twitter),  @sumio  (github)

      •  ॴଐ:  NTTιϑτ΢ΣΞגࣜձࣾ   •  ۀ຿಺༰:   – ࣾ಺Android™ؔ࿈ϓϩδΣΫτٕज़ࢧԉ   – Androidؔ࿈ࣾ಺ݚमߨࢣ   •  ϓϥΠϕʔτ:   – Androidͷࣗಈςετʹ͍ͭͯϒϩάॻ͍ͯ·͢   http://sumio.hatenablog.com/   ( )  Android  is  a  trademark  of  Google  Inc. 2  
  2. uiautomatorʹ͍ͭͯ •  ػೳɾUIςετࣗಈԽπʔϧ(Googleۘ੡)   –  http://developer.android.com/tools/testing/ testing_ui.html   •  MonkeyRunnerͱҧ͏ͱ͜Ζ

      –  JellyBean  (API  16)Ҏ্ͷΈରԠ   –  JavaͰॻ͚Δ   –  ઈର࠲ඪࢦఆ͕΄΅ෆཁ   •  MonkeyRunnerͱಉ͡ͱ͜Ζ   –  ΞϓϦʹ·͕ͨͬͨૢ࡞γφϦΦ͕ॻ͚Δ   –  ୈࡾऀ͕࡞ͬͨΞϓϦ΋ૢ࡞Մೳ   JellyBeanͷγΣΞ   50%ಥഁ!   ͦΖͦΖ࢖ͬͯΈ͍ͨ! 4  
  3. ࢒೦ͳ఺①   ೖྗࡁΈจࣈྻ΁ͷ্ॻ͖(͏·͘ಈ͘ྫ)  ࠨ୺Λ௕ԡ͠ "SELECT  ALL"   Λλοϓ ⌫ԡԼ

    setText("Android Test Casual Talk #1"); ӳޠ؀ڥͰ ৽͍͠จࣈྻΛλΠϓ ੒ޭ! 6  
  4. ࠨ୺Λ௕ԡ͠ "SELECT  ALL"   ΛλοϓͰ͖ͳ͍! ⌫ԡԼ "This"͚ͩফ͑Δ มԽͳ͠ ࢒೦ͳ఺①  

    ೖྗࡁΈจࣈྻ΁ͷ্ॻ͖(࢒೦ͳྫ)  setText("Android Test Casual Talk #1"); ೔ຊޠ؀ڥͰ 7   ৽͍͠จࣈྻΛλΠϓ ࢒೦!
  5. •  UiObject.setText(String)   –  Virtual  Keyboard  Device(=QWERTYΩʔϘʔυ)ͷΩʔΠ ϕϯτΛٖࣅతʹൃੜͤ͞Δ͜ͱͰೖྗΛ࣮ݱ   ࢒೦ͳ఺②

      ೔ຊޠΛؚΉจࣈྻͷೖྗ •  (΄΅)ASCIIҎ֎ΛؚΉจࣈྻೖྗ͸ແࢹ͞ΕΔ!   •  ಈ࡞தͷIMEʹӨڹ͞ΕΔ!   iWnn   IME Android   ΩʔϘʔυ setText("aiueo"); http://source.android.com/devices/tech/input/key-­‐character-­‐map-­‐files.html 8  
  6. 11   ͻͱ޻෉①   ೖྗࡁΈจࣈྻ΁ͷ্ॻ͖ λοϓର৅Λมߋ͍ͨ͠!   [SELECT  ALL]ˠ[͢΂ͯબ୒]  

    /* (લུ) */ getInteractionController() .longTapNoSync(rect.left + 20, rect.centerY()); // check if the edit menu is open UiObject selectAll = new UiObject(new UiSelector() .descriptionContains("Select all")); if (selectAll.waitForExists(50)) selectAll.click(); // wait for the selection SystemClock.sleep(250); // delete it getInteractionController().sendKey(KeyEvent.KEYCODE_DEL, 0); •  UiObject.clearTextField()ͷ࣮૷(*)Λݩʹ࡞ͬͯΈΔ   (*)https://android.googlesource.com/platform/frameworks/uiautomator/+/android-­‐4.4.1_r1/src/com/android/ uiautomator/core/UiObject.javaΑΓҰ෦Ҿ༻
  7. 12   ͻͱ޻෉①   ೖྗࡁΈจࣈྻ΁ͷ্ॻ͖ /* (લུ) */ getInteractionController() .longTapNoSync(rect.left

    + 20, rect.centerY()); // check if the edit menu is open UiObject selectAll = new UiObject(new UiSelector() .descriptionContains("Select all")); if (selectAll.waitForExists(50)) selectAll.click(); // wait for the selection SystemClock.sleep(250); // delete it getInteractionController().sendKey(KeyEvent.KEYCODE_DEL, 0); •  getInteractionController()ར༻෦෼   ˠΞΫηεෆՄͳͷͰɺద౰ͳpublicϝιουͰ୅ସ   •  "Select  All"ͷݕࡧ৚݅   ˠ"͢΂ͯબ୒"ʹมߋ   UiObject.longClickTopLeft()Λ࢖͏ UiDevice.pressDelete()Λ࢖͏ "͢΂ͯબ୒"ʹ͢Δ
  8. ͻͱ޻෉②   ೔ຊޠΛؚΉจࣈྻͷೖྗ(1/2) ASCIIจࣈྻΛUnicodeʹ   ม׵͢ΔIMEΛ࡞Γ·ͨ͠   UTF7  IME  for

     UI  Testing setText("&MFMwkzBrMGEwbw-!"); [&MFMwkzBrMGEwbw-­‐!]   Λ[͜Μʹͪ͸!]ʹม׵   Modified  UTF-­‐7   (RFC  3501)   13  
  9. ͻͱ޻෉②   ೔ຊޠΛؚΉจࣈྻͷೖྗ(2/2) •  จࣈྻͷΤϯίʔμࠐΈͰެ։͍ͯ͠·͢   Uiautomator  Unicode  Input  Helper

      https://github.com/sumio/uiautomator-­‐unicode-­‐input-­‐helper   (Apache  License,  Version  2.0)   UTF7  IME  for  UI  Testing UiObject edittext = ....; String encoded = Utf7ImeHelper.e("͜Μʹͪ͸!"); edittext.setText(encoded); Uiautomator  Unicode   Input  Helper Uiautomator  Unicode   Input  Helper 14  
  10. ·ͱΊ •  UiAutomatorΛ࢖ͬͨจࣈೖྗΛɺͻͱ޻෉ͯ͠೔ ຊਓʹ༏ͯ͘͠͠Έ·ͨ͠ɻ   –  ೖྗࡁΈจࣈྻͷ্ॻ͖:  [͢΂ͯબ୒]Λλοϓ   – 

    ೔ຊޠೖྗ:  ASCIIจࣈྻΛUnicodeʹม׵͢ΔIMEΛ༻ҙ   •  ྆ํ૊Έ߹ΘͤΕ͹ҎԼͷΑ͏ʹॻ͚·͢ɻ͓ࢼ ͍ͩ͘͠͞!   UiObject edittext = ....; // ೖྗ͍ͨ͠จࣈྻΛIME͕ղऍͰ͖ΔΑ͏ʹΤϯίʔυ͢Δ String encoded = Utf7ImeHelper.e("͜Μʹͪ͸!"); // edittextͷத਎ΛΫϦΞ͢Δ myClearTextField(edittext); // Τϯίʔυͨ͠จࣈྻΛೖྗ͢Δ edittext.setText(encoded); UiObject.clearTextFiled()   Λॻ͖׵͑ͨ΋ͷ   15