Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI tests for Emoji Search Android frontends #1697

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ jobs:

- run: ./gradlew -p samples/emoji-search build

- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
emulator-boot-timeout: 20000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we ever really figured out why the emulator boot would timeout in SQLDelight PR checks?
Hopefully this doesn't introduce flakiness.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two other jobs that already have emulators. They don't fail that often. Maybe one out of every 30 PRs. Not great, but not terrible either.

script: ./gradlew -p samples/emoji-search connectedCheck

- name: Build Emoji Search iOS (UIKit)
run: xcodebuild -project samples/emoji-search/ios-uikit/EmojiSearchApp.xcodeproj -scheme EmojiSearchApp -destination 'platform=iOS Simulator,name=iPhone 12,OS=latest'

Expand Down
1 change: 1 addition & 0 deletions samples/counter/android-composeui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ android {
}

buildFeatures {
// Needed to pass application ID to UIAutomator tests.
buildConfig = true
}
}
1 change: 1 addition & 0 deletions samples/counter/android-views/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ android {
}

buildFeatures {
// Needed to pass application ID to UIAutomator tests.
buildConfig = true
}
}
9 changes: 9 additions & 0 deletions samples/emoji-search/android-composeui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ redwoodBuild {
android {
namespace 'com.example.redwood.emojisearch.android.composeui'

defaultConfig {
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildFeatures {
compose = true
// Needed to pass application ID to UIAutomator tests.
buildConfig = true
}
}

Expand All @@ -33,4 +39,7 @@ dependencies {
implementation projects.redwoodTreehouseHostComposeui
implementation projects.redwoodWidgetCompose
implementation libs.okio.assetfilesystem

androidTestImplementation libs.androidx.test.runner
androidTestImplementation projects.samples.emojiSearch.androidTests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* 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 com.example.redwood.emojisearch.android.composeui

import com.example.redwood.emojisearch.android.composeui.BuildConfig.APPLICATION_ID
import com.example.redwood.emojisearch.android.tests.AbstractEmojiSearchUiTest

class EmojiSearchUiTest : AbstractEmojiSearchUiTest(APPLICATION_ID)
12 changes: 12 additions & 0 deletions samples/emoji-search/android-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

dependencies {
implementation(libs.junit)
implementation(libs.androidx.test.core)
implementation(libs.androidx.test.uiautomator)
}

android {
namespace 'com.example.redwood.emojisearch.android.tests'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* 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 com.example.redwood.emojisearch.android.tests

import android.content.Context
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.By.pkg
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import org.junit.Before
import org.junit.Test

abstract class AbstractEmojiSearchUiTest(private val appPackage: String) {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!!
private val search get() = device.findObject(By.clazz("android.widget.EditText"))!!

@Before fun before() {
val context = ApplicationProvider.getApplicationContext<Context>()
val intent = context.packageManager.getLaunchIntentForPackage(appPackage)!!.apply {
addFlags(FLAG_ACTIVITY_CLEAR_TASK)
}
context.startActivity(intent)
device.wait(Until.hasObject(pkg(appPackage).depth(0)), 5_000)
}

@Test fun searchTrees() {
awaitText("0. +1")
search.text = "tree"
awaitText("301. christmas_tree")
search.clear()
awaitText("0. +1")
}

private fun awaitText(value: String, duration: Duration = 4.seconds) {
val text = device.findObject(UiSelector().text(value))
if (!text.waitForExists(duration.inWholeMilliseconds)) {
throw AssertionError("Waited $duration for \"$value\" but never appeared")
}
}
}
14 changes: 13 additions & 1 deletion samples/emoji-search/android-views/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ redwoodBuild {
}

android {
namespace "com.example.redwood.emojisearch.android.views"
namespace 'com.example.redwood.emojisearch.android.views'

defaultConfig {
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildFeatures {
// Needed to pass application ID to UIAutomator tests.
buildConfig = true
}
}

dependencies {
Expand All @@ -23,4 +32,7 @@ dependencies {
implementation projects.redwoodTreehouse
implementation projects.redwoodTreehouseHost
implementation libs.okio.assetfilesystem

androidTestImplementation libs.androidx.test.runner
androidTestImplementation projects.samples.emojiSearch.androidTests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* 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 com.example.redwood.emojisearch.android.views

import com.example.redwood.emojisearch.android.tests.AbstractEmojiSearchUiTest
import com.example.redwood.emojisearch.android.views.BuildConfig.APPLICATION_ID
import org.junit.Ignore

@Ignore("https://github.com/cashapp/redwood/issues/1696")
class EmojiSearchUiTest : AbstractEmojiSearchUiTest(APPLICATION_ID)
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ if (!hasProperty('redwoodNoApps')) {
include ':samples:counter:shared-composeui'

include ':samples:emoji-search:android-composeui'
include ':samples:emoji-search:android-tests'
include ':samples:emoji-search:android-views'
include ':samples:emoji-search:browser'
include ':samples:emoji-search:ios-shared'
Expand Down