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

Fix #3607: ExplorationPlayer End to End tests #3608

Merged
merged 72 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
b720222
Introducing UiAutomator
FareesHussain Jul 15, 2021
f90cbfc
Using 23 api level
FareesHussain Jul 15, 2021
930abe0
some local tweaks
FareesHussain Jul 16, 2021
bb6f5bb
Updated implementation based on adb commands
FareesHussain Jul 20, 2021
46a1b56
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jul 20, 2021
44f4003
Nit fixes
FareesHussain Jul 20, 2021
72620a2
Nit fixes
FareesHussain Jul 20, 2021
7a384c3
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Jul 22, 2021
8a641d7
Requested changes
FareesHussain Jul 22, 2021
c58b6f6
fix class name
FareesHussain Jul 22, 2021
09c419e
update dependencies
FareesHussain Jul 22, 2021
004e3a1
Nit fixes
FareesHussain Jul 24, 2021
7124642
Initial e2e tests
FareesHussain Jul 29, 2021
7a1221d
Requested changes
FareesHussain Jul 30, 2021
0aec4a5
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jul 30, 2021
6e09966
updated maven_install
FareesHussain Jul 30, 2021
8ca2bb9
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Jul 30, 2021
4486882
Nit fix
FareesHussain Jul 30, 2021
f64d32c
Add CODEOWNERS
FareesHussain Jul 30, 2021
dc66ba2
Added KDoc
FareesHussain Jul 30, 2021
c233b71
NIT
FareesHussain Jul 30, 2021
2044979
Added comments
FareesHussain Jul 30, 2021
7ac1ac5
Added oppia_instrumentation_test.bzl
FareesHussain Jul 31, 2021
3bb5348
added exempted_file_path
FareesHussain Jul 31, 2021
1c818dd
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Jul 31, 2021
2e0440e
e2e tests for both explorations
FareesHussain Jul 31, 2021
e5a6128
Helper utility shifted to testing module
FareesHussain Aug 4, 2021
425ebfa
NIT
FareesHussain Aug 4, 2021
067537f
NIT
FareesHussain Aug 4, 2021
b9233c6
deleted the previous utility
FareesHussain Aug 4, 2021
37b10e2
ignoring instrumentation in ComputeAffectedTests.kt
FareesHussain Aug 5, 2021
3c1e79f
NIT
FareesHussain Aug 5, 2021
44363c1
NIT
FareesHussain Aug 5, 2021
e95d29f
NIT
FareesHussain Aug 6, 2021
c608f7c
changed startsWith("instrumentation/")
FareesHussain Aug 6, 2021
66f6b51
filtered bazel targets
FareesHussain Aug 6, 2021
6514ba9
NIT
FareesHussain Aug 6, 2021
e81706b
NIT
FareesHussain Aug 6, 2021
a4266e4
filtering the instrumentation from the total affected targets
FareesHussain Aug 6, 2021
6f2836c
NIT
FareesHussain Aug 6, 2021
870d0a2
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Aug 9, 2021
3660243
changed directory to javatests
FareesHussain Aug 10, 2021
d4aa4d4
NIT
FareesHussain Aug 10, 2021
41ea23f
NIT
FareesHussain Aug 10, 2021
b15451b
fixed scripts
FareesHussain Aug 11, 2021
73c650e
NIT
FareesHussain Aug 11, 2021
0d50914
updated the ComputedAffectedTests
FareesHussain Aug 13, 2021
e2db957
ignoring player directory
FareesHussain Aug 13, 2021
f8f3ca9
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Aug 14, 2021
16b51e5
Updated with new changes
FareesHussain Aug 15, 2021
02af57a
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 16, 2021
e39903f
updated tests
FareesHussain Aug 17, 2021
838c713
updated tests
FareesHussain Aug 17, 2021
08ffe75
fix OppiaTestApplication
FareesHussain Aug 17, 2021
e2ba215
added todo
FareesHussain Aug 17, 2021
989342e
fixed clearAppData to delete all the .cache file of the app
FareesHussain Aug 17, 2021
5610651
NIT
FareesHussain Aug 17, 2021
3f9e2c7
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 18, 2021
75c60cd
removed clearAppData
FareesHussain Aug 18, 2021
a37bcbb
updated ComputeAffectedTestsTest
FareesHussain Aug 18, 2021
33c4189
updated ComputeAffectedTestsTest
FareesHussain Aug 18, 2021
d40cd4b
reverted ComputeAffectedTestsTest.kt
FareesHussain Aug 19, 2021
55bc4d9
requested changes
FareesHussain Aug 19, 2021
58caec1
Using !!.
FareesHussain Aug 19, 2021
8d16408
NIT
FareesHussain Aug 19, 2021
c7bd1dd
fixed tests
FareesHussain Aug 19, 2021
f01a655
reverted chapter_completed_tick content desc
FareesHussain Aug 19, 2021
4811a07
Updated content description for ImageRegionSelectionInteraction
FareesHussain Aug 19, 2021
b9e9fbe
testing ImageRegionSelectionInteractionView
FareesHussain Aug 19, 2021
196f8db
updated test
FareesHussain Aug 20, 2021
bf1e0eb
remoced ignore
FareesHussain Aug 20, 2021
63ed680
Removed content description and Added checkNotNull
FareesHussain Aug 20, 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: 8 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ NOTICE @BenHenning
# Global model ownership.
/model/ @vinitamurthi @BenHenning


