1 /* 2 * Copyright (C) 2023 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.tools.integration 18 19 import android.annotation.SuppressLint 20 import android.app.Instrumentation 21 import android.tools.device.apphelpers.BrowserAppHelper 22 import android.tools.device.apphelpers.MessagingAppHelper 23 import android.tools.flicker.legacy.FlickerBuilder 24 import android.tools.flicker.legacy.runner.TransitionRunner 25 import android.tools.testutils.TEST_SCENARIO 26 import androidx.test.platform.app.InstrumentationRegistry 27 import org.junit.runner.Description 28 29 @SuppressLint("VisibleForTests") 30 object TestUtils { 31 private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() 32 internal const val TAG = "tag" 33 internal const val FAILURE = "Expected failure" 34 internal val setupAndTearDownTestApp = BrowserAppHelper(instrumentation) 35 internal val transitionTestApp = MessagingAppHelper(instrumentation) 36 createFlickernull37 private fun createFlicker(onExecuted: () -> Unit) = 38 FlickerBuilder(instrumentation) 39 .apply { 40 setup { 41 // Shouldn't be in the trace we run assertions on 42 setupAndTearDownTestApp.launchViaIntent(wmHelper) 43 setupAndTearDownTestApp.exit(wmHelper) 44 } 45 transitions { 46 // Should be in the trace we run assertions on 47 transitionTestApp.launchViaIntent(wmHelper) 48 createTag(TAG) 49 onExecuted() 50 } 51 teardown { 52 // Shouldn't be in the trace we run assertions on 53 setupAndTearDownTestApp.launchViaIntent(wmHelper) 54 setupAndTearDownTestApp.exit(wmHelper) 55 } 56 } 57 .build() 58 runTransitionnull59 fun runTransition(onExecuted: () -> Unit) { 60 android.tools.flicker.datastore.DataStore.clear() 61 val flicker = createFlicker(onExecuted) 62 63 val runner = TransitionRunner(TEST_SCENARIO, instrumentation) 64 runner.execute(flicker, Description.createTestDescription(this::class.java, "test")) 65 } 66 } 67