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

Unit test and E2E test updated #84

Merged
merged 7 commits into from
Oct 9, 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
7 changes: 6 additions & 1 deletion .github/workflows/test-android-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Run E2E Tests for Android
on:
workflow_dispatch:
pull_request:
branches: [ main ]
jobs:
test-android:
name: Test Android
Expand Down Expand Up @@ -45,9 +47,12 @@ jobs:
disable-animations: true
profile: Nexus 6
script: |
adb emu geo fix 72.58727 23.02579
adb emu geo fix 72.5228 23.0127
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.DefaultConnectionFlowSuite
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.DefaultConnectionFlowSuite2
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.main.SimulationStartTrackingHistoryLoggedTest
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.main.SimulationStopTrackingHistoryLoggedTest
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.DefaultConnectionFlowSuite3
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.AWSConnectionSuite
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.AWSSignInSuite
./gradlew app:connectedDebugAndroidTest -i -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.main.TrackingStartTrackingTest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:

- name: Run Unit Tests
run: |
./gradlew testDebugUnitTest
./gradlew testDebugUnitTestCoverage
- name: Upload test results
uses: actions/upload-artifact@v2
if: always()
with:
name: test-results
path: app/build/reports/androidTests/connected/
path: app/build/reports/jacoco/testDebugUnitTestCoverage/html/
retention-days: 1
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ Note:

