本文整理匯總了Java中android.support.test.uiautomator.UiObject.waitForExists方法的典型用法代碼示例。如果您正苦於以下問題:Java UiObject.waitForExists方法的具體用法?Java UiObject.waitForExists怎麽用?Java UiObject.waitForExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.test.uiautomator.UiObject
的用法示例。
在下文中一共展示了UiObject.waitForExists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shareTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的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();
}
示例2: testIfNotificationExists
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Inner method to get a dedicated notification and test it
* @param textContent - The text to use to get the notification
*/
private void testIfNotificationExists( String textContent ) {
UiObject n = null;
if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
n = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("pylapp.smoothclicker.android")
.textContains(textContent));
} else {
n = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("com.android.systemui")
.textContains(textContent));
}
mDevice.openNotification();
n.waitForExists(2000);
assertTrue(n.exists());
}
示例3: testNotification
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Inner method to get a dedicated notification and test it
* @param textContent - The text to use to get the notification
*/
private void testNotification( String textContent ){
UiObject n = null;
if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
n = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("pylapp.smoothclicker.android")
.textContains(textContent));
} else {
n = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("com.android.systemui")
.textContains(textContent));
}
mDevice.openNotification();
n.waitForExists(60000);
assertTrue(n.exists());
}
示例4: BadURLcheckTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void BadURLcheckTest() throws InterruptedException, UiObjectNotFoundException {
UiObject cancelOpenAppBtn = TestHelper.mDevice.findObject(new UiSelector()
.resourceId("android:id/button2"));
UiObject openAppalert = TestHelper.mDevice.findObject(new UiSelector()
.text("Open link in another app"));
/* provide an invalid URL */
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText("htps://www.mozilla.org");
TestHelper.hint.waitForExists(waitingTime);
TestHelper.pressEnterKey();
TestHelper.tryAgainBtn.waitForExists(waitingTime);
/* Check for error message */
assertTrue(TestHelper.notFoundMsg.exists());
assertTrue(TestHelper.notFounddetailedMsg.exists());
assertTrue(TestHelper.tryAgainBtn.exists());
/* provide market URL that is handled by Google Play app */
TestHelper.floatingEraseButton.perform(click());
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText("market://details?id=org.mozilla.firefox&referrer=" +
"utm_source%3Dmozilla%26utm_medium%3DReferral%26utm_campaign%3Dmozilla-org");
TestHelper.pressEnterKey();
// Wait for the dialog
cancelOpenAppBtn.waitForExists(waitingTime);
assertTrue(openAppalert.exists());
assertTrue(cancelOpenAppBtn.exists());
cancelOpenAppBtn.click();
TestHelper.floatingEraseButton.perform(click());
TestHelper.erasedMsg.waitForExists(waitingTime);
}
示例5: settingsScreenTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void settingsScreenTest() throws InterruptedException, UiObjectNotFoundException {
UiObject SearchEngineSelection = TestHelper.settingsList.getChild(new UiSelector()
.className("android.widget.LinearLayout")
.instance(0));
UiObject searchHeading = TestHelper.mDevice.findObject(new UiSelector()
.text("Search")
.resourceId("android:id/title"));
UiObject privacyHeading = TestHelper.mDevice.findObject(new UiSelector()
.text("Privacy")
.resourceId("android:id/title"));
UiObject perfHeading = TestHelper.mDevice.findObject(new UiSelector()
.text("Performance")
.resourceId("android:id/title"));
UiObject mozHeading = TestHelper.mDevice.findObject(new UiSelector()
.text("Mozilla")
.resourceId("android:id/title"));
/* Go to Settings */
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
openSettings();
SearchEngineSelection.waitForExists(waitingTime);
/* Check the first element and other headings are present */
assertTrue(SearchEngineSelection.isEnabled());
assertTrue(searchHeading.exists());
assertTrue(privacyHeading.exists());
TestHelper.swipeUpScreen();
assertTrue(perfHeading.exists());
mozHeading.waitForExists(waitingTime);
assertTrue(mozHeading.exists());
}
示例6: OpenTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void OpenTest() throws InterruptedException, UiObjectNotFoundException {
UiObject openWithBtn = TestHelper.mDevice.findObject(new UiSelector()
.resourceId("org.mozilla.focus.debug:id/open_select_browser")
.enabled(true));
UiObject openWithTitle = TestHelper.mDevice.findObject(new UiSelector()
.className("android.widget.TextView")
.text("Open with…")
.enabled(true));
UiObject openWithList = TestHelper.mDevice.findObject(new UiSelector()
.resourceId("org.mozilla.focus.debug:id/apps")
.enabled(true));
/* Go to mozilla page */
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText("mozilla");
TestHelper.hint.waitForExists(waitingTime);
TestHelper.pressEnterKey();
assertTrue(TestHelper.webView.waitForExists(waitingTime));
/* Select Open with from menu, check appearance */
TestHelper.menuButton.perform(click());
openWithBtn.waitForExists(waitingTime);
openWithBtn.click();
openWithTitle.waitForExists(waitingTime);
assertTrue(openWithTitle.exists());
assertTrue(openWithList.exists());
TestHelper.pressBackKey();
}
示例7: takeScreenshotOfNotification
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void takeScreenshotOfNotification() throws Exception {
onView(withId(R.id.urlView))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText(webServer.url("/").toString()), pressImeActionButton());
onView(withId(R.id.display_url))
.check(matches(isDisplayed()))
.check(matches(withText(containsString(webServer.getHostName()))));
final UiObject openAction = device.findObject(new UiSelector()
.descriptionContains(getString(R.string.notification_action_open))
.resourceId("android:id/action0")
.enabled(true));
device.openNotification();
try {
if (!openAction.waitForExists(waitingTime)) {
// The notification is not expanded. Let's expand it now.
device.findObject(new UiSelector()
.text(getString(R.string.app_name)))
.swipeDown(20);
assertTrue(openAction.waitForExists(waitingTime));
}
Screengrab.screenshot("DeleteHistory_NotificationBar");
} finally {
// Close notification tray again
device.pressBack();
}
}
示例8: click
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void click(String targetId) {
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject button = device.findObject(new UiSelector().resourceId(targetId));
try {
button.waitForExists(3000);
button.click();
} catch (UiObjectNotFoundException e) {
throw new IllegalStateException(e);
}
}
示例9: longClickOnArcMenuStartItem
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Tests the long clicks on the floating action button for start in the arc menu
*
* <i>A long click on the button to use to start the process should display a snackbar with an explain message</i>
*/
@Test
public void longClickOnArcMenuStartItem(){
l(this, "@Test longClickOnArcMenuStartItem");
String expectedText = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_start);
try {
/*
* Display the floating action buttons in the arc menu
*/
UiObject arcMenu = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
);
arcMenu.click();
arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
/*
* The floating action button
*/
UiObject fab = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabStart")
);
fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
assertTrue(fab.isLongClickable());
fab.swipeLeft(100); //fab.longClick() makes clicks sometimes, so swipeLeft() is a trick to make always a longclick
UiObject snack = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
);
assertEquals(expectedText, snack.getText());
} catch ( UiObjectNotFoundException uonfe ){
uonfe.printStackTrace();
fail( uonfe.getMessage() );
}
}
示例10: longClickOnArcMenuStopItem
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Tests the long clicks on the floating action button for stop in the arc menu
*
* <i>A long click on the button to use to stop the process should display a snackbar with an explain message</i>
*/
@Test
public void longClickOnArcMenuStopItem(){
l(this, "@Test longClickOnArcMenuStopItem");
String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_stop);
try {
/*
* Display the floating action buttons in the arc menu
*/
UiObject arcMenu = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
);
arcMenu.click();
arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
/*
* The floating action button
*/
UiObject fab = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabStop")
);
fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
assertTrue(fab.isLongClickable());
fab.swipeLeft(100); //fab.longClick() makes clicks sometimes, so swipeLeft() is a trick to make always a longclick
UiObject snack = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
);
assertEquals(expectedString, snack.getText());
} catch ( UiObjectNotFoundException uonfe ){
uonfe.printStackTrace();
fail( uonfe.getMessage() );
}
}
示例11: longClickOnArcMenuSuGrantItem
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Tests the long clicks on the floating action button for SU grant in the arc menu
*
* <i>A long click on the button to use to get the SU grant should display a snackbar with an explain message</i>
*/
@Test
public void longClickOnArcMenuSuGrantItem(){
l(this, "@Test longClickOnArcMenuSuGrantItem");
String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_request_su);
try {
/*
* Display the floating action buttons in the arc menu
*/
UiObject arcMenu = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction")
);
arcMenu.click();
arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
/*
* The floating action button
*/
UiObject fab = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabRequestSuGrant")
);
fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT);
assertTrue(fab.isLongClickable());
fab.swipeLeft(100); //fab.longClick() makes clicks sometimes, so swipeLeft() is a trick to make always a longclick
UiObject snack = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text")
);
assertEquals(expectedString, snack.getText());
} catch ( UiObjectNotFoundException uonfe ){
uonfe.printStackTrace();
fail( uonfe.getMessage() );
}
}
示例12: notificationOnGoing
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Tests if the notification is displayed when the standalone mode is running
*
* <i>If the standalone mode is running, a dedicated notification is displayed</i>
*/
@Test
public void notificationOnGoing(){
l(this, "@Test notificationOnGoing");
prepareNeededFiles();
// Start a standalone mode
try {
// Choose the OCR-like standalone mode (the alst of the list)
for ( int i = 1; i <= steps; i++ ){
UiObject rightArrow = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/swipeselector_layout_rightButton")
);
rightArrow.click();
}
// Click on the OK button
UiObject btOk = mDevice.findObject(
new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/btCreate")
);
btOk.click();
// Check the notification
String notificationText = InstrumentationRegistry.getTargetContext().getString(R.string.notif_content_text_clicks_on_going_standalone);
UiObject notification = null;
if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
notification = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("pylapp.smoothclicker.android")
.textContains(notificationText));
} else {
notification = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("com.android.systemui")
.textContains(notificationText));
}
mDevice.openNotification();
notification.waitForExists(2000);
w(10000);
assertTrue(notification.exists());
} catch ( UiObjectNotFoundException uonfe ){
uonfe.printStackTrace();
fail( uonfe.getMessage() );
}
}
示例13: testNotification
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Inner method to get a dedicated notification and test it
* @param textContent - The text to use to get the notification
*/
private void testNotification( String textContent ){
if ( textContent == null ) textContent = "";
UiObject n = null;
if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
n = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("pylapp.smoothclicker.android")
.textContains(textContent));
} else {
n = mDevice.findObject(
new UiSelector()
.resourceId("android:id/text")
.className("android.widget.TextView")
.packageName("com.android.systemui")
.textContains(textContent));
}
mDevice.openNotification();
n.waitForExists(2000);
assertTrue(n.exists());
}
示例14: getHotseatBounds
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
private Rect getHotseatBounds() throws Exception {
UiObject hotseat = mDevice.findObject(
new UiSelector().resourceId(mTargetPackage + ":id/hotseat"));
hotseat.waitForExists(6000);
return hotseat.getVisibleBounds();
}
示例15: DeleteWebViewDataTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void DeleteWebViewDataTest() throws InterruptedException, UiObjectNotFoundException, IOException {
// Load website with service worker
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString());
TestHelper.hint.waitForExists(waitingTime);
TestHelper.pressEnterKey();
assertTrue(TestHelper.webView.waitForExists(waitingTime));
// Assert website is loaded
final UiObject titleMsg = TestHelper.mDevice.findObject(new UiSelector()
.description("focus test page")
.enabled(true));
titleMsg.waitForExists(waitingTime);
assertTrue("Website title loaded", titleMsg.exists());
// Assert cookie is saved
final UiObject cookieMsg = TestHelper.mDevice.findObject(new UiSelector()
.description("Cookie saved")
.enabled(true));
cookieMsg.waitForExists(waitingTime);
assertTrue("Cookie is saved", cookieMsg.exists());
final UiObject serviceWorkerMsg = TestHelper.mDevice.findObject(new UiSelector()
.description("Service worker installed")
.enabled(true));
serviceWorkerMsg.waitForExists(waitingTime);
assertTrue("Service worker installed", serviceWorkerMsg.exists());
// Erase browsing session
TestHelper.floatingEraseButton.perform(click());
TestHelper.erasedMsg.waitForExists(waitingTime);
Assert.assertTrue(TestHelper.erasedMsg.exists());
Assert.assertTrue(TestHelper.inlineAutocompleteEditText.exists());
TestHelper.waitForIdle();
// Make sure all resources have been loaded from the web server
assertPathsHaveBeenRequested(webServer,
"/copper/truck/destroy?smoke=violet", // Actual URL
"/copper/truck/service-worker.js"); // Our service worker is installed
// Now let's assert that there are no surprises in the data directory
final File dataDir = new File(appContext.getApplicationInfo().dataDir);
assertTrue("App data directory should exist", dataDir.exists());
final File webViewDirectory = new File(dataDir, "app_webview");
assertTrue("WebView directory should exist", webViewDirectory.exists());
assertEquals("WebView directory contains one subdirectory", 1, webViewDirectory.list().length);
assertEquals("WebView subdirectory is local storage directory", "Local Storage", webViewDirectory.list()[0]);
assertCacheDirContentsPostErase();
for (final String name : dataDir.list()) {
if (WHITELIST_EMPTY_FOLDERS.contains(name)) {
final File folder = new File(dataDir, name);
assertTrue(" Check +'" + name + "' is empty folder", folder.isDirectory() && folder.list().length == 0);
continue;
}
assertTrue("Expected file '" + name + "' to be in the app's data dir whitelist",
WHITELIST_DATA_DIR_CONTENTS.contains(name));
}
assertNoTraces(dataDir);
}