|
| 1 | +/* |
| 2 | + * Copyright 2026 Google LLC |
| 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 com.example.wearosmap |
| 18 | + |
| 19 | +import androidx.test.core.app.ActivityScenario |
| 20 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 21 | +import androidx.test.filters.LargeTest |
| 22 | +import androidx.test.platform.app.InstrumentationRegistry |
| 23 | +import androidx.test.uiautomator.UiDevice |
| 24 | +import androidx.test.uiautomator.UiSelector |
| 25 | +import com.example.wearosmap.kt.MainActivity |
| 26 | +import com.google.common.truth.Truth.assertThat |
| 27 | +import org.junit.Test |
| 28 | +import org.junit.runner.RunWith |
| 29 | + |
| 30 | +@RunWith(AndroidJUnit4::class) |
| 31 | +@LargeTest |
| 32 | +class AppLaunchTest { |
| 33 | + |
| 34 | + @Test |
| 35 | + fun appLaunchesSuccessfully() { |
| 36 | + // Launch the activity |
| 37 | + ActivityScenario.launch(MainActivity::class.java).use { scenario -> |
| 38 | + scenario.onActivity { activity -> |
| 39 | + assertThat(activity).isNotNull() |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + fun mapContainerIsDisplayed() { |
| 46 | + // Launch the activity |
| 47 | + ActivityScenario.launch(MainActivity::class.java).use { |
| 48 | + val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) |
| 49 | + |
| 50 | + // Wait for the map container to appear |
| 51 | + val mapContainer = device.findObject(UiSelector().resourceId("com.example.wearos:id/map_container")) |
| 52 | + assertThat(mapContainer.waitForExists(5000)).isTrue() |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun markerTitleIsDisplayed() { |
| 58 | + // Launch the activity |
| 59 | + ActivityScenario.launch(MainActivity::class.java).use { |
| 60 | + val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) |
| 61 | + |
| 62 | + // Wait for the marker title "Sydney Opera House" to appear |
| 63 | + // Note: This relies on the Google Map rendering the marker and it being visible/accessible. |
| 64 | + // In a real device/emulator, this might need more robust waiting logic or accessibility settings. |
| 65 | + val markerTitle = device.findObject(UiSelector().descriptionContains("Sydney Opera House")) |
| 66 | + |
| 67 | + // Allow some time for map loading and rendering |
| 68 | + if (!markerTitle.exists()) { |
| 69 | + markerTitle.waitForExists(10000) |
| 70 | + } |
| 71 | + |
| 72 | + // Verify if found (Bonus check, might flake on some emulators if map doesn't render) |
| 73 | + // We use a softer check here or assertion if we are confident. |
| 74 | + // For now, let's assert it exists if we want to be strict, or just log if we want to be lenient. |
| 75 | + // Given the requirement "Verify Map and Marker presence (Bonus)", we'll try to assert. |
| 76 | + assertThat(markerTitle.exists()).isTrue() |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments