Skip to content

Commit

Permalink
Merge pull request #6834 from woocommerce/screenshots-automation/fix-…
Browse files Browse the repository at this point in the history
…locales-switching

[Screenshots Automation] Fix locales switching
  • Loading branch information
0nko committed Jul 1, 2022
2 parents 8a97497 + b0b7d01 commit df1fd96
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 30 deletions.
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() {
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")
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

0 comments on commit df1fd96

Please sign in to comment.