Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Screenshots Automation] Fix locales switching #6834

Merged
merged 5 commits into from Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion WooCommerce/build.gradle
Expand Up @@ -263,7 +263,7 @@ dependencies {
// See https://github.com/wordpress-mobile/WordPress-FluxC-Android/issues/919
exclude group: 'com.squareup.okhttp3'
}
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android-core:2.9.1'

// Dependencies for local unit tests
testImplementation "junit:junit:$jUnitVersion"
Expand Down
Expand Up @@ -40,11 +40,11 @@ class ScreenshotTest : TestBase() {
val composeTestRule = createComposeRule()

@get:Rule(order = 3)
var activityRule = ActivityTestRule(MainActivity::class.java)

@Rule @JvmField
val localeTestRule = LocaleTestRule()

@get:Rule(order = 4)
var activityRule = ActivityTestRule(MainActivity::class.java)

@Before
fun setUp() {
CleanStatusBar.enableWithDefaults()
Expand Down
29 changes: 20 additions & 9 deletions WooCommerce/src/debug/AndroidManifest.xml
@@ -1,29 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest package="com.woocommerce.android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.woocommerce.android">

<!-- Allows unlocking your device and activating its screen so UI tests can succeed -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Allows for storing and retrieving screenshots -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- Allows changing locales -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION"
tools:ignore="ProtectedPermissions" />

<!-- Clean the status bar for screenshots automation
See https://docs.fastlane.tools/actions/screengrab/#clean-status-bar -->
<!-- Indicates the use of the clean status bar feature -->
<uses-feature android:name="tools.fastlane.screengrab.cleanstatusbar" />
<!-- Allows for changing the status bar -->
<uses-permission android:name="android.permission.DUMP" tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.DUMP"
tools:ignore="ProtectedPermissions" />

<application
android:name=".WooCommerceDebug"
tools:replace="android:name" />
tools:replace="android:name">
<provider
android:name=".LeakCanaryInstaller"
android:authorities="${applicationId}.leakcanary-installer"
android:exported="false" />
</application>

</manifest>
@@ -0,0 +1,42 @@
package com.woocommerce.android

import android.app.Application
import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import com.woocommerce.android.util.PackageUtils
import com.woocommerce.android.util.WooLog
import leakcanary.AppWatcher

internal class LeakCanaryInstaller : ContentProvider() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the same logic as leak-canary's default artifact in using a ContentProvider for the initialization, the change is that we can have custom logic for the initialization now.

override fun onCreate(): Boolean {
if (!PackageUtils.isTesting()) {
WooLog.v(WooLog.T.DEVICE, "Installing LeakCanary")
val application = context!!.applicationContext as Application
AppWatcher.manualInstall(application)
}
return true
}

override fun query(
uri: Uri,
projectionArg: Array<String>?,
selection: String?,
selectionArgs: Array<String>?,
sortOrder: String?
): Cursor? = null

override fun getType(uri: Uri): String? = null

override fun insert(uri: Uri, contentValues: ContentValues?): Uri? = null

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0

override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?
): Int = 0
}
Expand Up @@ -90,7 +90,7 @@ class ZendeskHelper(
enableLogs: Boolean = BuildConfig.DEBUG
) {
if (isZendeskEnabled) {
if (PackageUtils.isUITesting()) return
if (PackageUtils.isTesting()) return
else error("Zendesk shouldn't be initialized more than once!")
}
if (zendeskUrl.isEmpty() || applicationId.isEmpty() || oauthClientId.isEmpty()) {
Expand Down
Expand Up @@ -24,7 +24,7 @@ class MoreMenuRepository @Inject constructor(

suspend fun isInboxEnabled(): Boolean =
withContext(Dispatchers.IO) {
if (!FeatureFlag.MORE_MENU_INBOX.isEnabled()) return@withContext false
if (!selectedSite.exists() || !FeatureFlag.MORE_MENU_INBOX.isEnabled()) return@withContext false

val currentWooCoreVersion =
wooCommerceStore.getSitePlugin(selectedSite.get(), WOO_CORE)?.version ?: "0.0"
Expand Down
Expand Up @@ -20,7 +20,7 @@ object PackageUtils {
fun isTesting(): Boolean {
if (isTesting == null) {
isTesting = try {
Class.forName("com.woocommerce.android.viewmodel.BaseUnitTest")
Class.forName("org.junit.Test")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, this function detects both UI tests and unit tests.

true
} catch (e: ClassNotFoundException) {
false
Expand All @@ -29,15 +29,6 @@ object PackageUtils {
return isTesting!!
}

fun isUITesting(): Boolean {
return try {
Class.forName("com.woocommerce.android.helpers.TestBase")
true
} catch (e: ClassNotFoundException) {
false
}
}

fun isBetaBuild(context: Context): Boolean {
val versionName = getVersionName(context).toLowerCase(Locale.ROOT)
return (versionName.contains("beta") || versionName.contains("rc"))
Expand Down
5 changes: 0 additions & 5 deletions fastlane/Fastfile
Expand Up @@ -613,11 +613,6 @@ platform :android do
map { |locale| locale[:google_play] }
end

# Override the locales array with one locale until
# https://github.com/fastlane/fastlane/issues/19521
# is fixed:
locales = ["en-EN"]

UI.message("Attempting screenshots for locales: #{locales}")

screenshot_options = {
Expand Down