Created
November 22, 2012 14:22
-
-
Save nowsprinting/4131415 to your computer and use it in GitHub Desktop.
UI Automatorさんがtwiccaで投稿してくれるテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nowsprinting.uiautomatorexample; | |
import com.android.uiautomator.core.UiObject; | |
import com.android.uiautomator.core.UiObjectNotFoundException; | |
import com.android.uiautomator.core.UiSelector; | |
import com.android.uiautomator.testrunner.UiAutomatorTestCase; | |
/** | |
* UI Automatorでtwiccaを操作してみるテスト. | |
* | |
* @author Koji Hasegawa | |
* @since 1.0 | |
*/ | |
public class TwiccaTest extends UiAutomatorTestCase { | |
public void testPostByTwicca() throws UiObjectNotFoundException { | |
// Homeボタンをタップ | |
getUiDevice().pressHome(); | |
// 対象アプリはホームにある前提 | |
UiObject twiccaLauncher = new UiObject(new UiSelector().text("twicca")); | |
twiccaLauncher.clickAndWaitForNewWindow(); | |
// 起動を確認 | |
UiObject twiccaValidation = new UiObject(new UiSelector().packageName("jp.r246.twicca")); | |
assertTrue("Unable to detect twicca", twiccaValidation.exists()); | |
// 投稿ボタン(ヒエラルキをたどって取得) | |
UiObject frame0 = new UiObject(new UiSelector().index(0)); | |
UiObject liner0 = frame0.getChild(new UiSelector().index(0)); | |
UiObject frame1 = liner0.getChild(new UiSelector().index(1)); | |
UiObject relative0 = frame1.getChild(new UiSelector().index(0)); | |
UiObject liner1 = relative0.getChild(new UiSelector().index(2)); | |
UiObject openPostButton = liner1.getChild(new UiSelector().index(0)); | |
openPostButton.clickAndWaitForNewWindow(); | |
// EditTextに入力(1つしかないのでクラス名で取得) | |
UiObject editText = new UiObject(new UiSelector().className("android.widget.EditText")); | |
editText.setText("oregayu-aio-tome-ta-da!"); | |
getUiDevice().pressEnter(); | |
// 投稿ボタンをタップ(テキストラベルで取得) | |
UiObject tweetButton = new UiObject(new UiSelector().text("ツイート")); | |
tweetButton.clickAndWaitForNewWindow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment