Skip to content

Commit 00a6765

Browse files
authored
Merge pull request #102 from aws-geospatial/ALS-1927_optimize_E2E_test_cases
ALS-1927 Optimize all E2E test case
2 parents 4a802b5 + 4d167a7 commit 00a6765

File tree

62 files changed

+2261
-3200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2261
-3200
lines changed

app/src/androidTest/java/com/aws/amazonlocation/ConstantTest.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ import com.aws.amazonlocation.utils.MAP
66

77
// SPDX-License-Identifier: MIT-0
88

9-
const val DELAY_15000 = 15000L
10-
const val DELAY_20000 = 20000L
11-
const val DELAY_10000 = 10000L
129
const val DELAY_5000 = 5000L
1310
const val DELAY_1000 = 1000L
14-
const val DELAY_2000 = 2000L
1511
const val DELAY_3000 = 3000L
16-
const val DELAY_4000 = 4000L
17-
const val SECOND_DELAY_60 = 60000L
1812
const val WHILE_USING_THE_APP = "While using the app"
1913
const val WHILE_USING_THE_APP_CAPS = "WHILE USING THE APP"
2014
const val WHILE_USING_THE_APP_ALLOW = "Allow only while using the app"
@@ -45,21 +39,13 @@ const val TEST_WORD_ARG = "ARG"
4539
const val TEST_WORD_RUS = "RUS"
4640
const val TEST_WORD_LANGUAGE_AR = "العربية"
4741
const val TEST_WORD_LANGUAGE_BO = "Bosanski"
48-
const val ACCESS_FINE_LOCATION = "android.permission.ACCESS_FINE_LOCATION"
49-
const val ACCESS_COARSE_LOCATION = "android.permission.ACCESS_COARSE_LOCATION"
5042
const val TEST_FAILED = "Test failed"
51-
const val TEST_FAILED_DIRECTION_CARD = "Test failed due to direction card not visible"
52-
const val TEST_FAILED_SEARCH_SHEET = "Test failed due to search bottom sheet not visible"
5343
const val TEST_FAILED_NO_SEARCH_RESULT = "Test failed due to no search result"
54-
const val TEST_FAILED_CARD_DRIVE_GO = "Test failed due to card drive go not visible"
55-
const val TEST_FAILED_BUTTON_DIRECTION = "Test failed due to button direction not visible"
56-
const val TEST_FAILED_SEARCH_DIRECTION = "Test failed due to search direction not visible"
5744
const val TEST_FAILED_ZOOM_LEVEL = "Test failed due to zoom level not available"
5845
const val TEST_FAILED_LIST = "Test failed due to list not visible"
5946
const val TEST_FAILED_COUNTRY= "Test failed due to selected country doesn't match"
6047
const val TEST_FAILED_LANGUAGE= "Test failed due to selected language doesn't match"
6148

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

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

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

