1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.providers.media.photopicker.ui.testapp; 18 19 import static com.google.common.truth.Truth.assertWithMessage; 20 21 import android.content.Intent; 22 import android.text.format.DateUtils; 23 24 import androidx.annotation.NonNull; 25 import androidx.test.uiautomator.UiDevice; 26 import androidx.test.uiautomator.UiSelector; 27 28 public class TestActivityUtils { 29 private static final String ACTION_LAUNCH_TEST_ACTIVITY = 30 "com.android.providers.media.photopicker.tests.LAUNCH_TEST"; 31 public static final Intent TEST_ACTIVITY_INTENT = new Intent(ACTION_LAUNCH_TEST_ACTIVITY); 32 33 private static final long TIMEOUT = 30 * DateUtils.SECOND_IN_MILLIS; 34 35 /** 36 * Verify if the {@link TestActivity} is launched and visible. 37 */ assertThatTestActivityIsVisible( @onNull UiDevice uiDevice, @NonNull String targetPackageName)38 public static void assertThatTestActivityIsVisible( 39 @NonNull UiDevice uiDevice, @NonNull String targetPackageName) { 40 assertWithMessage("Timed out waiting for the test activity to appear") 41 .that(uiDevice.findObject(new UiSelector().resourceId( 42 targetPackageName + ":id/test_app_text")).waitForExists(TIMEOUT)) 43 .isTrue(); 44 } 45 } 46