From 151d214c1e65945d0d299481bce8251dde2abf95 Mon Sep 17 00:00:00 2001 From: Timothy Nibeaudeau Date: Wed, 16 Dec 2020 10:47:52 +0100 Subject: [PATCH 1/3] Bump dependencies and target android API 30 --- core/build.gradle | 2 + .../screenshot/WindowAttachmentTest.java | 2 +- .../testing/screenshot/WindowAttachment.java | 2 +- .../screenshot/internal/AlbumImpl.java | 2 +- .../screenshot/internal/TestNameDetector.java | 2 +- .../AccessibilityIssuesDumper.java | 2 +- .../layouthierarchy/AccessibilityUtil.java | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../sample/ExampleScreenshotTest.java | 39 ------------------- .../sample/ExampleScreenshotTest.kt | 36 +++++++++++++++++ .../testing/screenshot/sample/MainActivity.kt | 2 +- versions.gradle | 18 +++++---- 12 files changed, 56 insertions(+), 55 deletions(-) delete mode 100644 sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.java create mode 100644 sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.kt diff --git a/core/build.gradle b/core/build.gradle index ab939a9d..41e86369 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -46,11 +46,13 @@ dependencies { compileOnly deps.jsr305 implementation deps.supportAppCompat + implementation deps.supportAnnotation androidTestImplementation deps.dexmaker androidTestImplementation deps.dexmakerDx androidTestImplementation deps.androidTestRules + androidTestImplementation deps.androidTestJunit androidTestImplementation deps.espresso androidTestImplementation deps.mockito androidTestImplementation deps.dexmakerMockito diff --git a/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java b/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java index f6c7ec7a..8e49d603 100644 --- a/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java +++ b/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java @@ -28,8 +28,8 @@ import android.widget.LinearLayout; import androidx.test.InstrumentationRegistry; import androidx.test.espresso.Espresso; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; import org.junit.Rule; diff --git a/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java b/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java index 2d6314d1..541efbfa 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java +++ b/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java @@ -25,13 +25,13 @@ import android.view.Display; import android.view.View; import android.view.WindowManager; +import androidx.annotation.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.WeakHashMap; -import javax.annotation.Nullable; @SuppressLint("PrivateApi") public abstract class WindowAttachment { diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java b/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java index fe922c05..1d6afcd7 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java @@ -22,6 +22,7 @@ import android.graphics.BitmapFactory; import android.util.Log; import android.util.Xml; +import androidx.annotation.Nullable; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -35,7 +36,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import javax.annotation.Nullable; import org.xmlpull.v1.XmlSerializer; /** A "local" implementation of Album. */ diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java b/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java index b80bca74..3e86d4dc 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java @@ -16,9 +16,9 @@ package com.facebook.testing.screenshot.internal; +import androidx.annotation.Nullable; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import javax.annotation.Nullable; /** Detect the test name and class that is being run currently. */ public class TestNameDetector { diff --git a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java index 21f515d4..92a17418 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java +++ b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java @@ -18,8 +18,8 @@ import android.view.View; import android.view.ViewGroup; +import androidx.annotation.Nullable; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; -import javax.annotation.Nullable; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; diff --git a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java index 55ea5471..6ca2e5e4 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java +++ b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java @@ -26,11 +26,11 @@ import android.view.ViewParent; import android.view.Window; import android.view.WindowManager; +import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * This class provides utility methods for determining certain accessibility properties of {@link diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4a6ebcea..be52383e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.java b/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.java deleted file mode 100644 index 8d37819a..00000000 --- a/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.testing.screenshot.sample; - -import android.content.Context; -import android.view.LayoutInflater; -import androidx.test.platform.app.InstrumentationRegistry; -import com.facebook.litho.LithoView; -import com.facebook.testing.screenshot.Screenshot; -import com.facebook.testing.screenshot.ViewHelpers; -import org.junit.Test; - -public class ExampleScreenshotTest { - @Test - public void testDefault() { - Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - LayoutInflater inflater = LayoutInflater.from(targetContext); - LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false); - - view.setComponent(Example.create(view.getComponentContext()).build()); - - ViewHelpers.setupView(view).setExactWidthDp(300).layout(); - Screenshot.snap(view).record(); - } -} diff --git a/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.kt b/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.kt new file mode 100644 index 00000000..34e88c52 --- /dev/null +++ b/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.testing.screenshot.sample + + +import android.view.LayoutInflater +import androidx.test.platform.app.InstrumentationRegistry +import com.facebook.litho.LithoView +import com.facebook.testing.screenshot.Screenshot +import com.facebook.testing.screenshot.ViewHelpers +import org.junit.Test + +class ExampleScreenshotTest { + @Test + fun testDefault() { + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext + val inflater = LayoutInflater.from(targetContext) + val view = inflater.inflate(R.layout.litho_view, null, false) as LithoView + view.setComponent(Example.create(view.componentContext).build()) + ViewHelpers.setupView(view).setExactWidthDp(300).layout() + Screenshot.snap(view).record() + } +} diff --git a/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt b/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt index 99200634..ff879d9a 100644 --- a/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt +++ b/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt @@ -79,7 +79,7 @@ class MainActivity : AppCompatActivity() { private fun Intent.string(name: String, defValue: String): String { if (hasExtra(name)) { - return getStringExtra(name) + return getStringExtra(name)!! } return defValue } diff --git a/versions.gradle b/versions.gradle index 41acb56b..44bbc943 100644 --- a/versions.gradle +++ b/versions.gradle @@ -20,22 +20,23 @@ ext { final lithoVersion = "0.34.0" versions = [ - kotlin : '1.3.61', - targetSdk : 28, - compileSdk: 28, + kotlin : '1.4.21', + targetSdk : 30, + compileSdk: 30, minSdk : 14, ] plugs = [ - agp : "com.android.tools.build:gradle:3.6.0", + agp : "com.android.tools.build:gradle:4.1.1", screenshot : "com.facebook.testing.screenshot:plugin:$screenshotTestVersion", kotlin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}", versions : 'com.github.ben-manes:gradle-versions-plugin:0.20.0' ] deps = [ - supportAppCompat : "androidx.appcompat:appcompat:1.1.0", - supportDesign : "com.google.android.material:material:1.1.0", + supportAppCompat : "androidx.appcompat:appcompat:1.2.0", + supportAnnotation : "androidx.annotation:annotation:1.1.0", + supportDesign : "com.google.android.material:material:1.2.1", supportMultidex : "androidx.multidex:multidex:2.0.1", kotlinStdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}", @@ -56,8 +57,9 @@ ext { dexmakerDx : "com.crittercism.dexmaker:dexmaker-dx:$dexmakerVersion", dexmakerMockito : "com.crittercism.dexmaker:dexmaker-mockito:$dexmakerVersion", - espresso : "androidx.test.espresso:espresso-core:3.1.0", - androidTestRules : "androidx.test:rules:1.1.0", + espresso : "androidx.test.espresso:espresso-core:3.3.0", + androidTestRules : "androidx.test:rules:1.3.0", + androidTestJunit : "androidx.test.ext:junit:1.1.2", junit : "junit:junit:4.12", mockito : "org.mockito:mockito-core:1.10.19", hamcrest : "org.hamcrest:hamcrest-core:1.3", From 85d071a6734c28086b118e9628c23dc2b6b3f9fe Mon Sep 17 00:00:00 2001 From: Timothy Nibeaudeau Date: Wed, 16 Dec 2020 10:48:24 +0100 Subject: [PATCH 2/3] Save file in public repository Download on external storage --- .../internal/ScreenshotDirectories.java | 9 ++-- .../pull_screenshots.py | 51 ++++++++++++------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java b/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java index 168f3eae..ba7fe7ff 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java @@ -24,6 +24,7 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; +import android.os.Environment; import android.os.ParcelFileDescriptor; import java.io.File; import java.io.FileInputStream; @@ -98,11 +99,11 @@ private void grantPermission(Context context, String permission) { } private File getSdcardDir(String type) { - String externalStorage = System.getenv("EXTERNAL_STORAGE"); + File publicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); - if (externalStorage == null) { + if (publicDir == null) { throw new RuntimeException( - "No $EXTERNAL_STORAGE has been set on the device, please report this bug!"); + "No Downloads directory has been found on the device, please report this bug!"); } String sdcardDirectory = @@ -111,7 +112,7 @@ private File getSdcardDir(String type) { : DEFAULT_SDCARD_DIRECTORY; String parent = - String.format("%s/%s/%s/", externalStorage, sdcardDirectory, mContext.getPackageName()); + String.format("%s/%s/%s/", publicDir, sdcardDirectory, mContext.getPackageName()); String child = String.format("%s/screenshots-%s", parent, type); diff --git a/plugin/src/py/android_screenshot_tests/pull_screenshots.py b/plugin/src/py/android_screenshot_tests/pull_screenshots.py index 9801d30c..c6ceadf7 100755 --- a/plugin/src/py/android_screenshot_tests/pull_screenshots.py +++ b/plugin/src/py/android_screenshot_tests/pull_screenshots.py @@ -470,36 +470,49 @@ def android_path_join(a, *args): def pull_metadata(package, dir, adb_puller): - root_screenshot_dir = android_path_join( - adb_puller.get_external_data_dir(), "screenshots" - ) - metadata_file = android_path_join( - root_screenshot_dir, package, "screenshots-default/metadata.xml" - ) - - old_metadata_file = android_path_join( - OLD_ROOT_SCREENSHOT_DIR, package, "app_screenshots-default/metadata.xml" - ) - - if adb_puller.remote_file_exists(metadata_file): - adb_puller.pull(metadata_file, join(dir, "metadata.xml")) - elif adb_puller.remote_file_exists(old_metadata_file): - adb_puller.pull(old_metadata_file, join(dir, "metadata.xml")) - metadata_file = old_metadata_file - else: - create_empty_metadata_file(dir) + metadata_file = None + external_dir = adb_puller.get_external_data_dir() + + possible_location = [ + android_path_join( + external_dir, + 'Download/screenshots', + package, + 'screenshots-default/metadata.xml'), + android_path_join( + external_dir, + "screenshots", + package, + 'screenshots-default/metadata.xml'), + android_path_join( + OLD_ROOT_SCREENSHOT_DIR, + package, + 'app_screenshots-default/metadata.xml') + ] + + for location in possible_location: + if adb_puller.remote_file_exists(location): + adb_puller.pull(location, join(dir, 'metadata.xml')) + metadata_file = location + break + + if metadata_file == None: + metadata_file = create_empty_metadata_file(dir) return metadata_file.replace("metadata.xml", "") def create_empty_metadata_file(dir): - with open(join(dir, "metadata.xml"), "w") as out: + metadata_file = join(dir, 'metadata.xml') + with open(metadata_file, 'w') as out: out.write( """ """ ) + return metadata_file + def pull_images(dir, device_dir, adb_puller): bundle_name = "screenshot_bundle.zip" From 1a6972e5fcedebf08a5ea26036b5d61c2c20e182 Mon Sep 17 00:00:00 2001 From: Timothy Nibeaudeau Date: Wed, 16 Dec 2020 11:45:48 +0100 Subject: [PATCH 3/3] Update versions --- .../com/facebook/testing/screenshot/internal/AlbumImpl.java | 6 ------ versions.gradle | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java b/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java index fbee5398..ad2f5d19 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java @@ -33,12 +33,6 @@ import java.io.IOException; import java.util.HashSet; import java.util.Set; -import java.util.zip.Deflater; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; -import javax.annotation.Nullable; -import org.xmlpull.v1.XmlSerializer; /** A "local" implementation of Album. */ @SuppressWarnings("deprecation") diff --git a/versions.gradle b/versions.gradle index 96968485..5e5d1c6d 100644 --- a/versions.gradle +++ b/versions.gradle @@ -60,10 +60,10 @@ ext { dexmakerMockito : "com.crittercism.dexmaker:dexmaker-mockito:$dexmakerVersion", espresso : "androidx.test.espresso:espresso-core:3.3.0", - testRunner : "androidx.test:runner:1.2.0", + testRunner : "androidx.test:runner:1.3.0", androidTestRules : "androidx.test:rules:1.3.0", androidTestJunit : "androidx.test.ext:junit:1.1.2", - orchestrator : "androidx.test:orchestrator:1.2.0", + orchestrator : "androidx.test:orchestrator:1.3.0", junit : "junit:junit:4.12", mockito : "org.mockito:mockito-core:1.10.19", hamcrest : "org.hamcrest:hamcrest-core:1.3",