本文整理匯總了Java中android.support.test.uiautomator.UiObject.exists方法的典型用法代碼示例。如果您正苦於以下問題:Java UiObject.exists方法的具體用法?Java UiObject.exists怎麽用?Java UiObject.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.test.uiautomator.UiObject
的用法示例。
在下文中一共展示了UiObject.exists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的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");
}
}
示例2: testChangeText_sameActivity
import android.support.test.uiautomator.UiObject; //導入方法依賴的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();
}
}
示例3: viewExistsContains
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public static boolean viewExistsContains(UiDevice device, String... textToMatch) throws UiObjectNotFoundException
{
if (textToMatch == null || textToMatch.length < 1)
{
return false;
}
UiObject view;
boolean contains = false;
for (int i = 0; i < textToMatch.length; i++)
{
view = device.findObject(new UiSelector().textContains(textToMatch[i]));
contains = view.exists();
if (contains) return true;
}
return false;
}
示例4: allowLocationPermissionWhenAsked
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Allows location permission if the runtime permission dialog is shown.
*/
public static void allowLocationPermissionWhenAsked()
{
try
{
if (!PermissionUtils.isLocationGranted(InstrumentationRegistry.getTargetContext()))
{
TestHelper.sleep(PERMISSIONS_DIALOG_DELAY);
final UiDevice device = UiDevice.getInstance(getInstrumentation());
final UiObject allowPermissions = device.findObject(new UiSelector()
.clickable(true)
.checkable(false)
.index(GRANT_BUTTON_INDEX));
if (allowPermissions.exists())
{
allowPermissions.click();
}
}
}
catch (final UiObjectNotFoundException e)
{
Log.e(PermissionTestHelper.class.getSimpleName(), "There is no permissions dialog to interact with.");
}
}
示例5: scrollIntoView
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Override
public boolean scrollIntoView(UiObject obj) throws UiObjectNotFoundException {
if (obj.exists()) {
return true;
}
// we will need to reset the search from the beginning to start search
flingToBeginning(getMaxSearchSwipes());
if (obj.exists()) {
return true;
}
for (int x = 0; x < getMaxSearchSwipes(); x++) {
if (!scrollForward()) {
return false;
}
if (obj.exists()) {
return true;
}
}
return false;
}
示例6: autoTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void autoTest() throws UiObjectNotFoundException, IOException {
// mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// mDevice.pressHome();
// final String launcherPackage = mDevice.getLauncherPackageName();
// Runtime.getRuntime().exec("am start me.xdj.ninesquare.sample/me.xdj.ninesquare.sample.MainActivity");
UiSelector uiSelector = new UiSelector().resourceId("me.xdj.ninesquare.sample:id/image");
UiObject uiObject = mDevice.findObject(uiSelector);
if (uiObject.exists()) {
uiObject.click();
}
// SystemClock.sleep(5000);
mDevice.waitForIdle();
// uiObject.swipeLeft(1);
for (int i = 0; i < 11; i++) {
// 1步5毫秒
mDevice.swipe(900, 1000, 10, 900, 100);
// UiObject uiObject1 = mDevice.findObject(new UiSelector().resourceId("me.xdj.ninesquare.sample:id"));
// uiObject1.swipeLeft(100);
SystemClock.sleep(900);
}
mDevice.click(900, 100);
SystemClock.sleep(3000);
}
示例7: clickOnAllow
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
Roboter clickOnAllow() throws UiObjectNotFoundException {
final UiObject allowPermissions = getButton("ALLOW");
if (allowPermissions.exists()) {
allowPermissions.click();
}
return this;
}
示例8: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded() {
if (Build.VERSION.SDK_INT >= 23) {
UiObject allowPermissions = mDevice.findObject(
new UiSelector().className("android.widget.Button")
.resourceId("com.android.packageinstaller:id/permission_allow_button"));
if (allowPermissions.exists()) {
try {
allowPermissions.click();
} catch (UiObjectNotFoundException e) {
Log.e(this.getClass().getName(), "There is no permissions dialog to interact with ", e);
}
}
}
}
示例9: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded() {
if (Build.VERSION.SDK_INT >= 23) {
UiObject allowPermissions = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).findObject(
new UiSelector().className("android.widget.Button")
.resourceId("com.android.packageinstaller:id/permission_allow_button"));
if (allowPermissions.exists()) {
try {
allowPermissions.click();
} catch (UiObjectNotFoundException e) {
Log.e(this.getClass().getName(), "There is no permissions dialog to interact with ", e);
}
}
}
}
示例10: skipPermission
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public void skipPermission(JSONArray permissionPatterns, int scanningCount) {
UiDevice mDevice = Elements.getGlobal().getmDevice();
// if permission list is empty, avoid execution
if (permissionPatterns.size() == 0) {
return;
}
// regular check for permission scanning
try {
for (int i = 0; i < scanningCount; i++) {
inner:
for (int j = 0; j < permissionPatterns.size(); j++) {
String text = permissionPatterns.getString(j);
UiObject object = mDevice.findObject(new UiSelector().text(text));
if (object.exists()) {
object.click();
break inner;
}
}
Thread.sleep(3000);
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getCause().toString());
}
}
示例11: closePermissionDialog
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
private void closePermissionDialog() {
UiObject denyPermissions = device.findObject(new UiSelector().text("Deny"));
if (denyPermissions.exists()) {
try {
denyPermissions.click();
} catch (UiObjectNotFoundException e) {
}
}
}
示例12: denyPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public void denyPermissionsIfNeeded(Activity activity, String permissionNeeded) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(activity, permissionNeeded)) {
waitInMillis(PERMISSIONS_DIALOG_DELAY);
UiDevice device = UiDevice.getInstance(getInstrumentation());
UiObject denyPermissions = device.findObject(new UiSelector().clickable(true).index(DENY_BUTTON_INDEX));
if (denyPermissions.exists()) {
denyPermissions.click();
}
}
} catch (UiObjectNotFoundException e) {
logNoPermissionDialogError();
}
}
示例13: clickButton
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Clicks a button with the given text. This will try to find the widget exactly as the text is given, and
* will try upper casing the text if it is not found.
*/
public static void clickButton(UiDevice device, String buttonText) throws UiObjectNotFoundException
{
UiObject accept = device.findObject(new UiSelector().text(buttonText));
if (accept.exists())
{
accept.click();
return;
}
accept = device.findObject(new UiSelector().text(buttonText.toUpperCase()));
accept.click();
}
示例14: shouldAskForPermissionFromSnackBarButton
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void shouldAskForPermissionFromSnackBarButton() throws Exception {
if (Build.VERSION.SDK_INT >= 23) {
String snackBarButtonText = activityRule.getActivity().getResources().getString(R.string.snack_bar_button);
UiObject snackBarButton = device.findObject(new UiSelector().text(snackBarButtonText));
if (snackBarButton.exists()) {
try {
snackBarButton.click();
testIfDialogIsDisplayed();
closePermissionDialog();
} catch (UiObjectNotFoundException e) {
}
}
}
}
示例15: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public static void allowPermissionsIfNeeded(UiDevice device) {
if (Build.VERSION.SDK_INT >= 23) {
UiObject allowPermissions = device.findObject(new UiSelector().text(TEXT_ALLOW));
if (allowPermissions.exists()) {
try {
allowPermissions.click();
} catch (UiObjectNotFoundException ignored) {
}
}
}
}