åçãœãŒã¹
ãã¹ãã¯ãã¢ããªã±ãŒã·ã§ã³éçºäžã®éåžžã«éèŠãªããã»ã¹ã§ãã Androidã®å Žåãå€ãã®ããã€ã¹ã«ã¯ç¹æ§ïŒç»é¢è§£å床ãAndroidããŒãžã§ã³ãªã©ïŒã«å€§ããªéãããããããã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãã¯å€æ°ã®ããã€ã¹ã§å®è¡ããå¿ èŠããããŸãã å€æ°ã®ããã€ã¹ã§ã¢ããªã±ãŒã·ã§ã³ãæåã§ãã¹ãããããã»ã¹ã¯ãæéãããããéå±ã§ããšã©ãŒãçºçãããããªããŸãã ããå¹ççã§ä¿¡é Œæ§ã®é«ãã¢ãããŒãã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®ãã¹ããèªååããããšã§ãã UIAutomatorã䜿çšãããšãå€ãã®Androidããã€ã¹ã§åäœãããã¹ãã¹ã¯ãªãããéçºã§ããŸã
åã粟床ãšåçŸæ§ã§ã
UIAutomator
UIAutomatorã¯Googleã«ãã£ãŠéçºãããAndroid SDKã«å梱ãããŠããŸãã UIAutomatorã¯ãAndroidã¢ããªã±ãŒã·ã§ã³ããã¹ãããããã®Appleã®UIAutomationããŒã«ã«é¡äŒŒããŠããŸãã Android SDKã«ã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®èªåæ©èœãã¹ãããµããŒããã次ã®ããŒã«ãçšæãããŠããŸãã
- UIAutomatorviewer-Androidã¢ããªã±ãŒã·ã§ã³ã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã³ã³ããŒãã³ããèªèããããã®ã°ã©ãã£ã«ã«ããŒã«ã
- UIAutomator-ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãã¹ããäœæããããã®ã¡ãœãããå«ãJava APIã©ã€ãã©ãªã
ãããã®ããŒã«ã䜿çšããã«ã¯ãAndroidç°å¢ã®æ¬¡ã®ã³ã³ããŒãã³ããã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
- Android SDKããŒã«ãããŒãžã§ã³21以éã
- API 16以äžãæèŒããAndroid SDKãã©ãããã©ãŒã ã
UIAutomatorã¯åžžã«æŽæ°ãããŠãããããææ°ã®ããã¥ã¡ã³ãã¯Webãµã€ãïŒ http://developer.android.com/tools/help/uiautomator/index.htmlïŒã§å ¥æã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ããã¹ãããããã®UIAutomatorã®å©ç¹ïŒ
- ç»é¢è§£å床ã«äŸåããŸããã
- ã¢ã¯ã·ã§ã³ã¯Android UIã³ã³ããŒãã³ãã«ãã€ã³ããããŸãã ããã«ããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ãçŽæ¥æäœã§ããŸãã ããšãã°ããOKããã¿ã³ãã¯ãªãã¯ããå¿ èŠãããå ŽåãUIAutomator APIã䜿çšããŠã³ãã³ããã¹ã¯ãªããã«éä¿¡ã§ããŸãããOKããšããã©ãã«ã®ä»ãããã¿ã³ãã¯ãªãã¯ããã¯ãªãã¯ããŸãã ãããã£ãŠã座æšã«ã¹ãããããå¿ èŠã¯ãããŸããã
- ãŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã®è€éãªã·ãŒã±ã³ã¹ãåçŸã§ããŸãããã®ã·ãŒã±ã³ã¹ã¯åžžã«åãã§ãã
- ãã¹ãã¯ãJavaã³ãŒããå€æŽããããšãªããããŸããŸãªããã€ã¹ã§å¿ èŠãªåæ°å®è¡ã§ããŸãã
- ããã€ã¹ã®å€éšãã¿ã³ã䜿çšã§ããŸãïŒæ»ããã¿ã³ããªããé³éãªã©ïŒã
ããããæ¬ ç¹ããããŸãïŒ
- HTML 5ããã³OpenGLã§èšè¿°ãããã¢ããªã±ãŒã·ã§ã³ã«ã¯äœ¿çšãå°é£ã§ãããããã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯Android UIèŠçŽ ããªãããã§ãã ãã®ç¹ã§ã座æšã«ã¢ã¿ãããããã代æ¿ã®ãã¹ããªãã·ã§ã³ãæ¢ãå¿ èŠããããŸãã
- Androidã¢ããªã±ãŒã·ã§ã³ãæŽæ°ãããšãã¯ãJavaã¹ã¯ãªããã確èªããå¿ èŠã«å¿ããŠæŽæ°ããå¿ èŠããããŸãã
UIAutomatorã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ããã¹ãããã«ã¯ã次ã®æé ãå®è¡ããŸãã
- ãã¹ãã®æºåïŒã¢ããªã±ãŒã·ã§ã³ãããã€ã¹ã«ã€ã³ã¹ããŒã«ããUIã³ã³ããŒãã³ããåæããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã®èªåãã¹ããäœæããŸãã
- ãã¹ããJARãã¡ã€ã«ã«ã³ã³ãã€ã«ããããã€ã¹ã«ã³ããŒããŸãã
- ãã¹ããå®è¡ããçµæãåæããŸãã
- ãã¹ãäžã«èŠã€ãã£ãããŸããŸãªãšã©ãŒã®ä¿®æ£ã
ã¹ã¯ãªããéçº
UIAutomatorãã¯ãããžãŒã«æ £ããããã«ãããã€ã¹ã§ç°¡åãªã¢ã¯ã·ã§ã³ãå®è¡ããç°¡åãªããã°ã©ã ã以äžã«ç€ºããŸãã ãã¹ããããã¢ããªã±ãŒã·ã§ã³ãšããŠæšæºã®Androidã¢ããªã±ãŒã·ã§ã³ã§ããã¡ãã»ãŒãžã³ã°ã䜿çšãããUIAutomatorãç¹å®ã®çªå·ã«SMSã¡ãã»ãŒãžãéä¿¡ããŸãã
ãã¹ãã§å®è£ ãããã¢ã¯ã·ã§ã³ãå®çŸ©ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ãæ€çŽ¢ããŠèµ·åããŸãã
- ã¡ãã»ãŒãžãäœæããŠéä¿¡ããŸãã
ã芧ã®ãšããããã¹ãŠãéåžžã«ç°¡åã§ãã
è©Šéšæºå
UIAutomatorviewerã¯ãã¢ããªã±ãŒã·ã§ã³ã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãåæããããã«äœ¿çšãããŸãã UIAutomatorviewerã¯ãã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ãããŠããããã€ã¹ã®ã¹ã¯ãªãŒã³ã·ã§ãããååŸããã¬ã€ã€ãŒã®éå±€ã衚瀺ããåã€ã³ã¿ãŒãã§ã€ã¹ã³ã³ããŒãã³ãã®ããããã£ãåå¥ã«è¡šç€ºããããã®äŸ¿å©ãªã°ã©ãã£ã«ã«ã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããŸãã ãã®æ å ±ããããšãUIAutomatorã¹ã¯ãªããã®äœæããã»ã¹ãå€§å¹ ã«ç°¡çŽ åãããŸãã
ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãåæããã«ã¯ïŒ
- Androidããã€ã¹ãã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããŸãã
- 次ã®å Žæã«ããUIAutomatorviewerãèµ·åããŸãïŒ<android-sdk> / tools /
$ uiautomatorviewer
- UIAutomatorviewerã®[ããã€ã¹ã¹ã¯ãªãŒã³ã·ã§ãã]ãã¿ã³ãã¯ãªãã¯ããŠãããã€ã¹ããç»åããã£ããã£ããŸãã
- ç¹å®ã®ã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ãéžæãããšããã®ããããã£ãå³åŽã®ãã€ã³ã«è¡šç€ºãããŸãã ãããã®ããããã£ã«åºã¥ããŠããã¹ãã¹ã¯ãªããã§èŠçŽ ãç°¡åã«èŠã€ããããšãã§ããŸãã
UIAutomatorviewerãç»åãã³ã³ããŒãã³ãã«å解ã§ããªãå Žåãã¢ããªã±ãŒã·ã§ã³ã¯HTML 5ãŸãã¯OpenGLã䜿çšããŠèšè¿°ãããŸãã
éçºç°å¢ã®ã»ããã¢ãã
Eclipseã䜿çšããŠããå ŽåïŒ
- Eclipseã§æ°ããJavaãããžã§ã¯ããäœæããŸãã ãã®ãããžã§ã¯ãã§ã¯ãUIAutomatorã¹ã¯ãªãããå®è£ ããŸãã ãããžã§ã¯ãã«ååãä»ããŸãããïŒSendMessage
- ãããžã§ã¯ããšã¯ã¹ãããŒã©ã§ãããžã§ã¯ããå³ã¯ãªãã¯ããŠã³ã³ããã¹ãã¡ãã¥ãŒãåŒã³åºãã[ããããã£]é
ç®ãéžæããŸãã [ããããã£]ã§ãJavaãã«ããã¹ãèŠã€ããå¿
èŠãªã©ã€ãã©ãªãè¿œå ããŸãã
- JUnitãµããŒããè¿œå ããã«ã¯ã[ã©ã€ãã©ãªã®è¿œå ]> [JUnit]ãéžæããŸãã
- [å€éšJARã®è¿œå ...]ãã¯ãªãã¯ãããšã<android-sdk> / platforms /ã«ããSDKã®ææ°ããŒãžã§ã³ã®ãã£ã¬ã¯ããªã«ç§»åãããã®äžã®2ã€ã®ãã¡ã€ã«ãéžæããå¿ èŠããããŸãïŒuiautomator.jarããã³android.jar
å¥ã®éçºç°å¢ã䜿çšããŠããå Žåã¯ãUIAutomator.jarããã³android.jarãã¡ã€ã«ããããžã§ã¯ãèšå®ã«è¿œå ãããŠããããšã確èªããŠãã ããã
UIAutomator API
UIAutomatorããã¹ãã¹ã¯ãªãããäœæããããã®ãã¹ãŠã®å¯èœæ§ã«ã€ããŠè©±ãã«ã¯ãããªãé·ãæéãå¿ èŠã«ãªããŸãã ãã¹ãŠã®è©³çŽ°æ å ±ã¯ãŠã§ããµã€ãã§èŠã€ããããšãã§ããŸãïŒ http : //developer.android.com/tools/help/UIAutomator/index.html
ã¹ã¯ãªããäœæ
æåã«ãããšãã°SendMessageãšããååã§ãSendMessageãããžã§ã¯ãã®Javaã¯ã©ã¹ã䜿çšããŠæ°ãããã¡ã€ã«ãäœæããŸãã ãã®ã¯ã©ã¹ã¯ãUIAutomatorTestCaseã¯ã©ã¹ããç¶æ¿ããå¿ èŠããããŸãã ã©ã€ãã©ãªãEclipseã«è¿œå ããã«ã¯ãããŒããŒãã·ã§ãŒãã«ããCtrl + Shift + oã䜿çšããŸãã ä»ã®ã©ã€ãã©ãªãåãããã«è¿œå ãããã®ã§ãããã«ã€ããŠã¯ãã説æããŸããã
ã¢ããªã±ãŒã·ã§ã³ã®äž»ãªæ©èœããã¹ãããããã®3ã€ã®é¢æ°ãäœæããŸãããã
- ã¢ããªã±ãŒã·ã§ã³ãæ€çŽ¢ããŠèµ·åãã
- SMSéä¿¡
- ã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ã¡ãã¥ãŒã«æ»ã
ãããã®ã¡ãœããããã¹ãŠå®è¡ããæåã®é¢æ°ã¯ãã¡ã€ã³é¢æ°ã®äžçš®ã§ã次ã®ããã«ãªããŸã
public void test() { // Here will be called for all other functions }
ã¢ããªã±ãŒã·ã§ã³ãæ€çŽ¢ããŠèµ·åããæ©èœ
ãã®æ©èœã¯æ¬¡ã®ã¢ã¯ã·ã§ã³ãå®è¡ããŸãïŒããŒã ãã¿ã³ãæŒããŠã¡ã€ã³ãŠã£ã³ããŠã«ç§»åããã¡ãã¥ãŒãéããŠç®çã®ã¢ããªã±ãŒã·ã§ã³ã®ã¢ã€ã³ã³ãèŠã€ãããã®ã¢ããªã±ãŒã·ã§ã³ãèµ·åããŸãã
ã¢ããªã±ãŒã·ã§ã³ãæ€çŽ¢ããŠèµ·åãã
private void findAndRunApp() throws UiObjectNotFoundException { // Go to main screen getUiDevice().pressHome(); // Find menu button UiObject allAppsButton = new UiObject(new UiSelector() .description("Apps")); // Click on menu button and wait new window allAppsButton.clickAndWaitForNewWindow(); // Find App tab UiObject appsTab = new UiObject(new UiSelector() .text("Apps")); // Click on app tab appsTab.click(); // Find scroll object (menu scroll) UiScrollable appViews = new UiScrollable(new UiSelector() .scrollable(true)); // Set the swiping mode to horizontal (the default is vertical) appViews.setAsHorizontalList(); // Find Messaging application UiObject settingsApp = appViews.getChildByText(new UiSelector() .className("android.widget.TextView"), "Messaging"); // Open Messaging application settingsApp.clickAndWaitForNewWindow(); // Validate that the package name is the expected one UiObject settingsValidation = new UiObject(new UiSelector() .packageName("com.android.mms")); assertTrue("Unable to detect Messaging", settingsValidation.exists()); }
ãã¹ãŠã®ã¯ã©ã¹åããã¿ã³ããã¹ããªã© uiautomatorviewerã䜿çšããŠååŸãããŸããã
SMSéä¿¡
ãã®æ©èœã§ã¯ãæ°ããã¡ãã»ãŒãžãäœæããããã®ãã¿ã³ãæ€çŽ¢ããŠæŒããé»è©±çªå·ãã¡ãã»ãŒãžã®ããã¹ããå ¥åããŠéä¿¡ããŸãã æ°å€ãšããã¹ãã¯ãé¢æ°ã®åŒæ°ãä»ããŠæž¡ãããŸãã
SMSéä¿¡æ©èœ
private void sendMessage(String toNumber, String text) throws UiObjectNotFoundException { // Find and click New message button UiObject newMessageButton = new UiObject(new UiSelector() .className("android.widget.TextView").description("New message")); newMessageButton.clickAndWaitForNewWindow(); // Find to box and enter the number into it UiObject toBox = new UiObject(new UiSelector() .className("android.widget.MultiAutoCompleteTextView").instance(0)); toBox.setText(toNumber); // Find text box and enter the message into it UiObject textBox = new UiObject(new UiSelector() .className("android.widget.EditText").instance(0)); textBox.setText(text); // Find send button and send message UiObject sendButton = new UiObject(new UiSelector() .className("android.widget.ImageButton").description("Send")); sendButton.click(); }
ãããã®ãã©ãŒã ã«ã¯ããã¹ãã説æããªããããçªå·ã®ãã£ãŒã«ããšéä¿¡çšã®ãã£ãŒã«ããç¹å¥ãªæšèã§èŠã€ããããšãã§ããŸããã§ããã ãããã£ãŠãã€ã³ã¹ã¿ã³ã¹ã¡ãœããã䜿çšããŠããããèŠã€ããŸãã ãã®ã¡ãœããã䜿çšãããšãã€ã³ã¿ãŒãã§ã€ã¹éå±€ã®ã·ãªã¢ã«çªå·ã§èŠçŽ ãååŸã§ããŸãã
ãã©ã¡ãŒã¿ãŒãšããŠã¡ãã»ãŒãžããã¹ãã ãã§ãªããåä¿¡è ã®é»è©±çªå·ãåä¿¡ããå¯èœæ§ãèªèããŠããŸãã ããã©ã«ãã®ãã©ã¡ãŒã¿ãŒã®åæåãtestïŒïŒé¢æ°ã«è¿œå ããå¿ èŠããããŸãããããã¯ã察å¿ããé¢æ°ã«åŒæ°ãšããŠæž¡ãããå ŽåããŠãŒã¶ãŒå®çŸ©ã®å€ã§äžæžãããå¿ èŠããããŸãã
ãã¹ãã§ãã©ã¡ãŒã¿ãŒãåãåã
// Default parameters String toNumber = "123456"; String text = "Test message"; String toParam = getParams().getString("to"); String textParam = getParams().getString("text"); if (toParam != null) { // Remove spaces toNumber = toParam.trim(); } if (textParam != null) { text = textParam.trim(); }
ãããã£ãŠãã³ãã³ãã©ã€ã³ãä»ããŠã¹ã¯ãªããã«ãã©ã¡ãŒã¿ãŒãæž¡ãããšãã§ããŸãã ããã¯ã-eã¹ã€ããã䜿çšããŠå®è¡ã§ããŸãã ãã®åŸããã©ã¡ãŒã¿åãšå€ã®2ã€ã®å€ã転éãããŸãã ããšãã°ãçªå·ã777777ããåä¿¡è ã®çªå·ãšããŠè»¢éããã«ã¯ããã©ã¡ãŒã¿-eãã777777ãæž¡ããŸãããããã®ãã©ã¡ãŒã¿ãååŸããã«ã¯ãã¹ã¯ãªããã¯ã¡ãœããgetParamsïŒïŒã䜿çšããŸãã
ããããããã€ãã®èœãšãç©ŽããããŸãã ããšãã°ãäžéšã®æåãå«ãããã¹ããéä¿¡ããããšã¯äžå¯èœã§ãããUIAutomatorã¯ããããåãå ¥ããŸããïŒã¹ããŒã¹ãïŒã<ã>ãïŒãïŒãããããªã©ãããã³UnicodeæåïŒã ãããè¡ãã«ã¯ããããã®æåãã¹ã¯ãªããã«æäŸãããšãã«æååã§çœ®ãæããããšãææ¡ããŸããããšãã°ãã¹ããŒã¹ãæååã§çœ®ãæããïŒblogspaceblogã ããã¯ãã¹ã¯ãªããã䜿çšããŠãå ¥åãã©ã¡ãŒã¿ãŒãåŠçããUIAutomatorã¹ã¯ãªãããå®è¡ããå Žåã«äŸ¿å©ã§ãã å ¥åãã©ã¡ãŒã¿ãŒãã§ãã¯ã«è§£æãè¿œå ãã次ã®è¡ã眮ãæããŸãã
æåå眮æã³ãŒã
if (toParam != null) { toNumber = toParam.trim(); } if (textParam != null) { textParam = textParam.replace("blogspaceblog", " "); textParam = textParam.replace("blogamperblog", "&"); textParam = textParam.replace("bloglessblog", "<"); textParam = textParam.replace("blogmoreblog", ">"); textParam = textParam.replace("blogopenbktblog", "("); textParam = textParam.replace("blogclosebktblog", ")"); textParam = textParam.replace("blogonequoteblog", "'"); textParam = textParam.replace("blogtwicequoteblog", "\""); text = textParam.trim(); }
ã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ã¡ãã¥ãŒã«æ»ã
ãã®é¢æ°ã¯ã以åã«å®è£ ãããã®ã®äžã§æãåçŽã§ãã 圌女ã¯ãæ°ããã¡ãã»ãŒãžãäœæãããã¿ã³ãèŠã€ãããŸã§ãæ»ããã¿ã³ãæŒããŸãã
private void exitToMainWindow() { // Find New message button UiObject newMessageButton = new UiObject(new UiSelector() .className("android.widget.TextView").description("New message")); // Press back button while new message button doesn't exist while(!newMessageButton.exists()) { getUiDevice().pressBack(); } }
ãã¹ãããã®ãã°ã®åé
ãã¹ãçµæãèšé²ããã«ã¯ãæšæºã®Androidãããã¡ãŒã䜿çšã§ããŸãã ããã䜿çšããã«ã¯ãã¹ã¯ãªããã§ã©ã€ãã©ãªãæ¥ç¶ããå¿ èŠããããŸãã
import android.util.Log;
èå³æ·±ãæ å ±ã¯ãã¹ãŠãã°ã«èšé²ã§ããŸãã ããã¯ã次ã®é¢æ°ã䜿çšããŠå®è¡ã§ããŸãã
Log.i(String title, String title);
次ã®ã³ãã³ãã䜿çšããŠãããã€ã¹ãããã°ãèªã¿åãããšãã§ããŸãã
$ adb logcat
logcatã®è©³çŽ°ã«ã€ããŠã¯ãå ¬åŒWebãµã€ãdeveloper.android.com/tools/help/logcat.htmlãã芧ãã ããã
çµæã®ã³ãŒã
ãããã£ãŠã次ã®ã³ãŒãããããŸãã
ã³ãŒãã衚瀺
package blog.send.message; import android.util.Log; import com.android.UIAutomator.core.UiObject; import com.android.UIAutomator.core.UiObjectNotFoundException; import com.android.UIAutomator.core.UiScrollable; import com.android.UIAutomator.core.UiSelector; import com.android.UIAutomator.testrunner.UiAutomatorTestCase; public class SendMessage extends UiAutomatorTestCase { public void test() throws UiObjectNotFoundException { // Default parameters String toNumber = "123456"; String text = "Test message"; String toParam = getParams().getString("to"); String textParam = getParams().getString("text"); if (toParam != null) { toNumber = toParam.trim(); } if (textParam != null) { textParam = textParam.replace("blogspaceblog", " "); textParam = textParam.replace("blogamperblog", "&"); textParam = textParam.replace("bloglessblog", "<"); textParam = textParam.replace("blogmoreblog", ">"); textParam = textParam.replace("blogopenbktblog", "("); textParam = textParam.replace("blogclosebktblog", ")"); textParam = textParam.replace("blogonequoteblog", "'"); textParam = textParam.replace("blogtwicequoteblog", "\""); text = textParam.trim(); } Log.i("SendMessageTest", "Start SendMessage"); findAndRunApp(); sendMessage(toNumber, text); exitToMainWindow(); Log.i("SendMessageTest", "End SendMessage"); } // Here will be called for all other functions private void findAndRunApp() throws UiObjectNotFoundException { // Go to main screen getUiDevice().pressHome(); // Find menu button UiObject allAppsButton = new UiObject(new UiSelector() .description("Apps")); // Click on menu button and wait new window allAppsButton.clickAndWaitForNewWindow(); // Find App tab UiObject appsTab = new UiObject(new UiSelector() .text("Apps")); // Click on app tab appsTab.click(); // Find scroll object (menu scroll) UiScrollable appViews = new UiScrollable(new UiSelector() .scrollable(true)); // Set the swiping mode to horizontal (the default is vertical) appViews.setAsHorizontalList(); // Find Messaging application UiObject settingsApp = appViews.getChildByText(new UiSelector() .className("android.widget.TextView"), "Messaging"); // Open Messaging application settingsApp.clickAndWaitForNewWindow(); // Validate that the package name is the expected one UiObject settingsValidation = new UiObject(new UiSelector() .packageName("com.android.mms")); assertTrue("Unable to detect Messaging", settingsValidation.exists()); } private void sendMessage(String toNumber, String text) throws UiObjectNotFoundException { // Find and click New message button UiObject newMessageButton = new UiObject(new UiSelector() .className("android.widget.TextView").description("New message")); newMessageButton.clickAndWaitForNewWindow(); // Find to box and enter the number into it UiObject toBox = new UiObject(new UiSelector() .className("android.widget.MultiAutoCompleteTextView").instance(0)); toBox.setText(toNumber); // Find text box and enter the message into it UiObject textBox = new UiObject(new UiSelector() .className("android.widget.EditText").instance(0)); textBox.setText(text); // Find send button and send message UiObject sendButton = new UiObject(new UiSelector() .className("android.widget.ImageButton").description("Send")); sendButton.click(); } private void exitToMainWindow() { // Find New message button UiObject newMessageButton = new UiObject(new UiSelector() .className("android.widget.TextView").description("New message")); // Press back button while new message button doesn't exist while(!newMessageButton.exists()) { getUiDevice().pressBack(); sleep(500); } } }
UIAutomatorãã¹ãã®ã³ã³ãã€ã«ãšå®è¡
- ãã¹ããã«ãæ§æãã¡ã€ã«ãçæããã«ã¯ãã¿ãŒããã«ã§æ¬¡ã®ã³ãã³ããå®è¡ããå¿
èŠããããŸãã
$ <android-sdk>/tools/android create uitest-project -n <name> -t <target-id> -p <path>
- , UIAutomator ( : SendMessage), <target-id> - Android API Level ( : <android-sdk>/tools/android list targets) - .
ANDROID_HOME:
ã©ãã§ãã- , UIAutomator ( : SendMessage), <target-id> - Android API Level ( : <android-sdk>/tools/android list targets) - .
ANDROID_HOME:
- , UIAutomator ( : SendMessage), <target-id> - Android API Level ( : <android-sdk>/tools/android list targets) - .
ANDROID_HOME:
- WindowsïŒ
set ANDROID_HOME=<path_to_your_sdk>
- UnixïŒ
export ANDROID_HOME=<path_to_your_sdk>
æé 1ã§çæãããbuild.xmlãã¡ã€ã«ãå«ããããžã§ã¯ãã®ãã£ã¬ã¯ããªã«ç§»åããŠãã³ãã³ããå®è¡ããŸãã
$ ant build
adb pushã³ãã³ãã䜿çšããŠãã¢ã»ã³ãã«ãããJARãã¡ã€ã«ãããã€ã¹ã«ã³ããŒããŸãã
$ adb push <path_to_output_jar> /data/local/tmp/
$ adb push <project_dir>/bin/SendMessage.jar /data/local/tmp/
ã¹ã¯ãªãããå®è¡ããŸãã
$ adb shell uiautomator runtest /data/local/tmp/SendMessage.jar âc blog.send.message.SendMessage -e to 777777
ãããã«
UIAutomatorã®äœ¿çšã¯ãå€æ°ã®ããã€ã¹äžã®ã¢ããªã±ãŒã·ã§ã³ã®é«å質ãªãã¹ãã«éåžžã«äŸ¿å©ã§ãã ãã®ãã¯ãããžãŒã䜿çšããŠãã¢ããªã±ãŒã·ã§ã³ããã¢ããããã®ããŸããŸãªãã¢ãäœæã§ããŸãã - WindowsïŒ