android / wear-os-samples

Multiple samples showing best practices in app and watch face development on Wear OS.
https://developer.android.com/wear
Apache License 2.0
1.07k stars 557 forks source link

AlwaysOnKotlin tests fail even with older checkouts #219

Open yschimke opened 2 years ago

yschimke commented 2 years ago
java.lang.IllegalStateException: No compose views found in the app. Is your Activity resumed?
    at androidx.compose.ui.test.TestContext.getAllSemanticsNodes$ui_test_release(TestOwner.kt:96)
    at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNodes$ui_test_release(SemanticsNodeInteraction.kt:79)
    at androidx.compose.ui.test.SemanticsNodeInteraction.fetchOneOrDie(SemanticsNodeInteraction.kt:145)
    at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNode(SemanticsNodeInteraction.kt:96)

Screen shows

image

This is both at head but also back at https://github.com/android/wear-os-samples/commit/15fdaf1a05300f9e1335b1451f81d90ac9a4a5d0

cc @alexvanyo @shumelchyk

yschimke commented 2 years ago

Working fine for me locally on API 28.

yschimke commented 2 years ago

Failing differently on API 26

com.example.android.wearable.wear.alwayson.AlwaysOnAppTests > textIsCorrectAfterReturningToActiveMode[test(AVD) - 8.0.0] FAILED 
    java.lang.AssertionError: Failed to assert the following: (Text + EditableText = [Draw count: 9])
    Semantics of the node:
Tests on test(AVD) - 8.0.0 failed: There was 1 failure(s).
Feb 21, 2022 4:56:34 PM com.google.testing.platform.RunnerImpl$Companion summarizeAndLogTestResult
SEVERE: Execute com.example.android.wearable.wear.alwayson.AlwaysOnAppTests.textIsCorrectAfterReturningToActiveMode: FAILED
java.lang.AssertionError: java.lang.AssertionError: Failed to assert the following: (Text + EditableText = [Draw count: 9])
Semantics of the node:
Node #35 at (l=75.0, t=170.0, r=205.0, b=199.0)px, Tag: 'drawCount'
Text = '[Draw count: 8]'
Actions = [GetTextLayoutResult]
Has 4 siblings
Selector used: (TestTag = 'drawCount')

at androidx.compose.ui.test.AssertionsKt.assert(Assertions.kt:270)
at androidx.compose.ui.test.AssertionsKt.assert$default(Assertions.kt:260)
at androidx.compose.ui.test.AssertionsKt.assertTextEquals(Assertions.kt:190)
at androidx.compose.ui.test.AssertionsKt.assertTextEquals$default(Assertions.kt:186)
castedmo commented 2 years ago

So the issue is that the current emulator binary sets the wear emulator to be connected to a charger. This causes the charger experience to cover the whole screen whenever the display goes to ambient. The long term solution is to wait for a fix that is will be released which sets the wear emulator to not be on a charger by default. The short term solution is to disconnect the charger before the test with adb emu power ac off

yschimke commented 2 years ago

Failing with different errors - https://github.com/android/wear-os-samples/pull/221

com.example.android.wearable.wear.alwayson.MainActivityTests > textIsCorrectAfterFiveSeconds[test(AVD) - 11] FAILED 
    java.lang.AssertionError: Activity never becomes requested state "[STARTED]" (last lifecycle transition = "DESTROYED")
    at androidx.test.core.app.ActivityScenario.waitForActivityToBecomeAnyOf(ActivityScenario.java:338)

com.example.android.wearable.wear.alwayson.MainActivityTests > textIsCorrectAfterReturningToActiveMode[test(AVD) - 11] FAILED 
    androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Draw count: 9"' doesn't match the selected view.
    Expected: an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Draw count: 9"
yschimke commented 2 years ago

As @castedmo pointed out these are the View tests.

yschimke commented 2 years ago

Running locally it generally works but there are still some timing issues or behavior change in the emulator breaking the test. Also in the compose test.

It will need someone to investigate and confirm the new behavior is a bug, or update the tests to be more tolerant if it's new expected behavior.