79-
const val TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE = "Test failed due to search field not visible"
80-
const val TEST_FAILED_EXIT_BUTTON_NOT_VISIBLE = "Test failed due to exit button not visible"
81-
const val TEST_FAILED_DISTANCE_OR_TIME_EMPTY = "Test failed due to distance or time empty"
8265
const val TEST_FAILED_DISTANCE_EMPTY = "Test failed due to distance is empty"
8366
const val TEST_FAILED_ZOOM_LEVEL_NOT_CHANGED = "Test failed due to zoom level not changed"
8467
const val TEST_FAILED_INVALID_IDENTITY_POOL_ID = "Test failed due to invalid identity pool id"
8568
const val TEST_FAILED_LOCATION_COMPONENT_NOT_ACTIVATED_OR_ENABLED = "Test failed due to location component not activated or enabled"
8669
const val TEST_FAILED_COUNT_NOT_GREATER_THAN_ZERO = "Test failed due to count not greater than zero"
8770
const val TEST_FAILED_MAX_ZOOM_NOT_REACHED = "Test failed due to max zoom not reached"
88-
const val TEST_FAILED_NAVIGATION_CARD_NOT_VISIBLE = "Test failed due to navigation card not visible"
8971
const val TEST_FAILED_HEIGHT_NOT_GREATER = "Test failed due to height not greater"
90-
const val TEST_FAILED_NO_MATCHING_TEXT_NOT_VISIBLE = "Test failed due to no matching text not visible"
9172
const val TEST_FAILED_COUNT_NOT_GREATER_THAN_ONE = "Test failed due to count not greater than one"
9273
const val TEST_FAILED_COUNT_NOT_GREATER_THEN_TWO = "Test failed due to count not greater then 2"
93-
const val TEST_FAILED_DRIVE_OR_WALK_OR_TRUCK_OPTION_NOT_VISIBLE = "Test failed due to drive or walk or truck option not visible"
9474
const val TEST_FAILED_INVALID_ORIGIN_OR_DESTINATION_TEXT = "Test failed due to invalid origin or destination text"
95-
const val TEST_FAILED_DIRECTION_TIME_NOT_VISIBLE = "Test failed due to direction time not visible"
96-
const val TEST_FAILED_PLACE_LINK_NOT_VISIBLE = "Test failed due to place link not visible"
9775
const val TEST_FAILED_IMAGE_NULL = "Test failed due to image null"
9876
const val TEST_FAILED_NOT_EQUAL = "Test failed due to not equal"
9977
const val TEST_FAILED_POOL_ID_NOT_BLANK = "Test failed due to pool id not blank"
10078
const val TEST_FAILED_ROUTE_OPTION_NOT_VISIBLE = "Test failed due to route option not visible"
101-
const val TEST_FAILED_LOGOUT_BUTTON_NOT_VISIBLE = "Test failed due to logout button not visible"
102-
const val TEST_FAILED_SIGNIN_BUTTON_NOT_VISIBLE = "Test failed due to signin button not visible"
103-
const val TEST_FAILED_COUNT_NOT_ZERO = "Test failed due to count not zero"
10479
const val TEST_FAILED_NOT_TRACKING_ENTERED_DIALOG = "Test failed due to not tracking entered dialog"
10580
const val TEST_FAILED_NOT_TRACKING_EXIT_DIALOG = "Test failed due to not tracking exit dialog"
106-
const val TEST_FAILED_MAP_NOT_FOUND = "Test failed due to map not found"
10781
const val TEST_FAILED_NO_DATA_FOUND = "No data found"
10882
const val TEST_FAILED_NO_MESSAGE_FOUND = "Expected message not found"
10983

app/src/androidTest/java/com/aws/amazonlocation/GeneralUtils.kt

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ package com.aws.amazonlocation
33
import android.content.Context
44
import android.provider.Settings
55
import android.view.View
6+
import androidx.test.core.app.ApplicationProvider
67
import androidx.test.espresso.Espresso
78
import androidx.test.espresso.ViewInteraction
9+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
10+
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
811
import androidx.test.platform.app.InstrumentationRegistry
12+
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
13+
import androidx.test.uiautomator.By
914
import androidx.test.uiautomator.UiDevice
1015
import androidx.test.uiautomator.UiObject
1116
import androidx.test.uiautomator.UiObjectNotFoundException
1217
import androidx.test.uiautomator.UiSelector
18+
import androidx.test.uiautomator.Until
1319
import org.hamcrest.Matcher
1420
import org.junit.Assert
1521
import java.util.Calendar
1622
import kotlin.random.Random
23+
import org.hamcrest.CoreMatchers.allOf
1724

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

@@ -39,6 +46,27 @@ fun enableGPS(context: Context) {
3946
}
4047
}
4148

