1 /* 2 * Copyright (C) 2022 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 android.nearby.integration.ui 18 19 import android.platform.test.rule.ScreenRecordRule.ScreenRecord 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.platform.app.InstrumentationRegistry 22 import androidx.test.uiautomator.UiDevice 23 import androidx.test.uiautomator.Until 24 import org.junit.AfterClass 25 import org.junit.Before 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 29 /** An instrumented test to start pairing by interacting with Nearby half sheet UI. 30 * 31 * To run this test directly: 32 * am instrument -w -r \ 33 * -e class android.nearby.integration.ui.PairByNearbyHalfSheetUiTest \ 34 * android.nearby.integration.ui/androidx.test.runner.AndroidJUnitRunner 35 */ 36 @RunWith(AndroidJUnit4::class) 37 class PairByNearbyHalfSheetUiTest : BaseUiTest() { 38 init { 39 device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) 40 } 41 42 @Before setUpnull43 fun setUp() { 44 CheckNearbyHalfSheetUiTest().apply { 45 setUp() 46 checkNearbyHalfSheetUi() 47 } 48 } 49 50 @Test 51 @ScreenRecord clickConnectButtonnull52 fun clickConnectButton() { 53 val connectButton = NearbyHalfSheetUiMap.DevicePairingFragment.connectButton 54 device.findObject(connectButton).click() 55 device.wait(Until.gone(connectButton), CONNECT_BUTTON_TIMEOUT_MILLS) 56 } 57 58 companion object { 59 private const val CONNECT_BUTTON_TIMEOUT_MILLS = 3000L 60 private lateinit var device: UiDevice 61 62 @AfterClass 63 @JvmStatic teardownClassnull64 fun teardownClass() { 65 // Cleans up after saving screenshot in TestWatcher, leaves nothing dirty behind. 66 device.pressBack() 67 DismissNearbyHalfSheetUiTest().dismissHalfSheet() 68 } 69 } 70 }