./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.DefaultConnectionFlowSuite
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.DefaultConnectionFlowSuite2
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.main.SimulationStartTrackingHistoryLoggedTest
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.main.SimulationStopTrackingHistoryLoggedTest
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.DefaultConnectionFlowSuite3
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.AWSConnectionSuite
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.AWSSignInSuite
./gradlew app:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aws.amazonlocation.ui.main.TrackingStartTrackingTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,9 @@ abstract class BaseTestMainActivity {

private val defaultPermissions = arrayOf(
ACCESS_FINE_LOCATION,
ACCESS_COARSE_LOCATION,
WRITE_EXTERNAL_STORAGE,
ACCESS_COARSE_LOCATION
)

private val permission: Array<String>
get() {
return enablePermissions().let {
if (it.isEmpty()) {
arrayOf(WRITE_EXTERNAL_STORAGE)
} else {
it.contains(WRITE_EXTERNAL_STORAGE).let { hasWritePermission ->
if (hasWritePermission) {
it
} else {
it + WRITE_EXTERNAL_STORAGE
}
}
}
}
}

private val instance: BaseTestMainActivity
get() {
return getClassInstance()
Expand All @@ -50,11 +32,6 @@ abstract class BaseTestMainActivity {
@get:Rule(order = 0)
var hiltRule = HiltAndroidRule(instance)

@get:Rule(order = 1)
var permissionRule: GrantPermissionRule = GrantPermissionRule.grant(
*permission,
)

@JvmField
@Rule(order = 2)
val ruleChain: RuleChain = RuleChain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.aws.amazonlocation.ui.main.CheckRouteMapAdjustedTest
import com.aws.amazonlocation.ui.main.CheckRouteOptionsTest
import com.aws.amazonlocation.ui.main.CheckRouteUserEnterMyLocationTest
import com.aws.amazonlocation.ui.main.ExploreFragmentChangeStyleTest
import com.aws.amazonlocation.ui.main.ExploreFragmentGrabChangeStyleTest
import com.aws.amazonlocation.ui.main.ExploreFragmentMapStyleSearchFilterTest
import com.aws.amazonlocation.ui.main.ExploreFragmentSearchResultTest
import com.aws.amazonlocation.ui.main.ExploreFragmentSearchTotalResultTest
Expand Down Expand Up @@ -43,7 +42,6 @@ import org.junit.runners.Suite
SettingsFragmentChangeDataProviderTest::class,
SettingsFragmentContentTest::class,
SettingsFragmentDefaultRouteTest::class,
ExploreFragmentGrabChangeStyleTest::class,
ExploreFragmentChangeStyleTest::class,
ExploreFragmentMapStyleSearchFilterTest::class,
SettingsMapStyleSearchFilterTest::class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aws.amazonlocation.ui

import com.aws.amazonlocation.ui.main.CheckGrabGoButtonTest
import com.aws.amazonlocation.ui.main.ExploreFragmentGrabChangeStyleTest
import com.aws.amazonlocation.ui.main.SettingsFragmentChangeLanguageTest
import com.aws.amazonlocation.ui.main.SettingsFragmentChangeRegionTest
import org.junit.runner.RunWith
import org.junit.runners.Suite

@RunWith(Suite::class)
@Suite.SuiteClasses(
SettingsFragmentChangeRegionTest::class,
SettingsFragmentChangeLanguageTest::class,
ExploreFragmentGrabChangeStyleTest::class,
CheckGrabGoButtonTest::class
)
class DefaultConnectionFlowSuite3
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ class AnalyticsTest : BaseTestMainActivity() {
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/edt_search_places")),
DELAY_5000
)
// Start - Search event check
val edtSearch =
onView(withId(R.id.edt_search_places)).check(ViewAssertions.matches(isDisplayed()))
edtSearch.perform(click())
onView(withId(R.id.edt_search_places)).perform(ViewActions.replaceText(TEST_ADDRESS))
var snackBarMsg = uiDevice.wait(Until.hasObject(By.text(EventType.PLACE_SEARCH)), DELAY_10000)
Assert.assertTrue(TEST_FAILED_NO_MESSAGE_FOUND, snackBarMsg)
edtSearch.perform(ViewActions.closeSoftKeyboard())
val clSearchSheet =
mActivityRule.activity.findViewById<ConstraintLayout>(R.id.bottom_sheet_search)
val mBottomSheetSearchPlaces: BottomSheetBehavior<ConstraintLayout> =
BottomSheetBehavior.from(clSearchSheet)
mBottomSheetSearchPlaces.state = BottomSheetBehavior.STATE_COLLAPSED
uiDevice.wait(Until.hasObject(By.text(mActivityRule.activity.getString(R.string.menu_explore))), DELAY_5000)
// End - Search event check
Thread.sleep(DELAY_1000)
// Start - Screen change event test
val settingTabText = mActivityRule.activity.getString(R.string.menu_setting)
onView(
Expand All @@ -96,16 +80,14 @@ class AnalyticsTest : BaseTestMainActivity() {
isDisplayed()
)
).perform(click())
snackBarMsg = uiDevice.wait(Until.hasObject(By.text(EventType.SCREEN_OPEN)), DELAY_10000)
Assert.assertTrue(TEST_FAILED_NO_MESSAGE_FOUND, snackBarMsg)
// End - Screen change event test
goToDataProvider()
Thread.sleep(DELAY_2000)
// Start - Map provider change event test
onView(
allOf(withId(R.id.ll_here), isDisplayed())
).perform(click())
snackBarMsg = uiDevice.wait(Until.hasObject(By.text(EventType.MAP_PROVIDER_CHANGE)), DELAY_10000)
var snackBarMsg = uiDevice.wait(Until.hasObject(By.text(EventType.MAP_PROVIDER_CHANGE)), DELAY_10000)
Assert.assertTrue(TEST_FAILED_NO_MESSAGE_FOUND, snackBarMsg)
// End - Map provider change event test
onView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,97 +138,6 @@ class CheckRouteEstimatedTimeAndDistanceTest : BaseTestMainActivity() {
tvWalkDistance.text.toString().isNotEmpty() && tvWalkMinute.text.toString().isNotEmpty() &&
tvTruckDistance.text.toString().isNotEmpty() && tvTruckMinute.text.toString().isNotEmpty(),
)

// val cardDirection =
// mActivityRule.activity.findViewById<MaterialCardView>(R.id.card_direction)
// if (cardDirection.visibility == View.VISIBLE) {
// val cardDirectionTest =
// onView(withId(R.id.card_direction)).check(matches(isDisplayed()))
// cardDirectionTest.perform(click())
// uiDevice.wait(
// Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/edt_search_direction")),
// DELAY_5000,
// )
// val edtSearchDirection =
// mActivityRule.activity.findViewById<TextInputEditText>(R.id.edt_search_direction)
// if (edtSearchDirection.visibility == View.VISIBLE) {
// onView(withId(R.id.edt_search_direction)).perform(ViewActions.typeText(TEST_WORD_9))
// Thread.sleep(DELAY_2000)
// uiDevice.wait(
// Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/rv_search_places_suggestion_direction")),
// DELAY_20000,
// )
// val rvSearchPlacesSuggestionDirection =
// mActivityRule.activity.findViewById<RecyclerView>(R.id.rv_search_places_suggestion_direction)
// rvSearchPlacesSuggestionDirection.adapter?.itemCount?.let {
// if (it > 0) {
// onView(withId(R.id.rv_search_places_suggestion_direction)).perform(
// RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
// 0,
// click(),
// ),
// )
// }
// }
// onView(withId(R.id.edt_search_dest)).perform(ViewActions.typeText(TEST_WORD_10))
// Thread.sleep(DELAY_2000)
// uiDevice.wait(
// Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/rv_search_places_suggestion_direction")),
// DELAY_20000,
// )
// rvSearchPlacesSuggestionDirection.adapter?.itemCount?.let {
// if (it > 0) {
// onView(withId(R.id.rv_search_places_suggestion_direction)).perform(
// RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
// 0,
// click(),
// ),
// )
// }
// }
// uiDevice.wait(
// Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/card_drive_go")),
// DELAY_20000,
// )
// uiDevice.wait(
// Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/card_walk_go")),
// DELAY_20000,
// )
// uiDevice.wait(
// Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/card_truck_go")),
// DELAY_20000,
// )
// val cardDriveGo =
// mActivityRule.activity.findViewById<MaterialCardView>(R.id.card_drive_go)
// if (cardDriveGo.visibility == View.VISIBLE) {
// val tvDriveDistance =
// mActivityRule.activity.findViewById<AppCompatTextView>(R.id.tv_drive_distance)
// val tvDriveMinute =
// mActivityRule.activity.findViewById<AppCompatTextView>(R.id.tv_drive_minute)
// val tvWalkDistance =
// mActivityRule.activity.findViewById<AppCompatTextView>(R.id.tv_walk_distance)
// val tvWalkMinute =
// mActivityRule.activity.findViewById<AppCompatTextView>(R.id.tv_walk_minute)
// val tvTruckDistance =
// mActivityRule.activity.findViewById<AppCompatTextView>(R.id.tv_truck_distance)
// val tvTruckMinute =
// mActivityRule.activity.findViewById<AppCompatTextView>(R.id.tv_truck_minute)
//
// Assert.assertTrue(
// TEST_FAILED_DISTANCE_OR_TIME_EMPTY,
// tvDriveDistance.text.toString().isNotEmpty() && tvDriveMinute.text.toString().isNotEmpty() &&
// tvWalkDistance.text.toString().isNotEmpty() && tvWalkMinute.text.toString().isNotEmpty() &&
// tvTruckDistance.text.toString().isNotEmpty() && tvTruckMinute.text.toString().isNotEmpty(),
// )
// } else {
// Assert.fail(TEST_FAILED_CARD_DRIVE_GO)
// }
// } else {
// Assert.fail(TEST_FAILED_SEARCH_DIRECTION)
// }
// } else {
// Assert.fail(TEST_FAILED_DIRECTION_CARD)
// }
} catch (_: Exception) {
Assert.fail(TEST_FAILED)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.aws.amazonlocation.ui.main

import android.app.ActivityManager
import android.content.Context
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.* // ktlint-disable no-wildcard-imports
Expand All @@ -21,6 +23,7 @@ import com.aws.amazonlocation.utils.KEY_POOL_ID
import com.aws.amazonlocation.utils.KEY_RE_START_APP
import com.aws.amazonlocation.utils.PreferenceManager
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.card.MaterialCardView
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.hamcrest.CoreMatchers
Expand Down Expand Up @@ -52,7 +55,7 @@ class ConnectToAWSTest : BaseTestMainActivity() {
try {
val settingTabText = mActivityRule.activity.getString(R.string.menu_setting)

Thread.sleep(DELAY_2000)
Thread.sleep(DELAY_3000)

onView(
allOf(
Expand Down Expand Up @@ -120,11 +123,20 @@ class ConnectToAWSTest : BaseTestMainActivity() {
try {
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
Thread.sleep(DELAY_1000)
Thread.sleep(DELAY_3000)

val tracking = uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.menu_tracking)))
tracking.click()

Thread.sleep(DELAY_1000)
val clEnableTracking =
mActivityRule.activity.findViewById<ConstraintLayout>(R.id.cl_enable_tracking)
if (clEnableTracking.visibility == View.VISIBLE) {
val btnEnableTracking =
mActivityRule.activity.findViewById<MaterialCardView>(R.id.btn_enable_tracking)
mActivityRule.activity.runOnUiThread {
btnEnableTracking.performClick()
}
}
Thread.sleep(DELAY_1000)
uiDevice.wait(
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/tv_sign_in_required")),
Expand Down Expand Up @@ -212,12 +224,21 @@ class ConnectToAWSTest : BaseTestMainActivity() {
try {
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
Thread.sleep(DELAY_1000)
Thread.sleep(DELAY_3000)

val tracking =
uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.menu_geofence)))
tracking.click()

Thread.sleep(DELAY_1000)
val clEnableTracking =
mActivityRule.activity.findViewById<ConstraintLayout>(R.id.cl_empty_geofence_list)
if (clEnableTracking.visibility == View.VISIBLE) {
val btnEnableTracking =
mActivityRule.activity.findViewById<MaterialCardView>(R.id.btn_add_geofence)
mActivityRule.activity.runOnUiThread {
btnEnableTracking.performClick()
}
}
Thread.sleep(DELAY_1000)
uiDevice.wait(
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/tv_sign_in_required")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ class ExploreFragmentGrabChangeStyleTest : BaseTestMainActivity() {
click()
)
)
Thread.sleep(DELAY_2000)
uiDevice.wait(
Until.hasObject(By.text(mActivityRule.activity.getString(R.string.ok))),
Until.hasObject(By.text(mActivityRule.activity.getString(R.string.enable_grab))),
DELAY_2000
)

val labelOk =
uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.ok)))
uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.enable_grab)))
labelOk?.click()
val mapName =
preferenceManager.getValue(KEY_MAP_NAME, mActivityRule.activity.getString(R.string.grab))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ExploreFragmentMapFunctionWithoutAwsLoginTest : BaseTestMainActivity() {
onView(withId(R.id.edt_search_places)).check(ViewAssertions.matches(isDisplayed()))
edtSearch?.perform(click())
onView(withId(R.id.edt_search_places))?.perform(typeText(TEST_WORD_4))
Thread.sleep(DELAY_5000)
uiDevice.wait(
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/rv_search_places_suggestion")),
DELAY_10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.aws.amazonlocation.BaseTestMainActivity
import com.aws.amazonlocation.DELAY_1000
import com.aws.amazonlocation.DELAY_10000
import com.aws.amazonlocation.DELAY_15000
import com.aws.amazonlocation.DELAY_2000
import com.aws.amazonlocation.DELAY_20000
import com.aws.amazonlocation.R
import com.aws.amazonlocation.TEST_FAILED_POOL_ID_NOT_BLANK
Expand Down Expand Up @@ -55,7 +56,7 @@ class SettingAWSDisconnectingTest : BaseTestMainActivity() {
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
val settingTabText = mActivityRule.activity.getString(R.string.menu_setting)
Thread.sleep(DELAY_1000)
Thread.sleep(DELAY_2000)
onView(
AllOf.allOf(
withText(settingTabText),
Expand Down
Loading
Loading