-
Notifications
You must be signed in to change notification settings - Fork 533
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 #3315: Set up UIAutomator with Bazel #3505
Conversation
… setup-uiautomator � Conflicts: � third_party/maven_install.json
BUILD.bazel
Outdated
@@ -59,6 +59,7 @@ android_binary( | |||
"versionName": "0.1-alpha", | |||
}, | |||
multidex = "native", # TODO(#1875): Re-enable legacy for optimized release builds. | |||
visibility = ["//visibility:public"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what package_group I need to use here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ought to create another binary specifically for tests, set that visibility to oppia_testing_visibility & set is as testonly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
import org.junit.Test | ||
|
||
/** Tests to load Oppia using UI Automator. */ | ||
class BaseTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test suite is basically to check if the UI Automator is working fine or not
and to check if the app is loading as expected.
I'm navigating to the ProfileDashboard especially to verify if the we don't face similar errors we faced when using android_instrumentation_test target
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using other test cases as the only purpose was to be able to run the end to end tests.
Other test cases may be used in future work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test suites should be specific to the things they are testing. In this case, I'd expect something like ExplorationPlayerTest. Please split this up/update it as needed to be specific to the sets of tests it will contain, and then update the packages & Bazel structure accordingly.
I think I also have feedback on how to change the Bazel structure, but it's hard for me to see the difference between which pieces a test-specific vs. generic. After this is addressed I should be able to give more specific feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
instrumentation/src/javatest/org/oppia/android/instrumentation/BaseTest.kt
Outdated
Show resolved
Hide resolved
@Test | ||
fun baseTest_openProfileDashboard_titleExists() { | ||
val skip_button = device.findObject(By.res("$OPPIA_PACKAGE:id/skip_text_view")) | ||
skip_button?.let { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null check, incase the app OnBoarding was already used once.
third_party/versions.bzl
Outdated
"androidx.test.ext:junit": "1.1.3", | ||
"androidx.test:core": "1.4.0", | ||
"androidx.test:runner": "1.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BenHenning I've updated these version when we were trying the previous implementation.
Shall I revert them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean toward not upgrading versions unless specifically needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** Tests to load Oppia using UI Automator. */ | ||
class BaseTest { | ||
private val OPPIA_PACKAGE = "org.oppia.android" | ||
private val LAUNCH_TIMEOUT = 5000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I choose 5 seconds as per the Ui Automator examples I've referred to,
Tried using 1 sec and 2 secs both fail, 3 sec seems to be working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also use 30 seconds. Generally, we see 10, 30, and 60 second timeouts, or 5 minutes as the longest possible (since Bazel will fail the test at that point) depending on the context. 30 seems more fitting here since there are a lot of things we may need to wait for on the emulator or device side for the test to actually start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I've also added a seperate timeout (TRANSITION_TIMEOUT) of 5 seconds to wait for the navigation between the activities, I used 5 seconds as minimum expecting that for the failure case the 30sec timeout would be very large for the activites.
@FareesHussain given your comments, is this PR in a state ready to be in full review or should it be in draft? Also, I probably won't be able to look at this for another day--sorry about that. |
It is ready for review, I've added the comments just to explain some parts of the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @FareesHussain. Took a very high-level pass & left some comments--PTAL.
BUILD.bazel
Outdated
@@ -59,6 +59,7 @@ android_binary( | |||
"versionName": "0.1-alpha", | |||
}, | |||
multidex = "native", # TODO(#1875): Re-enable legacy for optimized release builds. | |||
visibility = ["//visibility:public"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ought to create another binary specifically for tests, set that visibility to oppia_testing_visibility & set is as testonly.
import org.junit.Test | ||
|
||
/** Tests to load Oppia using UI Automator. */ | ||
class BaseTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test suites should be specific to the things they are testing. In this case, I'd expect something like ExplorationPlayerTest. Please split this up/update it as needed to be specific to the sets of tests it will contain, and then update the packages & Bazel structure accordingly.
I think I also have feedback on how to change the Bazel structure, but it's hard for me to see the difference between which pieces a test-specific vs. generic. After this is addressed I should be able to give more specific feedback.
/** Tests to load Oppia using UI Automator. */ | ||
class BaseTest { | ||
private val OPPIA_PACKAGE = "org.oppia.android" | ||
private val LAUNCH_TIMEOUT = 5000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also use 30 seconds. Generally, we see 10, 30, and 60 second timeouts, or 5 minutes as the longest possible (since Bazel will fail the test at that point) depending on the context. 30 seems more fitting here since there are a lot of things we may need to wait for on the emulator or device side for the test to actually start.
third_party/versions.bzl
Outdated
"androidx.test.ext:junit": "1.1.3", | ||
"androidx.test:core": "1.4.0", | ||
"androidx.test:runner": "1.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean toward not upgrading versions unless specifically needed.
…oppia-android; branch 'develop' of https://github.com/oppia/oppia-android into setup-uiautomator
@FareesHussain Let's review it tomorrow while our meeting. |
Tried
None of them seems to work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FareesHussain what specifically didn't work in each case?
scripts/src/javatests/org/oppia/android/scripts/ci/ComputeAffectedTestsTest.kt
Outdated
Show resolved
Hide resolved
I did mention this in the mail. executeShellCommand("pm clear $OPPIA_PACKAGE") https://gist.github.com/FareesHussain/b7ea9d5a8fdafe41f0dcc7536cd0111b clearApplicationData() from the application context also had the same error deleting the cacheDir doesn't have any change (I don't think it would reset the app as clearing application storage and deleting cache is a bit different), This doesn't crash the tests but also doesn't reset the app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @FareesHussain. One follow-up. I think the main thing left is ensuring data is properly reset between tests before this PR can be considered ready to merge (from my perspective).
scripts/src/javatests/org/oppia/android/scripts/ci/ComputeAffectedTestsTest.kt
Outdated
Show resolved
Hide resolved
running tests on fresh install / after clearing the application data, doesn't save the application data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything LGTM,
Need to follow up with Ben's comment about clearing app data in every test case.
comment - #3505 (comment)
Unassigning @anandwana001 since they have already approved the PR. |
… setup-uiautomator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @FareesHussain. Left one follow-up comment with a suggestion to unblock this PR so that we can get it merged. PTAL.
instrumentation/src/javatest/org/oppia/android/instrumentation/player/ExplorationPlayerTest.kt
Outdated
Show resolved
Hide resolved
scripts/src/javatests/org/oppia/android/scripts/ci/ComputeAffectedTestsTest.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since everything else looks good here, approving. Thanks @FareesHussain!
instrumentation/src/javatest/org/oppia/android/instrumentation/player/ExplorationPlayerTest.kt
Outdated
Show resolved
Hide resolved
Since there are no other open reviewer threads, merging this. |
Explanation
Fixes #3315
This pr introduces UI Automator with a BaseTest generated using Bazel
How to run UI Automator tests
Prerequisites:
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
Steps to run the tests:
2.1.Exploration.Player.Test.take.1.mp4
Checklist