49+
fun checkLocationPermission() {
50+
val uiDevice = UiDevice.getInstance(getInstrumentation())
51+
val btnContinueToApp =
52+
uiDevice.findObject(UiSelector().resourceId("${BuildConfig.APPLICATION_ID}:id/btn_continue_to_app"))
53+
if (btnContinueToApp.exists()) {
54+
btnContinueToApp.click()
55+
}
56+
Thread.sleep(DELAY_1000)
57+
uiDevice.findObject(By.text(WHILE_USING_THE_APP))?.click()
58+
uiDevice.findObject(By.text(WHILE_USING_THE_APP_CAPS))?.click()
59+
uiDevice.findObject(By.text(WHILE_USING_THE_APP_ALLOW))?.click()
60+
uiDevice.findObject(By.text(ALLOW))?.click()
61+
enableGPS(ApplicationProvider.getApplicationContext())
62+
waitForView(
63+
allOf(
64+
withContentDescription(AMAZON_MAP_READY),
65+
isDisplayed(),
66+
),
67+
)
68+
}
69+
4270
@Suppress("DEPRECATION")
4371
fun isLocationEnabled(context: Context): Boolean {
4472
val locationMode: Int = try {
@@ -86,15 +114,6 @@ val mockLocationsExit = listOf(
86114
MockLocation(23.011594, 72.522444),
87115
)
88116

89-
fun failTest(lineNo: Int, exception: Exception?) {
90-
// Assert.fail("$TEST_FAILED - Exception caught at line $lineNo: ${exception?.stackTraceToString() ?: "Custom error"}")
91-
if (exception != null) {
92-
throw exception
93-
} else {
94-
throw Exception("$TEST_FAILED - Exception caught at line $lineNo: Custom error")
95-
}
96-
}
97-
98117
fun waitUntil(waitTime: Long, maxCount: Int, condition: () -> Boolean?) {
99118
var count = 0
100119
while (condition() != true) {
Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,74 @@
11
package com.aws.amazonlocation.ui.main
22

3-
import android.view.View
4-
import androidx.constraintlayout.widget.ConstraintLayout
53
import androidx.recyclerview.widget.RecyclerView
6-
import androidx.test.core.app.ApplicationProvider
74
import androidx.test.espresso.Espresso.onView
5+
import androidx.test.espresso.Espresso.pressBack
86
import androidx.test.espresso.action.ViewActions.click
97
import androidx.test.espresso.action.ViewActions.replaceText
108
import androidx.test.espresso.assertion.ViewAssertions.matches
9+
import androidx.test.espresso.matcher.ViewMatchers.hasMinimumChildCount
1110
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
1211
import androidx.test.espresso.matcher.ViewMatchers.withId
13-
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
14-
import androidx.test.uiautomator.By
15-
import androidx.test.uiautomator.UiDevice
16-
import androidx.test.uiautomator.Until
17-
import com.aws.amazonlocation.AMAZON_MAP_READY
1812
import com.aws.amazonlocation.BaseTestMainActivity
19-
import com.aws.amazonlocation.BuildConfig
20-
import com.aws.amazonlocation.DELAY_15000
21-
import com.aws.amazonlocation.DELAY_2000
22-
import com.aws.amazonlocation.DELAY_20000
23-
import com.aws.amazonlocation.DELAY_5000
2413
import com.aws.amazonlocation.R
25-
import com.aws.amazonlocation.TEST_FAILED_DIRECTION_CARD
14+
import com.aws.amazonlocation.TEST_FAILED
2615
import com.aws.amazonlocation.TEST_FAILED_NO_SEARCH_RESULT
27-
import com.aws.amazonlocation.TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE
28-
import com.aws.amazonlocation.TEST_FAILED_SEARCH_SHEET
2916
import com.aws.amazonlocation.TEST_WORD_RIO_TINTO
17+
import com.aws.amazonlocation.checkLocationPermission
3018
import com.aws.amazonlocation.di.AppModule
31-
import com.aws.amazonlocation.enableGPS
32-
import com.aws.amazonlocation.failTest
33-
import com.google.android.material.bottomsheet.BottomSheetBehavior
34-
import com.google.android.material.card.MaterialCardView
35-
import com.google.android.material.textfield.TextInputEditText
19+
import com.aws.amazonlocation.waitForView
3620
import dagger.hilt.android.testing.HiltAndroidTest
3721
import dagger.hilt.android.testing.UninstallModules
22+
import org.hamcrest.CoreMatchers.allOf
3823
import org.junit.Assert
3924
import org.junit.Test
4025

4126
@UninstallModules(AppModule::class)
4227
@HiltAndroidTest
4328
class AfterSearchDirectionButtonWorkingTest : BaseTestMainActivity() {
44-
45-
private val uiDevice = UiDevice.getInstance(getInstrumentation())
46-
4729
@Test
4830
fun showAfterSearchDirectionButtonWorkingTest() {
4931
try {
50-
enableGPS(ApplicationProvider.getApplicationContext())
51-
uiDevice.wait(Until.hasObject(By.desc(AMAZON_MAP_READY)), DELAY_15000)
52-
Thread.sleep(DELAY_2000)
53-
32+
checkLocationPermission()
5433
val edtSearch =
5534
onView(withId(R.id.edt_search_places)).check(matches(isDisplayed()))
5635
edtSearch.perform(click())
5736
onView(withId(R.id.edt_search_places)).perform(replaceText(TEST_WORD_RIO_TINTO))
5837

59-
uiDevice.wait(
60-
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/rv_search_places_suggestion")),
61-
DELAY_20000,
62-
)
63-
Thread.sleep(DELAY_2000)
6438
val rvSearchPlaceSuggestion =
65-
mActivityRule.activity.findViewById<RecyclerView>(R.id.rv_search_places_suggestion)
66-
if (rvSearchPlaceSuggestion.adapter?.itemCount != null) {
67-
rvSearchPlaceSuggestion.adapter?.itemCount?.let {
68-
if (it >= 0) {
69-
val clSearchSheet =
70-
mActivityRule.activity.findViewById<ConstraintLayout>(R.id.bottom_sheet_search)
71-
if (clSearchSheet.visibility == View.VISIBLE) {
72-
val mBottomSheetSearchPlaces: BottomSheetBehavior<ConstraintLayout> =
73-
BottomSheetBehavior.from(clSearchSheet)
74-
mBottomSheetSearchPlaces.state = BottomSheetBehavior.STATE_COLLAPSED
75-
uiDevice.wait(Until.hasObject(By.text(mActivityRule.activity.getString(R.string.menu_explore))), DELAY_5000)
76-
val cardDirection =
77-
mActivityRule.activity.findViewById<MaterialCardView>(R.id.card_direction)
78-
if (cardDirection.visibility == View.VISIBLE) {
79-
val cardDirectionTest =
80-
onView(withId(R.id.card_direction)).check(matches(isDisplayed()))
81-
cardDirectionTest.perform(click())
82-
uiDevice.wait(
83-
Until.hasObject(By.res("${BuildConfig.APPLICATION_ID}:id/edt_search_direction")),
84-
DELAY_5000,
85-
)
86-
val edtSearchDirection =
87-
mActivityRule.activity.findViewById<TextInputEditText>(R.id.edt_search_direction)
88-
Assert.assertTrue(TEST_FAILED_SEARCH_FIELD_NOT_VISIBLE, edtSearchDirection.visibility == View.VISIBLE)
89-
} else {
90-
Assert.fail(TEST_FAILED_DIRECTION_CARD)
91-
}
92-
} else {
93-
Assert.fail(TEST_FAILED_SEARCH_SHEET)
94-
}
95-
} else {
96-
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
97-
}
39+
waitForView(
40+
allOf(
41+
withId(R.id.rv_search_places_suggestion),
42+
isDisplayed(),
43+
hasMinimumChildCount(1),
44+
),
45+
)
46+
47+
var itemCount = 0
48+
rvSearchPlaceSuggestion?.check { view, _ ->
49+
if (view is RecyclerView) {
50+
itemCount = view.adapter?.itemCount ?: 0
51+
} else {
52+
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
9853
}
54+
}
55+
if (itemCount >= 0) {
56+
pressBack()
57+
58+
val cardDirectionTest =
59+
onView(withId(R.id.card_direction)).check(matches(isDisplayed()))
60+
cardDirectionTest.perform(click())
61+
waitForView(
62+
allOf(
63+
withId(R.id.edt_search_direction),
64+
isDisplayed(),
65+
),
66+
)
9967
} else {
10068
Assert.fail(TEST_FAILED_NO_SEARCH_RESULT)
10169
}
10270
} catch (e: Exception) {
103-
failTest(118, e)
71+
Assert.fail("$TEST_FAILED ${e.message}")
10472
}
10573
}
10674
}

0 commit comments

Comments
 (0)