1

Wifi をオンにして、Wifi のユーザー名とパスワードの入力を求められたときにテキスト フィールドにテキストを入力するなど、いくつかの Android UI テストのために UiAutomation を実行したいと思います: http://android.zedcn.com/reference/android/app/UiAutomation.html

これを実現するために UiAutomation クラスからメソッドを呼び出すにはどうすればよいですか? 1) 設定アプリをクリックします 2) Wifi のトグル アイコンをクリックします 3) ネットワーク SSID をクリックします 4) ユーザー名とパスワードをテキスト フィールドに入力します

始めるためのヒントをいただければ幸いです。

4

1 に答える 1

-2
There are couple of ways you can accomplish. I prefer each page of the device as single class and defining all the required methods for that page. Example: Wifi Page

Create following classes:
 - Lock Screen
 - Pin Entry
 - Home Screen
 - All App
 - Settings
 - Wifi
 - MoreOption Menu
 - Add Network Dialouge

LockScreenPage: Define following Methods:
 - VerifyLockScreenPage
 - SwipeLockImage

PinEntryPage: Define following methods:
 - VerifyPinEntryPage
 - EnterPin
 - PressEnter

HomeScreenPage: Define following methods:
 - VerifyHomeScreenPage
 - ClickAllAppButton

AllAppPage: Define following methods:
 - VerifyAllAppPage
 - IsAppPresent : used for searching the expected app. In Your case it would be settings
 - OpenApp : Once IsAppPresent returns true, OpenApp is called to open the expected app. In your case its Settings.

SettingsPage : Define Following methods:
 - VerifySettingPage
 - IsSettingOptionPresent: Used to search through the available options whether expected option is present or not. If present return true else false. In your case it would be Wifi.
 - clickOption: Once IsSettingOptionPresent returns true, open this expected option .

WiFiPage: Define following methods:
 - VerifyWiFiPage
 - TurnOnWiFi
 - TurnOffWiFi
 - IsWiFiConnected
 - ClickMoreOption

MoreOptionMenu: Define Following methods:
 - VerifyMoreOptionMenu
 - ClickAddNetwork

AddNetworkDialogue: Define following methods:
 - VerifyAddNetworkDialogue
 - EnterNetworkId
 - ClickAndSelectSecurity
 - EnterPassword
 - ClickSave

Now once you are done with these, your test would look like this:
LockScreenPage lockScreen = new LockScreenPage();
lockScreen. VerifyLockScreenPage
lockScreen. SwipeLockImage

PinEntryPage pinEntryPage = new PinEntryPage();
pinEntryPage.VerifyPinEntryPage;
pinEntryPage.EnterPin
pinEntryPage.PressEnter

HomeScreenPage homeScreenPage = new HomeScreenPage();
homeScreenPage.VerifyHomeScreenPage
homeScreenPage.ClickAllAppButton
 ….. Similarly for the rest


Below is some sample code for LockScreenPage. Similarly define for other too.
package com.google.android.pages.common;

import android.util.Log;

import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.google.android.common.TestConstants;
import com.google.android.pages.Page;

public class LockScreenPage extends Page {

    public static String TITLE = "LOCK SCREEN";

    // Lock button image on the lock screen.
    public static UiSelector TITLE_SELECTOR = new UiSelector()
            .className("android.widget.ImageView")
            .resourceId("com.android.systemui:id/lock_icon")
            .descriptionContains("Unlock");

    // All App button on the home screen after unlock.
    public UiSelector ALL_APP_BUTTON = new UiSelector().packageName(
            "com.google.android.googlequicksearchbox").descriptionContains(
            "Apps");

    // Constructor
    public LockScreenPage(UiAutomatorTestCase testCase) throws Exception {
        super(testCase);
        getDevice().wakeUp();
        Log.d(getTag(), String.format(">>>>\t %s page.", TITLE));
        getTestUtils().storeUiAutomatorViewerFiles(TITLE);
    }

    // Swiping the unlock image to go to the enter pin page
    public EnterPinPage swipeUpToUnlock(UiObject obj) throws Exception {
        Log.d(getTag(), "Swiping up the object.");
        obj.swipeUp(TestConstants.DEFAULT_SWIPE_STEPS);
        getTestUtils().storeUiAutomatorViewerFiles(TITLE + 
                " after swiping up the object");
        return new EnterPinPage(getTestCase());
    }

    // Verifying whether device is locked or not.
    public boolean isDeviceLocked(UiObject obj) throws Exception {
        Log.d(getTag(), "Is devices Locked?");
        getDevice().wakeUp();
        if (new UiObject(ALL_APP_BUTTON).exists()) {
            Log.d(getTag(), "Divice is: Unlocked.");
            return false;
        }
        Log.d(getTag(), "Divice is: Locked.");
        return true;
    }

    @Override
    public String getPageName() {
        return TITLE;
    }

    @Override
    public UiSelector getPageTitleSelector() {
        return TITLE_SELECTOR;
    }
}

Hope this helps
于 2014-12-05T10:13:35.820 に答える