當前位置: 首頁>>代碼示例>>Java>>正文


Java UiObjectNotFoundException類代碼示例

本文整理匯總了Java中android.support.test.uiautomator.UiObjectNotFoundException的典型用法代碼示例。如果您正苦於以下問題:Java UiObjectNotFoundException類的具體用法?Java UiObjectNotFoundException怎麽用?Java UiObjectNotFoundException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UiObjectNotFoundException類屬於android.support.test.uiautomator包,在下文中一共展示了UiObjectNotFoundException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
public static void allowPermissionsIfNeeded(String permissionNeeded) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(permissionNeeded)) {
            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector()
                    .clickable(true)
                    .checkable(false)
                    .index(GRANT_BUTTON_INDEX));
            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }
    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:18,代碼來源:PermissionGranter.java

示例2: testChangeText_sameActivity

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
public void testChangeText_sameActivity() {


    UiObject skipButton = mDevice.findObject(new UiSelector()
            .text("SKIP").className("android.widget.TextView"));

    // Simulate a user-click on the OK button, if found.
    try {
        if (skipButton.exists() && skipButton.isEnabled()) {
                skipButton.click();
        }
    } catch (UiObjectNotFoundException e) {
        e.printStackTrace();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:17,代碼來源:UIAnimatorTest.java

示例3: shareTest

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
public void shareTest() throws InterruptedException, UiObjectNotFoundException {

    UiObject shareBtn = TestHelper.mDevice.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/share")
            .enabled(true));

    /* Go to a webpage */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));

    /* Select share */
    TestHelper.menuButton.perform(click());
    shareBtn.waitForExists(waitingTime);
    shareBtn.click();

    // For simulators, where apps are not installed, it'll take to message app
    TestHelper.shareMenuHeader.waitForExists(waitingTime);
    assertTrue(TestHelper.shareMenuHeader.exists());
    assertTrue(TestHelper.shareAppList.exists());
    TestHelper.pressBackKey();
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:27,代碼來源:ShareDialogTest.java

示例4: testA

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
/**
 * 測試CollapsingToolbarLayout
 * 被測Demo下載地址:https://github.com/alidili/DesignSupportDemo
 *
 * @throws UiObjectNotFoundException
 */
public void testA() throws UiObjectNotFoundException {
    // 獲取設備對象
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    UiDevice uiDevice = UiDevice.getInstance(instrumentation);
    // 獲取上下文
    Context context = instrumentation.getContext();

    // 啟動測試App
    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.yang.designsupportdemo");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    // 打開CollapsingToolbarLayout
    String resourceId = "com.yang.designsupportdemo:id/CollapsingToolbarLayout";
    UiObject collapsingToolbarLayout = uiDevice.findObject(new UiSelector().resourceId(resourceId));
    collapsingToolbarLayout.click();

    for (int i = 0; i < 5; i++) {
        // 向上移動
        uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(),
                uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2, 10);

        // 向下移動
        uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2,
                uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(), 10);
    }

    // 點擊應用返回按鈕
    UiObject back = uiDevice.findObject(new UiSelector().description("Navigate up"));
    back.click();

    // 點擊設備返回按鈕
    uiDevice.pressBack();
}
 
開發者ID:alidili,項目名稱:Demos,代碼行數:41,代碼來源:UiTest.java

示例5: testB

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
/**
 * 滑動界麵,打開About phone選項
 * 測試環境為標準Android 7.1.1版本,不同設備控件查找方式會有不同
 *
 * @throws UiObjectNotFoundException
 */
public void testB() throws UiObjectNotFoundException {
    // 獲取設備對象
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    UiDevice uiDevice = UiDevice.getInstance(instrumentation);
    // 獲取上下文
    Context context = instrumentation.getContext();

    // 點擊Settings按鈕
    UiObject uiObject = uiDevice.findObject(new UiSelector().description("Settings"));
    uiObject.click();

    // 滑動列表到最後,點擊About phone選項
    UiScrollable settings = new UiScrollable(new UiSelector().className("android.support.v7.widget.RecyclerView"));
    UiObject about = settings.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "About phone");
    about.click();

    // 點擊設備返回按鈕
    uiDevice.pressBack();
    uiDevice.pressBack();
}
 
開發者ID:alidili,項目名稱:Demos,代碼行數:27,代碼來源:UiTest.java

