Skip to content

Instantly share code, notes, and snippets.

View JoseAlcerreca's full-sized avatar

Jose Alcérreca JoseAlcerreca

View GitHub Profile
/* Copyright 2024 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply {
executeShellCommand(
"cmd overlay enable-exclusive " +
"com.android.internal.systemui.navbar.gestural", // or .threebutton
)
}
plugins {
...
jacoco
}
android {
applicationVariants.all(closureOf<com.android.build.gradle.api.ApplicationVariant> {
val myObjFactory = project.objects
val buildDir = layout.buildDirectory.get().asFile
/*
* Copyright 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
fun waitUntilAtLeastOneExists(matcher: SemanticsMatcher, timeout: Long = 1000L)
fun waitUntilDoesNotExist(matcher: SemanticsMatcher, timeout: Long = 1000L)
fun waitUntilExactlyOneExists(matcher: SemanticsMatcher, timeout: Long = 1000L)
fun waitUntilNodeCount(matcher: SemanticsMatcher, count: Int, timeout: Long = 1000L)
@JoseAlcerreca
JoseAlcerreca / customizer.sh
Created June 17, 2022 14:59
Renames a whole template and data model
#!/bin/bash
#
# Copyright (C) 2022 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
#
@Test
fun loginScreen_onContinueClick_welcomeDisplayed() {
composeTestRule.onNodeWithText("Continue¨).performClick()
composeTestRule.waitUntilDoesNotExist(hasText("Loading"))
composeTestRule.onNodeWithText("Welcome").assertExists()
}
@Test
fun loginScreen_onContinueClick_welcomeDisplayed() {
composeTestRule.onNodeWithText("Continue¨).performClick()
// Screen still shows "Loading"
composeTestRule.onNodeWithText("Welcome").assertExists() // FAILS!
}
class MyViewModel(repository…) {
val data = flow{
...
emitAll(repository.observeData())
}
}
@Composable
fun MyScreen(val viewModel: MyViewModel = viewModel()) {
val data by viewModel.data.collectAsState("Loading")
Text(greeting)
}
composeTestRule.waitUntilExactlyOneExists(hasText("Continue"))