Skip to content

Commit

Permalink
Improved the logs to capture the error. Also, improved the closing of…
Browse files Browse the repository at this point in the history
… google dialog if visible
  • Loading branch information
MohitMaliDeveloper committed Nov 15, 2024
1 parent f8f6b4c commit 61fe23a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,21 @@ class SearchWidgetRobot : BaseRobot() {
uiDevice.waitForIdle()
} catch (ignore: Exception) {
// nothing to do since widget is not added
Log.e("SEARCH_WIDGET", "Could not find the Search widget. It likely does not exist.")
Log.e(
"SEARCH_WIDGET_TEST",
"Could not find the Search widget. It likely does not exist."
)
}
}

fun assertAddWidgetToHomeScreenVisible(): Boolean =
try {
isVisible(Text("Add automatically"))
true
} catch (ignore: Exception) {
false
}

fun addWidgetToHomeScreenFromWidgetWindow() {
testFlakyView({ clickOn(Text("Add automatically")) })
}
Expand Down Expand Up @@ -95,10 +106,10 @@ class SearchWidgetRobot : BaseRobot() {
clickOnElementById(uiDevice, kiwixMainActivity, "search_widget_mic")
}

fun closeIfGoogleSearchVisible(uiDevice: UiDevice) {
fun closeIfGoogleSearchVisible() {
try {
pauseForBetterTestPerformance()
testFlakyView({ uiDevice.findObject(By.text("Google")) })
testFlakyView({ isVisible(Text("Google")) })
pressBack()
Log.e("SEARCH_WIDGET_TEST", "Closed the Google speak dialog")
} catch (ignore: Exception) {
Expand Down Expand Up @@ -149,7 +160,7 @@ class SearchWidgetRobot : BaseRobot() {
return
} catch (e: UiObjectNotFoundException) {
attempts++
Log.e("SEARCH_WIDGET", "Attempt $attempts: Failed to click on $elementId")
Log.e("SEARCH_WIDGET_TEST", "Attempt $attempts: Failed to click on $elementId")
}
}
throw RuntimeException("Could not find $elementId after $retryCount attempts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,25 @@ class SearchWidgetTest : BaseActivityTest() {
pressHome()
uiDevice.waitForIdle()
if (addWidgetToHomeScreen()) {
addWidgetToHomeScreenFromWidgetWindow()
assertSearchWidgetAddedToHomeScreen()
clickOnBookmarkIcon(uiDevice, kiwixMainActivity)
assertBookmarkScreenVisible()
pressBack()
pressHome()
findSearchWidget(uiDevice)
clickOnMicIcon(uiDevice, kiwixMainActivity)
closeIfGoogleSearchVisible(uiDevice)
assertSearchScreenVisible()
pressBack()
pressHome()
findSearchWidget(uiDevice)
clickOnSearchText(uiDevice, kiwixMainActivity)
assertSearchScreenVisible()
pressHome()
removeWidgetIfAlreadyAdded(uiDevice)
if (assertAddWidgetToHomeScreenVisible()) {
addWidgetToHomeScreenFromWidgetWindow()
assertSearchWidgetAddedToHomeScreen()
clickOnBookmarkIcon(uiDevice, kiwixMainActivity)
assertBookmarkScreenVisible()
pressBack()
pressHome()
findSearchWidget(uiDevice)
clickOnMicIcon(uiDevice, kiwixMainActivity)
closeIfGoogleSearchVisible()
assertSearchScreenVisible()
pressBack()
pressHome()
findSearchWidget(uiDevice)
clickOnSearchText(uiDevice, kiwixMainActivity)
assertSearchScreenVisible()
pressHome()
removeWidgetIfAlreadyAdded(uiDevice)
}
}
}
}
Expand Down

0 comments on commit 61fe23a

Please sign in to comment.