blob: e1a6bd96b167b1c2418bacc06b226760d5dd6ef9 [file] [log] [blame]
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.tools.device.flicker.integration
import android.annotation.SuppressLint
import android.app.Instrumentation
import android.tools.TEST_SCENARIO
import android.tools.device.apphelpers.BrowserAppHelper
import android.tools.device.apphelpers.MessagingAppHelper
import android.tools.device.flicker.datastore.DataStore
import android.tools.device.flicker.legacy.FlickerBuilder
import android.tools.device.flicker.legacy.runner.TransitionRunner
import android.tools.device.traces.executeShellCommand
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.runner.Description
@SuppressLint("VisibleForTests")
object Utils {
private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
internal const val TAG = "tag"
internal const val FAILURE = "Expected failure"
internal val setupAndTearDownTestApp = BrowserAppHelper(instrumentation)
internal val transitionTestApp = MessagingAppHelper(instrumentation)
private fun createFlicker(onExecuted: () -> Unit) =
FlickerBuilder(instrumentation)
.apply {
setup {
// Shouldn't be in the trace we run assertions on
setupAndTearDownTestApp.launchViaIntent(wmHelper)
setupAndTearDownTestApp.exit(wmHelper)
}
transitions {
// Should be in the trace we run assertions on
transitionTestApp.launchViaIntent(wmHelper)
createTag(TAG)
onExecuted()
}
teardown {
// Shouldn't be in the trace we run assertions on
setupAndTearDownTestApp.launchViaIntent(wmHelper)
setupAndTearDownTestApp.exit(wmHelper)
}
}
.build()
fun runTransition(onExecuted: () -> Unit) {
DataStore.clear()
val flicker = createFlicker(onExecuted)
// Clear the trace output directory
executeShellCommand("rm -rf ${flicker.outputDir}")
val runner = TransitionRunner(TEST_SCENARIO, instrumentation)
runner.execute(flicker, Description.createTestDescription(this::class.java, "test"))
}
}