Skip to content

Commit

Permalink
Merge pull request #102 from aws-geospatial/ALS-1927_optimize_E2E_tes…
Browse files Browse the repository at this point in the history
…t_cases

ALS-1927 Optimize all E2E test case
  • Loading branch information
wadhawh authored Feb 10, 2025
2 parents 4a802b5 + 4d167a7 commit 00a6765
Show file tree
Hide file tree
Showing 62 changed files with 2,261 additions and 3,200 deletions.
26 changes: 0 additions & 26 deletions app/src/androidTest/java/com/aws/amazonlocation/ConstantTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ import com.aws.amazonlocation.utils.MAP

// SPDX-License-Identifier: MIT-0

const val DELAY_15000 = 15000L
const val DELAY_20000 = 20000L
const val DELAY_10000 = 10000L
const val DELAY_5000 = 5000L
const val DELAY_1000 = 1000L
const val DELAY_2000 = 2000L
const val DELAY_3000 = 3000L
const val DELAY_4000 = 4000L
const val SECOND_DELAY_60 = 60000L
const val WHILE_USING_THE_APP = "While using the app"
const val WHILE_USING_THE_APP_CAPS = "WHILE USING THE APP"
const val WHILE_USING_THE_APP_ALLOW = "Allow only while using the app"
Expand Down Expand Up @@ -45,21 +39,13 @@ const val TEST_WORD_ARG = "ARG"
const val TEST_WORD_RUS = "RUS"
const val TEST_WORD_LANGUAGE_AR = "العربية"
const val TEST_WORD_LANGUAGE_BO = "Bosanski"
const val ACCESS_FINE_LOCATION = "android.permission.ACCESS_FINE_LOCATION"
const val ACCESS_COARSE_LOCATION = "android.permission.ACCESS_COARSE_LOCATION"
const val TEST_FAILED = "Test failed"
const val TEST_FAILED_DIRECTION_CARD = "Test failed due to direction card not visible"
const val TEST_FAILED_SEARCH_SHEET = "Test failed due to search bottom sheet not visible"
const val TEST_FAILED_NO_SEARCH_RESULT = "Test failed due to no search result"
const val TEST_FAILED_CARD_DRIVE_GO = "Test failed due to card drive go not visible"
const val TEST_FAILED_BUTTON_DIRECTION = "Test failed due to button direction not visible"
const val TEST_FAILED_SEARCH_DIRECTION = "Test failed due to search direction not visible"
const val TEST_FAILED_ZOOM_LEVEL = "Test failed due to zoom level not available"
const val TEST_FAILED_LIST = "Test failed due to list not visible"
const val TEST_FAILED_COUNTRY= "Test failed due to selected country doesn't match"
const val TEST_FAILED_LANGUAGE= "Test failed due to selected language doesn't match"

const val TEST_FAILED_SETTINGS_ALL_OPTIONS_NOT_VISIBLE = "Test failed due to settings all options not visible"

const val TEST_FAILED_DEFAULT_ROUTE_OPTIONS_NOT_LOADED = "Test failed due to default route options not loaded"

Expand All @@ -76,34 +62,22 @@ const val TEST_FAILED_NO_UPDATE_TRACKING_HISTORY = "Test failed due to tracking
const val TEST_FAILED_CONNECT_TO_AWS_FROM_SETTINGS = "Test failed for connect to aws from settings"
const val NESTED_SCROLL_ERROR = "Nested scroll error"

