aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-31 01:37:47 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-31 01:37:47 +0000
commitf175909a38c3bddf9a6c900dad54d476d85c2f36 (patch)
tree1ddff29a56949a5e98e79ec8c372043a7547e39c
parent22fc97e1def0099835a66ce5c6350226435f500a (diff)
parentf4fdd50f1f7bc4123cbb1ef6807310a4162b0881 (diff)
downloadcsuite-f175909a38c3bddf9a6c900dad54d476d85c2f36.tar.gz
Snap for 9853495 from f4fdd50f1f7bc4123cbb1ef6807310a4162b0881 to udc-release
Change-Id: I9d94b20cf431ed3d4e1c9ed6870263a61133ef98
-rw-r--r--test_scripts/src/main/java/com/android/pixel/OWNERS2
-rw-r--r--test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java2
-rw-r--r--test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java30
3 files changed, 28 insertions, 6 deletions
diff --git a/test_scripts/src/main/java/com/android/pixel/OWNERS b/test_scripts/src/main/java/com/android/pixel/OWNERS
index 05ffe9a..aa4bbf9 100644
--- a/test_scripts/src/main/java/com/android/pixel/OWNERS
+++ b/test_scripts/src/main/java/com/android/pixel/OWNERS
@@ -1,2 +1,2 @@
murphykuo@google.com
-huilingchi@google.com
+elisahsu@google.com
diff --git a/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java b/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java
index 6c44a88..aa79bb5 100644
--- a/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java
+++ b/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java
@@ -33,7 +33,6 @@ import org.junit.Before;
/** Base class for Pixel app compatibility tests. */
public abstract class PixelAppCompatTestBase {
private static final String KEY_PACKAGE_NAME = "package";
-
private DeviceUtils mDeviceUtils;
private UiDevice mDevice;
private KeyguardManager mKeyguardManager;
@@ -41,6 +40,7 @@ public abstract class PixelAppCompatTestBase {
@Before
public void setUp() throws Exception {
+ getDeviceUtils().setTestName(this.getClass().getSimpleName());
getDeviceUtils().createLogDataDir();
getDeviceUtils().wakeAndUnlockScreen();
// Start from the home screen
diff --git a/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java b/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java
index 9d29dbc..1b665e3 100644
--- a/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java
+++ b/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java
@@ -25,11 +25,14 @@ import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.util.Log;
+import com.google.common.base.Preconditions;
+
import org.junit.Assert;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
+import java.util.Optional;
public class DeviceUtils {
private static final String TAG = DeviceUtils.class.getSimpleName();
@@ -39,6 +42,8 @@ public class DeviceUtils {
private static final long VIDEO_TAIL_BUFFER = 500;
private static final String DISMISS_KEYGUARD = "wm dismiss-keyguard";
+ private String mFolderDir = LOG_DATA_DIR;
+ private String mTestName = TAG;
private RecordingThread mCurrentThread;
private File mLogDataDir;
private UiDevice mDevice;
@@ -47,9 +52,24 @@ public class DeviceUtils {
mDevice = device;
}
+ /**
+ * Sets the test name and the folder path for the current test.
+ *
+ * @param testName The test name.
+ */
+ public void setTestName(String testName) {
+ Optional<String> optionalTestName = Optional.ofNullable(testName);
+ if (optionalTestName.isPresent()) {
+ mTestName = optionalTestName.get();
+ mFolderDir = String.join("/", LOG_DATA_DIR, optionalTestName.get());
+ } else {
+ Preconditions.checkNotNull(testName, "testName cannot be null");
+ }
+ }
+
/** Create a directory to save test screenshots, screenrecord and text files. */
public void createLogDataDir() {
- mLogDataDir = new File(LOG_DATA_DIR);
+ mLogDataDir = new File(mFolderDir);
if (mLogDataDir.exists()) {
String[] children = mLogDataDir.list();
for (String file : children) {
@@ -104,8 +124,9 @@ public class DeviceUtils {
public void takeScreenshot(String packageName, String description) {
File screenshot =
new File(
- LOG_DATA_DIR,
- String.format("%s_screenshot_%s.png", packageName, description));
+ mFolderDir,
+ String.format(
+ "%s_%s_screenshot_%s.png", mTestName, packageName, description));
mDevice.takeScreenshot(screenshot);
}
@@ -118,7 +139,8 @@ public class DeviceUtils {
Log.v(TAG, "Started Recording");
mCurrentThread =
new RecordingThread(
- "test-screen-record", String.format("%s_screenrecord", packageName));
+ "test-screen-record",
+ String.format("%s_%s_screenrecord", mTestName, packageName));
mCurrentThread.start();
}