TP-72438 | Login benchmark (#11757)

This commit is contained in:
Abhinav Gupta
2024-07-10 17:01:13 +05:30
committed by GitHub
parent a7d5b6887e
commit 5c26bf6af1
8 changed files with 50 additions and 12 deletions

View File

@@ -113,6 +113,7 @@ class BoxInputGroup(context: Context, attributeSet: AttributeSet? = null) :
)
otpView.layoutParams = layoutParams
binding.otpLayout.addView(otpView)
otpView.contentDescription = "${Constants.OTP}-$position"
editTextBoxes.add(otpView.findViewById(R.id.otp_et))
editTextBoxes.forEach { it.hideCutCopyMenuPopUp() }
}

View File

@@ -479,6 +479,7 @@ object Constants {
const val SECTION_CONTENT_SIZE = 3
const val PERMISSION_REQUIRED = "permissionRequired"
const val INVESTMENT_TAB_INIT_LANDING_PAGE = "investment_tab_init_landing_page"
const val OTP = "otp"
// Constants for Animation label
object AnimationLabels {

View File

@@ -49,6 +49,7 @@
<EditText
android:id="@+id/phone_edit"
android:contentDescription="loginNumber"
style="@style/PhoneNumberTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -109,6 +110,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/get_otp_btn"
android:layout_width="0dp"
android:contentDescription="numberLoginButton"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_dp_32"
android:background="@color/outrageous_orange"

View File

@@ -141,6 +141,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_dp_40"
android:contentDescription="otpLoginButton"
android:background="@color/outrageous_orange"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/no_call_disclaimer"

View File

@@ -13,6 +13,7 @@ import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.naviapp.benchmark.utils.PACKAGE_NAME
import com.naviapp.benchmark.utils.performLogin
import com.naviapp.benchmark.utils.scrollHomePage
import com.naviapp.benchmark.utils.startActivityAndAllowNotifications
import com.naviapp.benchmark.utils.waitForHomePage
@@ -42,6 +43,7 @@ class HomePageScrollBenchmark {
startActivityAndAllowNotifications()
}
) {
performLogin()
waitForHomePage()
scrollHomePage()
}

View File

@@ -10,19 +10,19 @@ package com.naviapp.benchmark.startup
import androidx.benchmark.macro.BaselineProfileMode.Disable
import androidx.benchmark.macro.BaselineProfileMode.Require
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.StartupMode.COLD
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.naviapp.benchmark.utils.PACKAGE_NAME
import com.naviapp.benchmark.utils.allowNotifications
import com.naviapp.benchmark.utils.performLogin
import com.naviapp.benchmark.utils.startActivityAndAllowNotifications
import com.naviapp.benchmark.utils.waitForHomePageLoad
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4ClassRunner::class)
@RunWith(AndroidJUnit4::class)
class StartupBenchmark {
@get:Rule val benchmarkRule = MacrobenchmarkRule()
@@ -46,13 +46,11 @@ class StartupBenchmark {
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
iterations = 5,
startupMode = COLD,
setupBlock = {
pressHome()
allowNotifications()
},
startupMode = StartupMode.COLD,
setupBlock = { pressHome() },
) {
startActivityAndAllowNotifications()
performLogin()
waitForHomePageLoad()
}
}

View File

@@ -15,7 +15,35 @@ import androidx.test.uiautomator.Until
import java.util.concurrent.TimeUnit
fun MacrobenchmarkScope.waitForHomePage() {
device.wait(Until.hasObject(By.clazz(HOME_PAGE_CLASS_NAME)), TimeUnit.SECONDS.toMillis(50))
device.wait(Until.hasObject(By.clazz(HOME_PAGE_CLASS_NAME)), TimeUnit.SECONDS.toMillis(5))
}
fun MacrobenchmarkScope.performLogin() {
waitForLoginPage()
enterLoginCredentials()
}
fun MacrobenchmarkScope.enterLoginCredentials() {
if (!device.wait(Until.hasObject(By.desc("loginNumber")), TimeUnit.SECONDS.toMillis(10))) {
return
}
val loginNumber = device.waitAndFindObject(By.desc("loginNumber"), TimeUnit.SECONDS.toMillis(5))
loginNumber.text = "6666681798"
val numberLoginButton =
device.waitAndFindObject(By.desc("numberLoginButton"), TimeUnit.SECONDS.toMillis(5))
numberLoginButton.click()
val otpNumber0 = device.waitAndFindObject(By.desc("otp-1"), TimeUnit.SECONDS.toMillis(5))
otpNumber0.text = "1"
val otpNumber1 = device.waitAndFindObject(By.desc("otp-2"), TimeUnit.SECONDS.toMillis(5))
otpNumber1.text = "2"
val otpNumber2 = device.waitAndFindObject(By.desc("otp-3"), TimeUnit.SECONDS.toMillis(5))
otpNumber2.text = "3"
val otpNumber3 = device.waitAndFindObject(By.desc("otp-4"), TimeUnit.SECONDS.toMillis(5))
otpNumber3.text = "4"
val otpLoginButton =
device.waitAndFindObject(By.desc("otpLoginButton"), TimeUnit.SECONDS.toMillis(5))
otpLoginButton.click()
}
fun MacrobenchmarkScope.scrollHomePage() {
@@ -25,10 +53,14 @@ fun MacrobenchmarkScope.scrollHomePage() {
}
fun MacrobenchmarkScope.waitForHomePageLoad() {
device.wait(Until.hasObject(By.clazz(HOME_PAGE_CLASS_NAME)), TimeUnit.SECONDS.toMillis(50))
device.wait(Until.hasObject(By.clazz(HOME_PAGE_CLASS_NAME)), TimeUnit.SECONDS.toMillis(10))
val list =
device.waitAndFindObject(By.res("homeScreenWidgetsList"), TimeUnit.SECONDS.toMillis(10))
list.wait(untilHasChildren(), 60_000)
list.wait(untilHasChildren(), 5000)
}
fun MacrobenchmarkScope.waitForLoginPage() {
device.wait(Until.hasObject(By.clazz(LOGIN_PAGE_CLASS_NAME)), TimeUnit.SECONDS.toMillis(10))
}
fun untilHasChildren(

View File

@@ -18,6 +18,7 @@ val PACKAGE_NAME = buildString { append("com.naviapp.dev") }
val HOME_PAGE_CLASS_NAME = buildString {
append("com.naviapp.home.compose.activity.HomePageActivity")
}
val LOGIN_PAGE_CLASS_NAME = buildString { append("com.naviapp.registration.RegistrationActivity") }
fun UiDevice.waitAndFindObject(selector: BySelector, timeout: Long): UiObject2 {
if (!wait(Until.hasObject(selector), timeout)) {