const val TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE = "Test failed due to search field not visible"
const val TEST_FAILED_EXIT_BUTTON_NOT_VISIBLE = "Test failed due to exit button not visible"
const val TEST_FAILED_DISTANCE_OR_TIME_EMPTY = "Test failed due to distance or time empty"
const val TEST_FAILED_DISTANCE_EMPTY = "Test failed due to distance is empty"
const val TEST_FAILED_ZOOM_LEVEL_NOT_CHANGED = "Test failed due to zoom level not changed"
const val TEST_FAILED_INVALID_IDENTITY_POOL_ID = "Test failed due to invalid identity pool id"
const val TEST_FAILED_LOCATION_COMPONENT_NOT_ACTIVATED_OR_ENABLED = "Test failed due to location component not activated or enabled"
const val TEST_FAILED_COUNT_NOT_GREATER_THAN_ZERO = "Test failed due to count not greater than zero"
const val TEST_FAILED_MAX_ZOOM_NOT_REACHED = "Test failed due to max zoom not reached"
const val TEST_FAILED_NAVIGATION_CARD_NOT_VISIBLE = "Test failed due to navigation card not visible"
const val TEST_FAILED_HEIGHT_NOT_GREATER = "Test failed due to height not greater"
const val TEST_FAILED_NO_MATCHING_TEXT_NOT_VISIBLE = "Test failed due to no matching text not visible"
const val TEST_FAILED_COUNT_NOT_GREATER_THAN_ONE = "Test failed due to count not greater than one"
const val TEST_FAILED_COUNT_NOT_GREATER_THEN_TWO = "Test failed due to count not greater then 2"
const val TEST_FAILED_DRIVE_OR_WALK_OR_TRUCK_OPTION_NOT_VISIBLE = "Test failed due to drive or walk or truck option not visible"
const val TEST_FAILED_INVALID_ORIGIN_OR_DESTINATION_TEXT = "Test failed due to invalid origin or destination text"
const val TEST_FAILED_DIRECTION_TIME_NOT_VISIBLE = "Test failed due to direction time not visible"
const val TEST_FAILED_PLACE_LINK_NOT_VISIBLE = "Test failed due to place link not visible"
const val TEST_FAILED_IMAGE_NULL = "Test failed due to image null"
const val TEST_FAILED_NOT_EQUAL = "Test failed due to not equal"
const val TEST_FAILED_POOL_ID_NOT_BLANK = "Test failed due to pool id not blank"
const val TEST_FAILED_ROUTE_OPTION_NOT_VISIBLE = "Test failed due to route option not visible"
const val TEST_FAILED_LOGOUT_BUTTON_NOT_VISIBLE = "Test failed due to logout button not visible"
const val TEST_FAILED_SIGNIN_BUTTON_NOT_VISIBLE = "Test failed due to signin button not visible"
const val TEST_FAILED_COUNT_NOT_ZERO = "Test failed due to count not zero"
const val TEST_FAILED_NOT_TRACKING_ENTERED_DIALOG = "Test failed due to not tracking entered dialog"
const val TEST_FAILED_NOT_TRACKING_EXIT_DIALOG = "Test failed due to not tracking exit dialog"
const val TEST_FAILED_MAP_NOT_FOUND = "Test failed due to map not found"
const val TEST_FAILED_NO_DATA_FOUND = "No data found"
const val TEST_FAILED_NO_MESSAGE_FOUND = "Expected message not found"

Expand Down
37 changes: 28 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,17 +3,24 @@ 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.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
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.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
import kotlin.random.Random
import org.hamcrest.CoreMatchers.allOf

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand All @@ -39,6 +46,27 @@ fun enableGPS(context: Context) {
}
}

fun checkLocationPermission() {
val uiDevice = UiDevice.getInstance(getInstrumentation())
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())
waitForView(
allOf(
withContentDescription(AMAZON_MAP_READY),
isDisplayed(),
),
)
}

@Suppress("DEPRECATION")
fun isLocationEnabled(context: Context): Boolean {
val locationMode: Int = try {
Expand Down Expand Up @@ -86,15 +114,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
@@ -1,106 +1,74 @@
package com.aws.amazonlocation.ui.main

import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
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.matcher.ViewMatchers.hasMinimumChildCount
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
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.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_DIRECTION_CARD
import com.aws.amazonlocation.TEST_FAILED
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.checkLocationPermission
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
import com.aws.amazonlocation.waitForView
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.hamcrest.CoreMatchers.allOf
import org.junit.Assert
import org.junit.Test

@UninstallModules(AppModule::class)
@HiltAndroidTest
class AfterSearchDirectionButtonWorkingTest : BaseTestMainActivity() {

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

@Test
fun showAfterSearchDirectionButtonWorkingTest() {
try {
enableGPS(ApplicationProvider.getApplicationContext())
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
Thread.sleep(DELAY_2000)

checkLocationPermission()
val edtSearch =
onView(withId(R.id.edt_search_places)).check(matches(isDisplayed()))
edtSearch.perform(click())
onView(withId(R.id.edt_search_places)).perform(replaceText(TEST_WORD_RIO_TINTO))

uiDevice.wait(
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) {
rvSearchPlaceSuggestion.adapter?.itemCount?.let {
if (it >= 0) {
val clSearchSheet =
mActivityRule.activity.findViewById<ConstraintLayout>(R.id.bottom_sheet_search)
if (clSearchSheet.visibility == View.VISIBLE) {
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)
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)
Assert.assertTrue(TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE, edtSearchDirection.visibility == View.VISIBLE)
} else {
Assert.fail(TEST_FAILED_DIRECTION_CARD)
}
} else {
Assert.fail(TEST_FAILED_SEARCH_SHEET)
}
} else {
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
}
waitForView(
allOf(
withId(R.id.rv_search_places_suggestion),
isDisplayed(),
hasMinimumChildCount(1),
),
)

var itemCount = 0
rvSearchPlaceSuggestion?.check { view, _ ->
if (view is RecyclerView) {
itemCount = view.adapter?.itemCount ?: 0
} else {
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
}
}
if (itemCount >= 0) {
pressBack()

val cardDirectionTest =
onView(withId(R.id.card_direction)).check(matches(isDisplayed()))
cardDirectionTest.perform(click())
waitForView(
allOf(
withId(R.id.edt_search_direction),
isDisplayed(),
),
)
} else {
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
}
} catch (e: Exception) {
failTest(118, e)
Assert.fail("$TEST_FAILED ${e.message}")
}
}
}
Loading

0 comments on commit 00a6765

Please sign in to comment.