示例6: test018CheckSleepTimeOut

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
//檢查顯示下休眠時間正確(T1)
public void test018CheckSleepTimeOut() throws UiObjectNotFoundException {
    screenshotCap("after_enter");
    TestUtils.enterSettingsFirstLevelByName("顯示");
    UiObject2 sleepTimeObj = device.findObject(By.text("休眠")).getParent().findObject(By.res("android:id/summary"));
    String sleepTime = sleepTimeObj.getText();
    Assert.assertEquals("期望是無操作1周後,而實際是" + sleepTime, "無操作1周後", sleepTime);
    sleep(SHORT_SLEEP);
    sleepTimeObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 sleepOpt = device.findObject(By.checked(true));
    String sleepTime1 = sleepOpt.getText();
    Assert.assertEquals("期望是1周,而實際是" + sleepTime1, "1周", sleepTime1);
    sleep(SHORT_SLEEP);
    UiObject2 fiveMinObj = device.findObject(By.text("5分鍾"));
    fiveMinObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 sleepTimeObj1 = device.findObject(By.text("休眠")).getParent().findObject(By.res("android:id/summary"));
    String sleepTime2 = sleepTimeObj1.getText();
    Assert.assertEquals("期望是無操作5分鍾後,而實際是" + sleepTime, "無操作5分鍾後", sleepTime2);
    sleep(SHORT_SLEEP);
    sleepTimeObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 oneWeekObj = device.findObject(By.text("1周"));
    oneWeekObj.click();
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:25,代碼來源:SunmiSettings.java

示例7: test019CheckFont

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
//檢查顯示下字體大小正確(T1)
public void test019CheckFont() throws UiObjectNotFoundException {
    screenshotCap("after_enter");
    TestUtils.enterSettingsFirstLevelByName("顯示");
    UiObject2 fontObj = device.findObject(By.text("字體大小")).getParent().findObject(By.res("android:id/summary"));
    String fontSize = fontObj.getText();
    Assert.assertEquals("期望是正常,而實際是" + fontSize, "正常", fontSize);
    sleep(SHORT_SLEEP);
    fontObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 fontOpt = device.findObject(By.checked(true));
    String fontSize1 = fontOpt.getText();
    Assert.assertEquals("期望是正常,而實際是" + fontSize1, "正常", fontSize1);
    sleep(SHORT_SLEEP);
    UiObject2 hugeObj = device.findObject(By.text("超大"));
    hugeObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    sleep(SHORT_SLEEP);
    UiObject2 fontObj1 = device.findObject(By.text("字體大小")).getParent().findObject(By.res("android:id/summary"));
    String fontSize2 = fontObj1.getText();
    Assert.assertEquals("期望是超大,而實際是" + fontSize2, "超大", fontSize2);
    sleep(SHORT_SLEEP);
    fontObj1.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 normalObj = device.findObject(By.text("正常"));
    normalObj.click();
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:26,代碼來源:SunmiSettings.java

示例8: test021CheckTipsAndNotifFirstLevel

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
    //檢查提示音和通知(T1)
    public void test021CheckTipsAndNotifFirstLevel() throws UiObjectNotFoundException {
        screenshotCap("after_enter");
        TestUtils.enterSettingsFirstLevelByName("提示音和通知");
        sleep(SHORT_SLEEP);
//        Pattern p = Pattern.compile("\\s");
        String[] tipAndNotfi = {"提示音和通知", "聲音", "媒體音量", "通知音量", "免打擾", "默認通知鈴聲", "Pixie Dust", "其他提示音", "通知", "設備鎖定時", "顯示所有通知內容", "應用通知"};
        List<UiObject2> tipAndNotifList = device.findObjects(By.clazz("android.widget.TextView"));
        sleep(SHORT_SLEEP);
        for (int i = 0; i < tipAndNotifList.size(); i++) {
            Assert.assertEquals("期望是" + tipAndNotfi[i] + ",而實際是" + tipAndNotifList.get(i), tipAndNotfi[i], tipAndNotifList.get(i).getText());
            Log.v("myautotest", tipAndNotifList.get(i).getText());
        }
//        Iterator it = tipAndNotifList.iterator();
//        while(it.hasNext()){
//            Log.v("myautotest",it.next());
//        }
    }
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:20,代碼來源:SunmiSettings.java

示例9: allTests

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
public void allTests() throws IOException, UiObjectNotFoundException, InterruptedException {
    String appName, type, value;
    if (parser.apps != null) {
        for (App app : parser.apps) {
            appName = app.getName();
            if (launchPackage(appName)) {
                if (app.actList != null) {
                    for (Action action : app.actList) {
                        type = action.getType();
                        value = action.getValue();
                        processAction(type, value);
                    }
                }
            }
        }
    }
}
 
開發者ID:Sl0v3C,項目名稱:UIAutomatorAdapter,代碼行數:19,代碼來源:AutoTestAdapter.java

示例10: test009SearchByTitle

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test009SearchByTitle() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
    String targetAppName = hotOne.getText();
    UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
    searchObj.click();
    TestUtils.screenshotCap("afterClickSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
    searchObj1.click();
    searchObj1.setText(targetAppName);
    TestUtils.screenshotCap("inputSearchContent");
    UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject appInfo = appList.getChildByInstance(new UiSelector().className("android.widget.FrameLayout"),0);
    UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
    Assert.assertEquals(targetAppName,appNameObj.getText());
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:20,代碼來源:SunmiAppStore_v3_3_15.java

示例11: test020EnterFeedback

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
    @Test
    public void test020EnterFeedback() throws UiObjectNotFoundException {
        TestUtils.screenshotCap("appStoreHome");
        UiObject2 mineEntrence = device.findObject(By.res("woyou.market:id/fab_me"));
        mineEntrence.clickAndWait(Until.newWindow(),LONG_WAIT);
        TestUtils.screenshotCap("mineHome");
        UiScrollable mineScroll = new UiScrollable(new UiSelector().className("android.widget.ScrollView"));
        mineScroll.scrollTextIntoView("反饋");
        TestUtils.screenshotCap("ScrollToFeedbackInterface");
        UiObject2 feedbackObj = device.findObject(By.text("反饋"));
        feedbackObj.clickAndWait(Until.newWindow(),LONG_WAIT);
        TestUtils.screenshotCap("enterFeedbackInterface");
        String currentPkgName = device.getCurrentPackageName();
//        for (int i = 0; i <10 ; i++) {
//            Log.v("myautotest1",device.getCurrentPackageName());
//            sleep(500);
//        }
        Assert.assertEquals("期望當前包名為com.sunmi.userfeedback,而實際為"+currentPkgName,"com.sunmi.userfeedback",currentPkgName);
    }
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:21,代碼來源:SunmiAppStore_v3_3_15.java

示例12: test024CommentBeforeInstall

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test024CommentBeforeInstall() throws IOException, UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollIntoView(new UiSelector().resourceId("woyou.market:id/id_tv_install_view").text("安裝"));
    TestUtils.screenshotCap("scrollInstallBtnInterface");
    UiObject2 installObj = device.findObject(By.res("woyou.market:id/id_tv_install_view").text("安裝"));
    UiObject2 fullAppObj = installObj.getParent().getParent();
    fullAppObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("uninstalledAppDetail");
    UiObject2 commentObj = device.findObject(By.res("woyou.market:id/tv_install_comment_app"));
    commentObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("afterClickComment");
    UiObject2 rateObj = device.findObject(By.res("woyou.market:id/rating_bar"));
    Assert.assertNull(rateObj);
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:21,代碼來源:SunmiAppStore_v3_3_15.java

示例13: test025CommentAfterInstall

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test025CommentAfterInstall() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollIntoView(new UiSelector().resourceId("woyou.market:id/id_tv_install_view").text("打開"));
    UiObject2 installObj = device.findObject(By.res("woyou.market:id/id_tv_install_view").text("打開"));
    UiObject2 fullAppObj = installObj.getParent().getParent();
    fullAppObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("enterAppDetail");
    UiObject2 commentObj = device.findObject(By.res("woyou.market:id/tv_install_comment_app"));
    commentObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    device.wait(Until.hasObject(By.res("woyou.market:id/rating_bar")),LONG_WAIT);
    TestUtils.screenshotCap("afterClickComment");
    UiObject2 rateObj = device.findObject(By.res("woyou.market:id/rating_bar"));
    Assert.assertNotNull(rateObj);
    device.pressBack();
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:22,代碼來源:SunmiAppStore_v3_3_15.java

示例14: test026FoldupAppDetail

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test026FoldupAppDetail() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject fullAppObj = hotAllScroll.getChild(new UiSelector().className("android.widget.FrameLayout"));
    fullAppObj.clickAndWaitForNewWindow(LONG_WAIT);
    TestUtils.screenshotCap("enterAppDetail");
    UiObject2 foldupButton = device.findObject(By.res("woyou.market:id/iv_arrow"));
    foldupButton.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("foldUpAppDetail");
    UiScrollable hotAllScroll1 = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    Assert.assertNotNull(hotAllScroll1);
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:18,代碼來源:SunmiAppStore_v3_3_15.java

示例15: test009SearchByTitle

import android.support.test.uiautomator.UiObjectNotFoundException; //導入依賴的package包/類
@Test
public void test009SearchByTitle() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
    String targetAppName = hotOne.getText();
    UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
    searchObj.click();
    TestUtils.screenshotCap("afterClickSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
    searchObj1.click();
    searchObj1.setText(targetAppName);
    TestUtils.screenshotCap("inputSearchContent");
    UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject appInfo = appList.getChildByInstance(new UiSelector().resourceId("woyou.market:id/app_view"),0);
    UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
    Assert.assertEquals("搜索結果列表第一個應用不是"+targetAppName,targetAppName,appNameObj.getText());
}
 
開發者ID:sunmiqa,項目名稱:SunmiAuto,代碼行數:19,代碼來源:SunmiAppStore.java


注:本文中的android.support.test.uiautomator.UiObjectNotFoundException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。