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

ALS-1927 Optimize all E2E test case #102

Merged
merged 6 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 18 additions & 9 deletions app/src/androidTest/java/com/aws/amazonlocation/GeneralUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.aws.amazonlocation
import android.content.Context
import android.provider.Settings
import android.view.View
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.ViewInteraction
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiObjectNotFoundException
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.Matcher
import org.junit.Assert
import java.util.Calendar
Expand Down Expand Up @@ -39,6 +42,21 @@ fun enableGPS(context: Context) {
}
}

fun checkLocationPermission(uiDevice: UiDevice) {
val btnContinueToApp =
uiDevice.findObject(UiSelector().resourceId("${BuildConfig.APPLICATION_ID}:id/btn_continue_to_app"))
if (btnContinueToApp.exists()) {
btnContinueToApp.click()
}
Thread.sleep(DELAY_1000)
uiDevice.findObject(By.text(WHILE_USING_THE_APP))?.click()
uiDevice.findObject(By.text(WHILE_USING_THE_APP_CAPS))?.click()
uiDevice.findObject(By.text(WHILE_USING_THE_APP_ALLOW))?.click()
uiDevice.findObject(By.text(ALLOW))?.click()
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
}

@Suppress("DEPRECATION")
fun isLocationEnabled(context: Context): Boolean {
val locationMode: Int = try {
Expand Down Expand Up @@ -86,15 +104,6 @@ val mockLocationsExit = listOf(
MockLocation(23.011594, 72.522444),
)

fun failTest(lineNo: Int, exception: Exception?) {
// Assert.fail("$TEST_FAILED - Exception caught at line $lineNo: ${exception?.stackTraceToString() ?: "Custom error"}")
if (exception != null) {
throw exception
} else {
throw Exception("$TEST_FAILED - Exception caught at line $lineNo: Custom error")
}
}

fun waitUntil(waitTime: Long, maxCount: Int, condition: () -> Boolean?) {
var count = 0
while (condition() != true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ import com.aws.amazonlocation.AMAZON_MAP_READY
import com.aws.amazonlocation.BaseTestMainActivity
import com.aws.amazonlocation.BuildConfig
import com.aws.amazonlocation.DELAY_15000
import com.aws.amazonlocation.DELAY_2000
import com.aws.amazonlocation.DELAY_20000
import com.aws.amazonlocation.DELAY_5000
import com.aws.amazonlocation.R
import com.aws.amazonlocation.TEST_FAILED
import com.aws.amazonlocation.TEST_FAILED_DIRECTION_CARD
import com.aws.amazonlocation.TEST_FAILED_NO_SEARCH_RESULT
import com.aws.amazonlocation.TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE
import com.aws.amazonlocation.TEST_FAILED_SEARCH_SHEET
import com.aws.amazonlocation.TEST_WORD_RIO_TINTO
import com.aws.amazonlocation.di.AppModule
import com.aws.amazonlocation.enableGPS
import com.aws.amazonlocation.failTest
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.card.MaterialCardView
import com.google.android.material.textfield.TextInputEditText
Expand All @@ -49,7 +48,6 @@ class AfterSearchDirectionButtonWorkingTest : BaseTestMainActivity() {
try {
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
Thread.sleep(DELAY_2000)

val edtSearch =
onView(withId(R.id.edt_search_places)).check(matches(isDisplayed()))
Expand All @@ -60,7 +58,6 @@ class AfterSearchDirectionButtonWorkingTest : BaseTestMainActivity() {
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/rv_search_places_suggestion")),
DELAY_20000,
)
Thread.sleep(DELAY_2000)
val rvSearchPlaceSuggestion =
mActivityRule.activity.findViewById<RecyclerView>(R.id.rv_search_places_suggestion)
if (rvSearchPlaceSuggestion.adapter?.itemCount != null) {
Expand Down Expand Up @@ -100,7 +97,7 @@ class AfterSearchDirectionButtonWorkingTest : BaseTestMainActivity() {
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
}
} catch (e: Exception) {
failTest(118, e)
Assert.fail("$TEST_FAILED ${e.message}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ import androidx.test.uiautomator.Until
import com.aws.amazonlocation.AMAZON_MAP_READY
import com.aws.amazonlocation.BaseTestMainActivity
import com.aws.amazonlocation.BuildConfig
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_5000
import com.aws.amazonlocation.R
import com.aws.amazonlocation.TEST_ADDRESS
import com.aws.amazonlocation.TEST_FAILED
import com.aws.amazonlocation.TEST_FAILED_NO_MESSAGE_FOUND
import com.aws.amazonlocation.di.AppModule
import com.aws.amazonlocation.failTest
import com.aws.amazonlocation.utils.EventType
import com.aws.amazonlocation.utils.KEY_MAP_NAME
import com.aws.amazonlocation.utils.KEY_MAP_STYLE_NAME
Expand All @@ -44,7 +41,6 @@ import org.junit.Test
@UninstallModules(AppModule::class)
@HiltAndroidTest
class AnalyticsTest : BaseTestMainActivity() {

private val uiDevice = UiDevice.getInstance(getInstrumentation())

private lateinit var preferenceManager: PreferenceManager
Expand All @@ -66,62 +62,61 @@ class AnalyticsTest : BaseTestMainActivity() {
fun checkAnalyticsContent() {
try {
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
Thread.sleep(DELAY_2000)
uiDevice.wait(
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/edt_search_places")),
DELAY_5000
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)
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
uiDevice.wait(
Until.hasObject(By.text(mActivityRule.activity.getString(R.string.menu_explore))),
DELAY_5000,
)
val settingTabText = mActivityRule.activity.getString(R.string.menu_setting)
onView(
allOf(
withText(settingTabText),
isDescendantOfA(withId(R.id.bottom_navigation_main)),
isDisplayed()
)
isDisplayed(),
),
).perform(click())
snackBarMsg = uiDevice.wait(Until.hasObject(By.text(EventType.SCREEN_OPEN)), DELAY_10000)
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
// Start - Map unit change event test
onView(
allOf(
withId(R.id.cl_unit_system),
isDisplayed()
)
isDisplayed(),
),
).perform(click())

Thread.sleep(DELAY_2000)
onView(
allOf(
withId(R.id.ll_imperial),
isDisplayed()
)
isDisplayed(),
),
).perform(click())
Thread.sleep(DELAY_2000)

snackBarMsg = uiDevice.wait(Until.hasObject(By.text(EventType.MAP_UNIT_CHANGE)), DELAY_10000)
snackBarMsg =
uiDevice.wait(Until.hasObject(By.text(EventType.MAP_UNIT_CHANGE)), DELAY_10000)
Assert.assertTrue(TEST_FAILED_NO_MESSAGE_FOUND, snackBarMsg)
// End - Map unit change event test
} catch (e: Exception) {
failTest(95, e)
Assert.fail(TEST_FAILED)
Assert.fail("$TEST_FAILED ${e.message}")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
package com.aws.amazonlocation.ui.main

import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasMinimumChildCount
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.aws.amazonlocation.AMAZON_MAP_READY
import com.aws.amazonlocation.BaseTestMainActivity
import com.aws.amazonlocation.DELAY_15000
import com.aws.amazonlocation.DELAY_2000
import com.aws.amazonlocation.GO
import com.aws.amazonlocation.R
import com.aws.amazonlocation.TEST_FAILED
import com.aws.amazonlocation.TEST_WORD_SHYAMAL_CROSS_ROAD
import com.aws.amazonlocation.checkLocationPermission
import com.aws.amazonlocation.di.AppModule
import com.aws.amazonlocation.enableGPS
import com.aws.amazonlocation.failTest
import com.aws.amazonlocation.waitForView
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
Expand All @@ -40,31 +37,22 @@ class CheckGoButtonClickLiveNavigationTest : BaseTestMainActivity() {
@Test
fun showGoButtonClickLiveNavigationTest() {
try {
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
checkLocationPermission(uiDevice)

val cardDirectionTest =
onView(withId(R.id.card_direction)).check(matches(isDisplayed()))
cardDirectionTest.perform(click())

Thread.sleep(DELAY_2000)

val sourceEdt = waitForView(allOf(withId(R.id.edt_search_direction), isDisplayed()))
sourceEdt?.perform(click())

Thread.sleep(DELAY_2000)

val clMyLocation =
waitForView(allOf(withText(R.string.label_my_location), isDisplayed()))
clMyLocation?.perform(click())

Thread.sleep(DELAY_2000)

val destinationEdt = waitForView(allOf(withId(R.id.edt_search_dest), isDisplayed()))
destinationEdt?.perform(click(), replaceText(TEST_WORD_SHYAMAL_CROSS_ROAD))

Thread.sleep(DELAY_2000)

val suggestionListRv = waitForView(
allOf(
withId(R.id.rv_search_places_suggestion_direction),
Expand Down Expand Up @@ -92,16 +80,14 @@ class CheckGoButtonClickLiveNavigationTest : BaseTestMainActivity() {

Espresso.closeSoftKeyboard()

// navListView
waitForView(allOf(withId(R.id.rv_navigation_list), isDisplayed(), hasMinimumChildCount(1)))

// btnExit
waitForView(allOf(withId(R.id.btn_exit), isDisplayed())) {
failTest(109, null)
Assert.fail("$TEST_FAILED button exit not visible")
}
} catch (e: Exception) {
failTest(145, e)
Assert.fail(TEST_FAILED)
Assert.fail("$TEST_FAILED ${e.message}")
}
}
}
Loading
Loading