From a878e4b3faa9d75f43290d7dbfb1f4e07a8e1840 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Wed, 13 Mar 2024 14:17:28 +0200 Subject: [PATCH] Bug 1885123 - Add logs to DataGenerationHelper --- .../fenix/helpers/DataGenerationHelper.kt | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/DataGenerationHelper.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/DataGenerationHelper.kt index d82affa71..44e46b135 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/DataGenerationHelper.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/DataGenerationHelper.kt @@ -13,6 +13,7 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.net.Uri +import android.util.Log import androidx.browser.customtabs.CustomTabsIntent import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiSelector @@ -20,6 +21,7 @@ import mozilla.components.browser.state.search.SearchEngine import mozilla.components.browser.state.state.availableSearchEngines import org.junit.Assert import org.mozilla.fenix.ext.components +import org.mozilla.fenix.helpers.Constants.TAG import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.utils.IntentUtils import java.time.LocalDate @@ -33,6 +35,7 @@ object DataGenerationHelper { customMenuItemLabel: String = "", customActionButtonDescription: String = "", ): Intent { + Log.i(TAG, "createCustomTabIntent: Trying to create custom tab intent with url: $pageUrl") val appContext = InstrumentationRegistry.getInstrumentation() .targetContext .applicationContext @@ -48,33 +51,44 @@ object DataGenerationHelper { ) .build() customTabsIntent.intent.data = Uri.parse(pageUrl) + Log.i(TAG, "createCustomTabIntent: Created custom tab intent with url: $pageUrl") return customTabsIntent.intent } private fun createTestBitmap(): Bitmap { + Log.i(TAG, "createTestBitmap: Trying to create a test bitmap") val bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) canvas.drawColor(Color.GREEN) + Log.i(TAG, "createTestBitmap: Created a test bitmap") return bitmap } fun getStringResource(id: Int, argument: String = TestHelper.appName) = TestHelper.appContext.resources.getString(id, argument) private val charPool: List = ('a'..'z') + ('A'..'Z') + ('0'..'9') - fun generateRandomString(stringLength: Int) = - (1..stringLength) - .map { kotlin.random.Random.nextInt(0, charPool.size) } - .map(charPool::get) - .joinToString("") + fun generateRandomString(stringLength: Int): String { + Log.i(TAG, "generateRandomString: Trying to generate a random string with $stringLength characters") + val randomString = + (1..stringLength) + .map { kotlin.random.Random.nextInt(0, charPool.size) } + .map(charPool::get) + .joinToString("") + Log.i(TAG, "generateRandomString: Generated random string: $randomString") + + return randomString + } /** * Creates clipboard data. */ fun setTextToClipBoard(context: Context, message: String) { + Log.i(TAG, "setTextToClipBoard: Trying to set clipboard text to: $message") val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clipData = ClipData.newPlainText("label", message) clipBoard.setPrimaryClip(clipData) + Log.i(TAG, "setTextToClipBoard: Clipboard text was set to: $message") } /** @@ -88,6 +102,7 @@ object DataGenerationHelper { * @return A string representing the current date and time in the specified format. */ fun getSponsoredFxSuggestPlaceHolder(): String { + Log.i(TAG, "getSponsoredFxSuggestPlaceHolder: Trying to get the sponsored search suggestion placeholder") val currentDate = LocalDate.now() val currentTime = LocalTime.now() @@ -96,6 +111,8 @@ object DataGenerationHelper { val currentYear = currentDate.year.toString() val currentHour = currentTime.hour.toString().padStart(2, '0') + Log.i(TAG, "getSponsoredFxSuggestPlaceHolder: Got: ${currentYear + currentMonth + currentDay + currentHour} as the sponsored search suggestion placeholder") + return currentYear + currentMonth + currentDay + currentHour } @@ -103,6 +120,7 @@ object DataGenerationHelper { * Returns sponsored shortcut title based on the index. */ fun getSponsoredShortcutTitle(position: Int): String { + Log.i(TAG, "getSponsoredShortcutTitle: Trying to get the title of the sponsored shortcut at position: ${position - 1}") val sponsoredShortcut = mDevice.findObject( UiSelector() .resourceId("${TestHelper.packageName}:id/top_site_item") @@ -111,7 +129,7 @@ object DataGenerationHelper { UiSelector() .resourceId("${TestHelper.packageName}:id/top_site_title"), ).text - + Log.i(TAG, "getSponsoredShortcutTitle: The sponsored shortcut at position: ${position - 1} has title: $sponsoredShortcut") return sponsoredShortcut } @@ -120,8 +138,10 @@ object DataGenerationHelper { * For en-us it will return the 6 engines selected by default: Google, Bing, DuckDuckGo, Amazon, Ebay, Wikipedia. */ fun getRegionSearchEnginesList(): List { + Log.i(TAG, "getRegionSearchEnginesList: Trying to get the search engines based on the region of the user") val searchEnginesList = appContext.components.core.store.state.search.regionSearchEngines - Assert.assertTrue("Search engines list returned nothing", searchEnginesList.isNotEmpty()) + Assert.assertTrue("$TAG: Search engines list returned nothing", searchEnginesList.isNotEmpty()) + Log.i(TAG, "getRegionSearchEnginesList: Got $searchEnginesList based on the region of the user") return searchEnginesList } @@ -130,8 +150,10 @@ object DataGenerationHelper { * For en-us it will return the 2 engines: Reddit, Youtube. */ fun getAvailableSearchEngines(): List { + Log.i(TAG, "getAvailableSearchEngines: Trying to get the alternative search engines based on the region of the user") val searchEnginesList = TestHelper.appContext.components.core.store.state.search.availableSearchEngines - Assert.assertTrue("Search engines list returned nothing", searchEnginesList.isNotEmpty()) + Assert.assertTrue("$TAG: Search engines list returned nothing", searchEnginesList.isNotEmpty()) + Log.i(TAG, "getAvailableSearchEngines: Got $searchEnginesList based on the region of the user") return searchEnginesList } }