Skip to content

CI enable integration test on Android Emulator #376

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

Merged
merged 28 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fb6eedd
Enable test on android emulator automatically
sunmou99 Apr 13, 2021
b25f255
Add android gameloop app
sunmou99 Apr 13, 2021
e640949
Enable test on simulator
sunmou99 Apr 13, 2021
3b102cb
change Permission
sunmou99 Apr 13, 2021
2dd62e6
add flag that notify it's in ci
sunmou99 Apr 13, 2021
2ee8867
format summary log
sunmou99 Apr 13, 2021
14af2b9
Merge branch 'feature/test-on-android-emulator' of https://github.com…
sunmou99 Apr 13, 2021
93e3a10
fix ios simulator
sunmou99 Apr 13, 2021
75d0e80
fix ios simulator
sunmou99 Apr 13, 2021
c888cef
boot emulator in background
sunmou99 Apr 13, 2021
80a56ab
Update description
sunmou99 Apr 13, 2021
d5a6f3b
format test summary
sunmou99 Apr 14, 2021
2171e5c
format PATH
sunmou99 Apr 14, 2021
645154f
Update GameLoopUITest.kt
sunmou99 Apr 14, 2021
e143493
Update test timeout to 15 minutes
sunmou99 Apr 14, 2021
06c479a
update timeout
sunmou99 Apr 14, 2021
a2fe977
update report summary
sunmou99 Apr 15, 2021
f5d030b
Update summarize_test_results.py
sunmou99 Apr 15, 2021
96d59a5
Update platform name match
sunmou99 Apr 16, 2021
d0a2a87
update based on comments
sunmou99 Apr 21, 2021
32bc10b
update based on comments
sunmou99 Apr 21, 2021
06f938e
update based on comments
sunmou99 Apr 21, 2021
da73414
update based on comments
sunmou99 Apr 21, 2021
512f746
update based on comments
sunmou99 Apr 21, 2021
95e3968
update based on comments
sunmou99 Apr 21, 2021
ae2335d
fix typo
sunmou99 Apr 21, 2021
3ac7579
add return value description & put string into res
sunmou99 Apr 21, 2021
35faf86
Disable simulator test
sunmou99 Apr 22, 2021
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
8 changes: 4 additions & 4 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ env:
statusLabelFailed: "tests: failed"
statusLabelSucceeded: "tests: succeeded"
statusCommentIdentifier: "integration-test-status-comment"
mobileTestOn: "device"
mobileTestOn: "device,simulator"

jobs:
check_trigger:
Expand Down Expand Up @@ -351,10 +351,10 @@ jobs:
if: matrix.target_platform == 'Desktop' && !cancelled()
run: |
python scripts/gha/desktop_tester.py --testapp_dir ta
- name: Run iOS integration tests on Simulator locally
if: contains(env.mobileTestOn, 'simulator') && matrix.target_platform == 'iOS' && !cancelled()
- name: Run iOS integration tests on iOS Simulator / Android Emulator locally
if: contains(env.mobileTestOn, 'simulator') && startsWith(matrix.os, 'macos') && matrix.target_platform != 'Desktop' && !cancelled()
run: |
python scripts/gha/test_simulator.py --testapp_dir ta
python scripts/gha/test_simulator.py --testapp_dir ta --ci
# Workaround for https://github.com/GoogleCloudPlatform/github-actions/issues/100
# Must be run after the Python setup action
- name: Set CLOUDSDK_PYTHON (Windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class GameLoopLauncherUITests: XCTestCase {
return timeoutSecs
} else {
// Default 5 minutes
return TimeInterval(60 * 3)
return TimeInterval(60 * 5)
}
}

Expand Down
35 changes: 35 additions & 0 deletions scripts/gha/integration_testing/gameloop_android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.compileSdk
buildToolsVersion rootProject.buildTools

defaultConfig {
applicationId "com.google.firebase.gameloop"
minSdkVersion rootProject.minSdk
targetSdkVersion rootProject.targetSdk
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.firebase.gameloop">
<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.google.firebase.gameloop

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import junit.framework.Assert.assertNotNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class GameLoopUITest {

companion object {
const val GAMELOOP_TIMEOUT = 7 * 60 * 1000L
}

private lateinit var device: UiDevice

@get:Rule
var activityRule: ActivityScenarioRule<MainActivity>
= ActivityScenarioRule(MainActivity::class.java)

@Before
fun initDevice() {
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
}

@Test
fun testLaunchGameLoop() {
val element = device.wait(
Until.findObject(By.text(getInstrumentation().targetContext.getString(R.string.test_complete))),
GAMELOOP_TIMEOUT)
assertNotNull(element)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.gameloop">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<provider
android:authorities="com.google.firebase.gameloop.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.google.firebase.gameloop

import android.content.Intent
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import java.io.File


class MainActivity : AppCompatActivity(R.layout.activity_main) {
companion object {
const val GAMELOOP_INTENT = "com.google.intent.action.TEST_LOOP"
const val TEST_LOOP_REQUEST_CODE = 1
}

private lateinit var testingTV: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
testingTV = findViewById(R.id.test)
launchGame()
}

private fun launchGame() {
val intent = Intent(GAMELOOP_INTENT, null)
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.type = "application/javascript"
val pkgAppsList: List<ResolveInfo> = packageManager.queryIntentActivities(intent, 0)
val gamePackageName = pkgAppsList[0].activityInfo.packageName

val dir = File(getExternalFilesDir(null), gamePackageName)
if (!dir.exists()) dir.mkdirs()
val filename = "Results1.json"
val file = File(dir, filename)
file.createNewFile()
Log.d("TAG", "Test Result Path :" + file)
val fileUri: Uri = FileProvider.getUriForFile(this, "com.google.firebase.gameloop.fileprovider", file)

intent.setPackage(gamePackageName)
.setDataAndType(fileUri, "application/javascript").flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION

startActivityForResult(intent, TEST_LOOP_REQUEST_CODE)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
TEST_LOOP_REQUEST_CODE -> testingTV.text = getString(R.string.test_complete)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/testing"
android:id="@+id/test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<string name="app_name">gameloop</string>
<string name="testing">Testing</string>
<string name="test_complete">Game Loop Complete</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="files"
path="/"/>
</paths>
33 changes: 33 additions & 0 deletions scripts/gha/integration_testing/gameloop_android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

ext {
compileSdk = 28
buildTools = '28.0.3'
minSdk = 16
targetSdk = 28
}

task clean(type: Delete) {
delete rootProject.buildDir
}
21 changes: 21 additions & 0 deletions scripts/gha/integration_testing/gameloop_android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Sat Apr 03 15:11:30 PDT 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Loading