#####################################################################################
# instrumentation #
#####################################################################################

# End-to-end test utilities and modules.
/instrumentation/src/java/**/*.kt @anandwana001 @BenHenning

#####################################################################################
# global overrides #
#####################################################################################
Expand Down
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package_group(
"//app/...",
"//data/...",
"//domain/...",
"//instrumentation/...",
"//testing/...",
"//utility/...",
],
Expand Down
15 changes: 15 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ http_archive(

load("@rules_jvm_external//:defs.bzl", "maven_install")

ATS_TAG = "1edfdab3134a7f01b37afabd3eebfd2c5bb05151"

ATS_SHA256 = "dcd1ff76aef1a26329d77863972780c8fe1fc8ff625747342239f0489c2837ec"

http_archive(
name = "android_test_support",
sha256 = ATS_SHA256,
strip_prefix = "android-test-%s" % ATS_TAG,
urls = ["https://github.com/android/android-test/archive/%s.tar.gz" % ATS_TAG],
)

load("@android_test_support//:repo.bzl", "android_test_repositories")

android_test_repositories()

# Note to developers: new dependencies should be added to //third_party:versions.bzl, not here.
maven_install(
artifacts = DAGGER_ARTIFACTS + get_maven_dependencies(),
Expand Down
30 changes: 30 additions & 0 deletions instrumentation/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
This library contains all android_binary and android_instrumentation_test targets to each
test suite in instrumentation module as a oppia_instrumentation_test wrapper.
Note that:
- All the oppia_instrumentation_test targets are named similar to the respective class name
of the test suite.
"""

exports_files(["src/javatests/AndroidManifest.xml"])

# Used for end-to-end tests
android_binary(
name = "oppia_test",
testonly = True,
custom_package = "org.oppia.android",
enable_data_binding = True,
manifest = "//app:src/main/AndroidManifest.xml",
manifest_values = {
"applicationId": "org.oppia.android",
"minSdkVersion": "19",
"targetSdkVersion": "29",
"versionCode": "0",
"versionName": "0.1-test",
},
multidex = "native",
visibility = ["//:oppia_testing_visibility"],
deps = [
"//app",
],
)
40 changes: 40 additions & 0 deletions instrumentation/oppia_instrumentation_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Instrumentation macros to define up end-to-end tests.
"""

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

def oppia_instrumentation_test(
name,
srcs,
deps):
"""
Creates library, binary, and instrumentation test for each test suite.

Args:
name: str. The class name of the test suite.
srcs: list of str. List of test files corresponding to this test suite.
deps: list of str. The list of dependencies needed to build and run the test.
"""
kt_android_library(
name = "%s_lib" % name,
testonly = True,
srcs = srcs,
deps = deps,
)

native.android_binary(
name = "%sBinary" % name,
testonly = True,
custom_package = "org.oppia.android",
instruments = "//instrumentation:oppia_test",
manifest = "//instrumentation:src/javatests/AndroidManifest.xml",
deps = [":%s_lib" % name],
)

# TODO(#3617): Target isn't supported yet.
native.android_instrumentation_test(
name = name,
target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_23_x86_qemu2",
test_app = ":%sBinary" % name,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
This library contains the utilities used in end-to-end testing.
"""

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
name = "e2e_test_helper",
testonly = True,
srcs = [
"EndToEndTestHelper.kt",
],
visibility = ["//:oppia_testing_visibility"],
deps = [
"//third_party:androidx_test_ext_junit",
"//third_party:androidx_test_uiautomator_uiautomator",
"//third_party:com_google_truth_truth",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.oppia.android.instrumentation.testing

import android.content.Context
import android.content.Intent
import androidx.test.core.app.ApplicationProvider
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import com.google.common.truth.Truth.assertThat

/** This object contains common operations used for end-to-end tests. */
object EndToEndTestHelper {

private val OPPIA_PACKAGE = "org.oppia.android"
private val LAUNCH_TIMEOUT_SECONDS = 30000L
private val TRANSITION_TIMEOUT_SECONDS = 5000L

/** Starts Oppia from the home screen. */
fun UiDevice.startOppiaFromScratch() {
// Start from the home screen
pressHome()

// Wait for launcher
val launcherPackage = launcherPackageName
assertThat(launcherPackage).isNotNull()
wait(Until.hasObject(By.pkg(launcherPackage).depth(1)), LAUNCH_TIMEOUT_SECONDS)

// Launch the blueprint app
val context = ApplicationProvider.getApplicationContext<Context>()
val intent = context.packageManager
.getLaunchIntentForPackage(OPPIA_PACKAGE)
intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) // Clear out any previous instances
context.startActivity(intent)

// Wait for the app to appear
wait(Until.hasObject(By.pkg(OPPIA_PACKAGE)), LAUNCH_TIMEOUT_SECONDS)
}

/** Waits for the view with given resourceId to appear. */
fun UiDevice.waitForRes(resourceId: String, timeout: Long = TRANSITION_TIMEOUT_SECONDS) {
wait(Until.hasObject(By.res(resourceId)), timeout)
}

/** Waits for the view with given text to appear. */
fun UiDevice.waitForText(text: String) {
wait(Until.hasObject(By.text(text)), TRANSITION_TIMEOUT_SECONDS)
}

/** Waits for the view with given content description to appear. */
fun UiDevice.waitForDesc(text: String) {
wait(Until.hasObject(By.desc(text)), TRANSITION_TIMEOUT_SECONDS)
}

/** Return the UiObject with the given text. */
fun UiDevice.findObjectByText(text: String): UiObject2? {
waitForText(text)
return findObject(By.text(text))
}

/** Returns the UiObject for the given resourceId. */
fun UiDevice.findObjectByRes(resourceId: String): UiObject2? {
waitForRes(resourceId)
return findObject(By.res("$OPPIA_PACKAGE:id/$resourceId"))
}

/** Returns the UiObject for the given content description. */
fun UiDevice.findObjectByDesc(text: String): UiObject2? {
waitForDesc(text)
return findObject(By.desc(text))
}

/** Performs a scroll until the view with the give text is visible. */
fun scrollRecyclerViewTextIntoView(text: String, isVertical: Boolean = true) {
val recyclerView = UiScrollable(UiSelector().scrollable(true))
if (isVertical) {
recyclerView.setAsVerticalList()
} else {
recyclerView.setAsHorizontalList()
}
recyclerView.scrollTextIntoView(text)
}
}
11 changes: 11 additions & 0 deletions instrumentation/src/javatests/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xmxl version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.oppia.android.app.instrumentation">
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="29" />
<instrumentation
android:targetPackage="org.oppia.android"
android:name="androidx.test.runner.AndroidJUnitRunner" />
<application android:label="OppiaTest" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
This library contains the test suite source files of the player package.
"""

load("//instrumentation:oppia_instrumentation_test.bzl", "oppia_instrumentation_test")

oppia_instrumentation_test(
name = "ExplorationPlayerTest",
srcs = [
"ExplorationPlayerTest.kt",
],
deps = [
"//instrumentation/src/java/org/oppia/android/instrumentation/testing:e2e_test_helper",
"//third_party:androidx_test_ext_junit",
"//third_party:androidx_test_runner",
"//third_party:androidx_test_uiautomator_uiautomator",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
],
)
Loading