aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuexi Ma <yuexima@google.com>2023-03-21 16:00:11 -0700
committerYuexi Ma <yuexima@google.com>2023-03-27 15:59:45 -0700
commita15550b24d862c093eca8f8109551dbe9cc569cd (patch)
tree7862c2dd581592df647f5a17d5a75691584c0cae
parentbf6585e0626df83506db86946e52fcc8cdd99df2 (diff)
downloadcsuite-a15550b24d862c093eca8f8109551dbe9cc569cd.tar.gz
Support UTP Robo Client
Test: forrest + unit test Bug: 243719156 Change-Id: Ic64a63d337c3fd5c8472bc0c690d71c7831a22e5
-rw-r--r--harness/src/main/java/com/android/csuite/core/AppCrawlTester.java167
-rw-r--r--harness/src/main/java/com/android/csuite/core/AppCrawlTesterHostPreparer.java29
-rw-r--r--harness/src/main/java/com/android/csuite/core/RoboLoginConfig.java36
-rw-r--r--harness/src/main/java/com/android/csuite/core/RoboLoginConfigProvider.java34
-rw-r--r--harness/src/test/java/com/android/csuite/core/AppCrawlTesterHostPreparerTest.java21
-rw-r--r--harness/src/test/java/com/android/csuite/core/AppCrawlTesterTest.java167
6 files changed, 273 insertions, 181 deletions
diff --git a/harness/src/main/java/com/android/csuite/core/AppCrawlTester.java b/harness/src/main/java/com/android/csuite/core/AppCrawlTester.java
index a4cfcb4..258b374 100644
--- a/harness/src/main/java/com/android/csuite/core/AppCrawlTester.java
+++ b/harness/src/main/java/com/android/csuite/core/AppCrawlTester.java
@@ -37,6 +37,8 @@ import org.junit.Assert;
import java.io.File;
import java.io.IOException;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -64,6 +66,7 @@ public final class AppCrawlTester {
private Path mRoboscriptFile;
private Path mCrawlGuidanceProtoFile;
private Path mLoginConfigDir;
+ private FileSystem mFileSystem;
/**
* Creates an {@link AppCrawlTester} instance.
@@ -78,14 +81,20 @@ public final class AppCrawlTester {
return new AppCrawlTester(
packageName,
TestUtils.getInstance(testInformation, testLogData),
- () -> new RunUtil());
+ () -> new RunUtil(),
+ FileSystems.getDefault());
}
@VisibleForTesting
- AppCrawlTester(String packageName, TestUtils testUtils, RunUtilProvider runUtilProvider) {
+ AppCrawlTester(
+ String packageName,
+ TestUtils testUtils,
+ RunUtilProvider runUtilProvider,
+ FileSystem fileSystem) {
mRunUtilProvider = runUtilProvider;
mPackageName = packageName;
mTestUtils = testUtils;
+ mFileSystem = fileSystem;
}
/** An exception class representing crawler test failures. */
@@ -188,17 +197,34 @@ public final class AppCrawlTester {
throw new CrawlerException("Failed to create temp directory for output.", e);
}
- String[] command = createCrawlerRunCommand(mTestUtils.getTestInformation());
-
- CLog.d("Launching package: %s.", mPackageName);
-
IRunUtil runUtil = mRunUtilProvider.get();
-
+ AtomicReference<String[]> command = new AtomicReference<>();
AtomicReference<CommandResult> commandResult = new AtomicReference<>();
- runUtil.setEnvVariable(
- "GOOGLE_APPLICATION_CREDENTIALS",
- AppCrawlTesterHostPreparer.getCredentialPath(mTestUtils.getTestInformation())
- .toString());
+
+ CLog.d("Start to crawl package: %s.", mPackageName);
+
+ Path bin =
+ mFileSystem.getPath(
+ AppCrawlTesterHostPreparer.getCrawlerBinPath(
+ mTestUtils.getTestInformation()));
+ boolean isUtpClient = false;
+ if (Files.exists(bin.resolve("utp-cli-android_deploy.jar"))) {
+ command.set(createUtpCrawlerRunCommand(mTestUtils.getTestInformation()));
+ runUtil.setEnvVariable(
+ "ANDROID_SDK",
+ AppCrawlTesterHostPreparer.getSdkPath(mTestUtils.getTestInformation())
+ .toString());
+ isUtpClient = true;
+ } else if (Files.exists(bin.resolve("crawl_launcher_deploy.jar"))) {
+ command.set(createCrawlerRunCommand(mTestUtils.getTestInformation()));
+ runUtil.setEnvVariable(
+ "GOOGLE_APPLICATION_CREDENTIALS",
+ AppCrawlTesterHostPreparer.getCredentialPath(mTestUtils.getTestInformation())
+ .toString());
+ } else {
+ throw new CrawlerException(
+ "Crawler executable binaries not found in " + bin.toString());
+ }
if (mCollectGmsVersion) {
mTestUtils.collectGmsVersion(mPackageName);
@@ -212,11 +238,11 @@ public final class AppCrawlTester {
if (mRecordScreen) {
mTestUtils.collectScreenRecord(
() -> {
- commandResult.set(runUtil.runTimedCmd(commandTimeout, command));
+ commandResult.set(runUtil.runTimedCmd(commandTimeout, command.get()));
},
mPackageName);
} else {
- commandResult.set(runUtil.runTimedCmd(commandTimeout, command));
+ commandResult.set(runUtil.runTimedCmd(commandTimeout, command.get()));
}
// Must be done after the crawler run because the app is installed by the crawler.
@@ -225,9 +251,10 @@ public final class AppCrawlTester {
}
collectOutputZip();
- collectCrawlStepScreenshots();
+ collectCrawlStepScreenshots(isUtpClient);
- if (!commandResult.get().getStatus().equals(CommandStatus.SUCCESS)) {
+ if (!commandResult.get().getStatus().equals(CommandStatus.SUCCESS)
+ || commandResult.get().getStdout().contains("Unknown options:")) {
throw new CrawlerException("Crawler command failed: " + commandResult.get());
}
@@ -235,13 +262,16 @@ public final class AppCrawlTester {
}
/** Copys the step screenshots into test outputs for easier access. */
- private void collectCrawlStepScreenshots() {
+ private void collectCrawlStepScreenshots(boolean isUtpClient) {
if (mOutput == null) {
CLog.e("Output directory is not created yet. Skipping collecting step screenshots.");
return;
}
- Path subDir = mOutput.resolve("app_firebase_test_lab");
+ Path subDir =
+ isUtpClient
+ ? mOutput.resolve("output").resolve("artifacts")
+ : mOutput.resolve("app_firebase_test_lab");
if (!Files.exists(subDir)) {
CLog.e(
"The crawler output directory is not complete, skipping collecting step"
@@ -286,16 +316,106 @@ public final class AppCrawlTester {
}
@VisibleForTesting
- String[] createCrawlerRunCommand(TestInformation testInfo) throws CrawlerException {
+ String[] createUtpCrawlerRunCommand(TestInformation testInfo) throws CrawlerException {
+ Path bin =
+ mFileSystem.getPath(
+ AppCrawlTesterHostPreparer.getCrawlerBinPath(
+ mTestUtils.getTestInformation()));
ArrayList<String> cmd = new ArrayList<>();
cmd.addAll(
Arrays.asList(
"java",
"-jar",
- AppCrawlTesterHostPreparer.getCrawlerBinPath(testInfo)
- .resolve("crawl_launcher_deploy.jar")
+ bin.resolve("utp-cli-android_deploy.jar").toString(),
+ "android",
+ "robo",
+ "--device-id",
+ testInfo.getDevice().getSerialNumber(),
+ "--app-id",
+ mPackageName,
+ "--controller-endpoint",
+ "PROD",
+ "--utp-binaries-dir",
+ bin.toString(),
+ "--key-file",
+ AppCrawlTesterHostPreparer.getCredentialPath(
+ mTestUtils.getTestInformation())
.toString(),
+ "--base-crawler-apk",
+ bin.resolve("crawler_app.apk").toString(),
+ "--stub-crawler-apk",
+ bin.resolve("crawler_stubapp_androidx.apk").toString(),
+ "--tmp-dir",
+ mOutput.toString()));
+
+ if (mTimeoutSec > 0) {
+ cmd.add("--crawler-flag");
+ cmd.add("crawlDurationSec=" + Integer.toString(mTimeoutSec));
+ }
+
+ if (mUiAutomatorMode) {
+ cmd.addAll(Arrays.asList("--ui-automator-mode", "--app-installed-on-device"));
+ } else {
+ Preconditions.checkNotNull(
+ mApkRoot, "Apk file path is required when not running in UIAutomator mode");
+
+ List<Path> apks;
+ try {
+ apks =
+ TestUtils.listApks(mApkRoot).stream()
+ .filter(
+ path ->
+ path.getFileName()
+ .toString()
+ .toLowerCase()
+ .endsWith(".apk"))
+ .collect(Collectors.toList());
+ } catch (TestUtilsException e) {
+ throw new CrawlerException(e);
+ }
+
+ cmd.add("--apks-to-crawl");
+ cmd.add(apks.stream().map(Path::toString).collect(Collectors.joining(",")));
+ }
+
+ if (mRoboscriptFile != null) {
+ Assert.assertTrue(
+ "Please provide a valid roboscript file.",
+ Files.isRegularFile(mRoboscriptFile));
+ cmd.add("--crawler-asset");
+ cmd.add("robo.script=" + mRoboscriptFile.toString());
+ }
+
+ if (mCrawlGuidanceProtoFile != null) {
+ Assert.assertTrue(
+ "Please provide a valid CrawlGuidance file.",
+ Files.isRegularFile(mCrawlGuidanceProtoFile));
+ cmd.add("--crawl-guidance-proto-path");
+ cmd.add(mCrawlGuidanceProtoFile.toString());
+ }
+
+ if (mLoginConfigDir != null) {
+ RoboLoginConfigProvider configProvider = new RoboLoginConfigProvider(mLoginConfigDir);
+ cmd.addAll(configProvider.findConfigFor(mPackageName, true).getLoginArgs());
+ }
+
+ return cmd.toArray(new String[cmd.size()]);
+ }
+
+ @VisibleForTesting
+ String[] createCrawlerRunCommand(TestInformation testInfo) throws CrawlerException {
+
+ Path bin =
+ mFileSystem.getPath(
+ AppCrawlTesterHostPreparer.getCrawlerBinPath(
+ mTestUtils.getTestInformation()));
+ ArrayList<String> cmd = new ArrayList<>();
+ cmd.addAll(
+ Arrays.asList(
+ "java",
+ "-jar",
+ bin.resolve("crawl_launcher_deploy.jar").toString(),
"--android-sdk-path",
AppCrawlTesterHostPreparer.getSdkPath(testInfo).toString(),
"--device-serial-code",
@@ -304,9 +424,7 @@ public final class AppCrawlTester {
mOutput.toString(),
"--key-store-file",
// Using the publicly known default file name of the debug keystore.
- AppCrawlTesterHostPreparer.getCrawlerBinPath(testInfo)
- .resolve("debug.keystore")
- .toString(),
+ bin.resolve("debug.keystore").toString(),
"--key-store-password",
// Using the publicly known default password of the debug keystore.
"android"));
@@ -366,8 +484,7 @@ public final class AppCrawlTester {
if (mLoginConfigDir != null) {
RoboLoginConfigProvider configProvider = new RoboLoginConfigProvider(mLoginConfigDir);
- RoboLoginConfig loginConfig = configProvider.findConfigFor(mPackageName);
- cmd.addAll(loginConfig.getLoginArgs());
+ cmd.addAll(configProvider.findConfigFor(mPackageName, false).getLoginArgs());
}
return cmd.toArray(new String[cmd.size()]);
diff --git a/harness/src/main/java/com/android/csuite/core/AppCrawlTesterHostPreparer.java b/harness/src/main/java/com/android/csuite/core/AppCrawlTesterHostPreparer.java
index 4be78f7..abb3de3 100644
--- a/harness/src/main/java/com/android/csuite/core/AppCrawlTesterHostPreparer.java
+++ b/harness/src/main/java/com/android/csuite/core/AppCrawlTesterHostPreparer.java
@@ -31,6 +31,8 @@ import com.google.common.io.MoreFiles;
import java.io.File;
import java.io.IOException;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -44,6 +46,7 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
@VisibleForTesting static final String SDK_TAR_OPTION = "sdk-tar";
@VisibleForTesting static final String CRAWLER_BIN_OPTION = "crawler-bin";
@VisibleForTesting static final String CREDENTIAL_JSON_OPTION = "credential-json";
+ private final FileSystem mFileSystem;
@Option(
name = SDK_TAR_OPTION,
@@ -66,12 +69,13 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
private RunUtilProvider mRunUtilProvider;
public AppCrawlTesterHostPreparer() {
- this(() -> new RunUtil());
+ this(() -> new RunUtil(), FileSystems.getDefault());
}
@VisibleForTesting
- AppCrawlTesterHostPreparer(RunUtilProvider runUtilProvider) {
+ AppCrawlTesterHostPreparer(RunUtilProvider runUtilProvider, FileSystem fileSystem) {
mRunUtilProvider = runUtilProvider;
+ mFileSystem = fileSystem;
}
/**
@@ -80,7 +84,7 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
* @param testInfo The test info where the path is stored in.
* @return The path to Android SDK; Null if not set.
*/
- public static Path getSdkPath(TestInformation testInfo) {
+ public static String getSdkPath(TestInformation testInfo) {
return getPathFromBuildInfo(testInfo, SDK_PATH_KEY);
}
@@ -90,7 +94,7 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
* @param testInfo The test info where the path is stored in.
* @return The path to the crawler binaries folder; Null if not set.
*/
- public static Path getCrawlerBinPath(TestInformation testInfo) {
+ public static String getCrawlerBinPath(TestInformation testInfo) {
return getPathFromBuildInfo(testInfo, CRAWLER_BIN_PATH_KEY);
}
@@ -100,7 +104,7 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
* @param testInfo The test info where the path is stored in.
* @return The path to the crawler credential json file.
*/
- public static Path getCredentialPath(TestInformation testInfo) {
+ public static String getCredentialPath(TestInformation testInfo) {
return getPathFromBuildInfo(testInfo, CREDENTIAL_PATH_KEY);
}
@@ -114,9 +118,8 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
return testInfo.getBuildInfo().getBuildAttributes().get(IS_READY_KEY) != null;
}
- private static Path getPathFromBuildInfo(TestInformation testInfo, String key) {
- String path = testInfo.getBuildInfo().getBuildAttributes().get(key);
- return path == null ? null : Path.of(path);
+ private static String getPathFromBuildInfo(TestInformation testInfo, String key) {
+ return testInfo.getBuildInfo().getBuildAttributes().get(key);
}
@VisibleForTesting
@@ -154,9 +157,13 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
setSdkPath(testInfo, sdkPath);
+ Path jar = mCrawlerBin.toPath().resolve("crawl_launcher_deploy.jar");
+ if (!Files.exists(jar)) {
+ jar = mCrawlerBin.toPath().resolve("utp-cli-android_deploy.jar");
+ }
+
// Make the crawler binary executable.
- String chmodCmd =
- "chmod 555 " + mCrawlerBin.toPath().resolve("crawl_launcher_deploy.jar").toString();
+ String chmodCmd = "chmod 555 " + jar.toString();
CommandResult chmodRes = runUtil.runTimedCmd(COMMAND_TIMEOUT_MILLIS, chmodCmd.split(" "));
if (!chmodRes.getStatus().equals(CommandStatus.SUCCESS)) {
throw new TargetSetupError(
@@ -173,7 +180,7 @@ public final class AppCrawlTesterHostPreparer implements ITargetPreparer {
@Override
public void tearDown(TestInformation testInfo, Throwable e) {
try {
- cleanUp(getSdkPath(testInfo));
+ cleanUp(mFileSystem.getPath(getSdkPath(testInfo)));
} catch (IOException ioException) {
CLog.e(ioException);
}
diff --git a/harness/src/main/java/com/android/csuite/core/RoboLoginConfig.java b/harness/src/main/java/com/android/csuite/core/RoboLoginConfig.java
deleted file mode 100644
index 0a37b3a..0000000
--- a/harness/src/main/java/com/android/csuite/core/RoboLoginConfig.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * 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.android.csuite.core;
-
-import com.google.common.collect.ImmutableList;
-
-/*
- * A class returned by RoboLoginConfigProvider that contains the login arguments
- * to be passed to the crawler.
- */
-public final class RoboLoginConfig {
- private final ImmutableList<String> mLoginArgs;
-
- public RoboLoginConfig(ImmutableList<String> loginArgs) {
- this.mLoginArgs = loginArgs;
- }
-
- /* Returns the login arguments for this config which can be passed to the crawler. */
- public ImmutableList<String> getLoginArgs() {
- return mLoginArgs;
- }
-}
diff --git a/harness/src/main/java/com/android/csuite/core/RoboLoginConfigProvider.java b/harness/src/main/java/com/android/csuite/core/RoboLoginConfigProvider.java
index 944e50f..2cfb4d0 100644
--- a/harness/src/main/java/com/android/csuite/core/RoboLoginConfigProvider.java
+++ b/harness/src/main/java/com/android/csuite/core/RoboLoginConfigProvider.java
@@ -45,20 +45,48 @@ public final class RoboLoginConfigProvider {
* directory should contain only one config file per package name. If both Roboscript and
* CrawlGuidance files are present, only the Roboscript file will be used."
*/
- public RoboLoginConfig findConfigFor(String packageName) {
+ public RoboLoginConfig findConfigFor(String packageName, boolean isUtpClient) {
Path crawlGuidanceFile = mLoginFilesDir.resolve(packageName + CRAWL_GUIDANCE_FILE_SUFFIX);
Path roboScriptFile = mLoginFilesDir.resolve(packageName + ROBOSCRIPT_FILE_SUFFIX);
- if (Files.exists(roboScriptFile)) {
+ if (Files.exists(roboScriptFile) && !isUtpClient) {
return new RoboLoginConfig(
ImmutableList.of(ROBOSCRIPT_CMD_FLAG, roboScriptFile.toString()));
}
- if (Files.exists(crawlGuidanceFile)) {
+ if (Files.exists(crawlGuidanceFile) && !isUtpClient) {
return new RoboLoginConfig(
ImmutableList.of(CRAWL_GUIDANCE_CMD_FLAG, crawlGuidanceFile.toString()));
}
+ if (Files.exists(roboScriptFile) && isUtpClient) {
+ return new RoboLoginConfig(
+ ImmutableList.of(
+ "--crawler-asset", "robo.script=" + roboScriptFile.toString()));
+ }
+
+ if (Files.exists(crawlGuidanceFile) && isUtpClient) {
+ return new RoboLoginConfig(
+ ImmutableList.of("--crawl-guidance-proto-path", crawlGuidanceFile.toString()));
+ }
+
return new RoboLoginConfig(ImmutableList.of());
}
+
+ /*
+ * A class returned by RoboLoginConfigProvider that contains the login arguments
+ * to be passed to the crawler.
+ */
+ public static final class RoboLoginConfig {
+ private final ImmutableList<String> mLoginArgs;
+
+ public RoboLoginConfig(ImmutableList<String> loginArgs) {
+ this.mLoginArgs = loginArgs;
+ }
+
+ /* Returns the login arguments for this config which can be passed to the crawler. */
+ public ImmutableList<String> getLoginArgs() {
+ return mLoginArgs;
+ }
+ }
}
diff --git a/harness/src/test/java/com/android/csuite/core/AppCrawlTesterHostPreparerTest.java b/harness/src/test/java/com/android/csuite/core/AppCrawlTesterHostPreparerTest.java
index 87762ea..7a060ea 100644
--- a/harness/src/test/java/com/android/csuite/core/AppCrawlTesterHostPreparerTest.java
+++ b/harness/src/test/java/com/android/csuite/core/AppCrawlTesterHostPreparerTest.java
@@ -56,14 +56,14 @@ public final class AppCrawlTesterHostPreparerTest {
Path path = Path.of("some");
AppCrawlTesterHostPreparer.setSdkPath(mTestInfo, path);
- Path result = AppCrawlTesterHostPreparer.getSdkPath(mTestInfo);
+ String result = AppCrawlTesterHostPreparer.getSdkPath(mTestInfo);
- assertThat(result.toString()).isEqualTo(path.toString());
+ assertThat(result).isEqualTo(path.toString());
}
@Test
public void getSdkPath_wasNotSet_returnsNull() {
- Path result = AppCrawlTesterHostPreparer.getSdkPath(mTestInfo);
+ String result = AppCrawlTesterHostPreparer.getSdkPath(mTestInfo);
assertNull(result);
}
@@ -73,14 +73,14 @@ public final class AppCrawlTesterHostPreparerTest {
Path path = Path.of("some");
AppCrawlTesterHostPreparer.setCrawlerBinPath(mTestInfo, path);
- Path result = AppCrawlTesterHostPreparer.getCrawlerBinPath(mTestInfo);
+ String result = AppCrawlTesterHostPreparer.getCrawlerBinPath(mTestInfo);
- assertThat(result.toString()).isEqualTo(path.toString());
+ assertThat(result).isEqualTo(path.toString());
}
@Test
public void getCrawlerBinPath_wasNotSet_returnsNull() {
- Path result = AppCrawlTesterHostPreparer.getCrawlerBinPath(mTestInfo);
+ String result = AppCrawlTesterHostPreparer.getCrawlerBinPath(mTestInfo);
assertNull(result);
}
@@ -90,14 +90,14 @@ public final class AppCrawlTesterHostPreparerTest {
Path path = Path.of("some");
AppCrawlTesterHostPreparer.setCredentialPath(mTestInfo, path);
- Path result = AppCrawlTesterHostPreparer.getCredentialPath(mTestInfo);
+ String result = AppCrawlTesterHostPreparer.getCredentialPath(mTestInfo);
- assertThat(result.toString()).isEqualTo(path.toString());
+ assertThat(result).isEqualTo(path.toString());
}
@Test
public void getCredentialPath_wasNotSet_returnsNull() {
- Path result = AppCrawlTesterHostPreparer.getCredentialPath(mTestInfo);
+ String result = AppCrawlTesterHostPreparer.getCredentialPath(mTestInfo);
assertNull(result);
}
@@ -143,7 +143,8 @@ public final class AppCrawlTesterHostPreparerTest {
}
private AppCrawlTesterHostPreparer createTestSubject() throws Exception {
- AppCrawlTesterHostPreparer suj = new AppCrawlTesterHostPreparer(() -> mRunUtil);
+ AppCrawlTesterHostPreparer suj =
+ new AppCrawlTesterHostPreparer(() -> mRunUtil, mFileSystem);
OptionSetter optionSetter = new OptionSetter(suj);
optionSetter.setOptionValue(
AppCrawlTesterHostPreparer.SDK_TAR_OPTION,
diff --git a/harness/src/test/java/com/android/csuite/core/AppCrawlTesterTest.java b/harness/src/test/java/com/android/csuite/core/AppCrawlTesterTest.java
index 6907307..67ff1cf 100644
--- a/harness/src/test/java/com/android/csuite/core/AppCrawlTesterTest.java
+++ b/harness/src/test/java/com/android/csuite/core/AppCrawlTesterTest.java
@@ -55,6 +55,7 @@ import java.util.Arrays;
@RunWith(JUnit4.class)
public final class AppCrawlTesterTest {
+ private static final String PACKAGE_NAME = "package.name";
private final TestArtifactReceiver mTestArtifactReceiver =
Mockito.mock(TestArtifactReceiver.class);
private final FileSystem mFileSystem =
@@ -228,14 +229,13 @@ public final class AppCrawlTesterTest {
}
@Test
- public void start_credentialIsProvidedToCrawler() throws Exception {
+ public void start_sdkPathIsProvidedToCrawler() throws Exception {
AppCrawlTester suj = createPreparedTestSubject();
suj.setApkPath(createApkPathWithSplitApks());
suj.start();
- Mockito.verify(mRunUtil)
- .setEnvVariable(Mockito.eq("GOOGLE_APPLICATION_CREDENTIALS"), Mockito.anyString());
+ Mockito.verify(mRunUtil).setEnvVariable(Mockito.eq("ANDROID_SDK"), Mockito.anyString());
}
@Test
@@ -361,7 +361,7 @@ public final class AppCrawlTesterTest {
}
@Test
- public void createCrawlerRunCommand_containsRequiredCrawlerParams() throws Exception {
+ public void createUtpCrawlerRunCommand_containsRequiredCrawlerParams() throws Exception {
Path apkRoot = mFileSystem.getPath("apk");
Files.createDirectories(apkRoot);
Files.createFile(apkRoot.resolve("some.apk"));
@@ -369,16 +369,20 @@ public final class AppCrawlTesterTest {
suj.setApkPath(apkRoot);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().contains("--key-store-file");
- assertThat(result).asList().contains("--key-store-password");
- assertThat(result).asList().contains("--device-serial-code");
- assertThat(result).asList().contains("--apk-file");
+ assertThat(result).asList().contains("android");
+ assertThat(result).asList().contains("robo");
+ assertThat(result).asList().contains("--device-id");
+ assertThat(result).asList().contains("--app-id");
+ assertThat(result).asList().contains("--utp-binaries-dir");
+ assertThat(result).asList().contains("--key-file");
+ assertThat(result).asList().contains("--base-crawler-apk");
+ assertThat(result).asList().contains("--stub-crawler-apk");
}
@Test
- public void createCrawlerRunCommand_containsRoboscriptFileWhenProvided() throws Exception {
+ public void createUtpCrawlerRunCommand_containsRoboscriptFileWhenProvided() throws Exception {
AppCrawlTester suj = createPreparedTestSubject();
Path roboDir = mFileSystem.getPath("/robo");
Files.createDirectory(roboDir);
@@ -387,27 +391,15 @@ public final class AppCrawlTesterTest {
suj.setRoboscriptFile(roboFile);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().contains("--robo-script-file");
+ assertThat(result).asList().contains("--crawler-asset");
+ assertThat(result).asList().contains("robo.script=" + roboFile.toString());
}
@Test
- public void createCrawlerRunCommand_containsEndpointWhenProvided() throws Exception {
- AppCrawlTester suj = createPreparedTestSubject();
- suj.setUiAutomatorMode(true);
- String endpoint = "abc@efg";
- suj.setCrawlControllerEndpoint(endpoint);
- suj.start();
-
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
-
- assertThat(result).asList().contains("--endpoint");
- assertThat(result).asList().contains(endpoint);
- }
-
- @Test
- public void createCrawlerRunCommand_containsCrawlGuidanceFileWhenProvided() throws Exception {
+ public void createUtpCrawlerRunCommand_containsCrawlGuidanceFileWhenProvided()
+ throws Exception {
AppCrawlTester suj = createPreparedTestSubject();
Path crawlGuideDir = mFileSystem.getPath("/cg");
Files.createDirectory(crawlGuideDir);
@@ -416,73 +408,71 @@ public final class AppCrawlTesterTest {
suj.setUiAutomatorMode(true);
suj.setCrawlGuidanceProtoFile(crawlGuideFile);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().contains("--text-guide-file");
+ assertThat(result).asList().contains("--crawl-guidance-proto-path");
}
@Test
- public void createCrawlerRunCommand_loginDirContainsOnlyCrawlGuidanceFile_addsFilePath()
+ public void createUtpCrawlerRunCommand_loginDirContainsOnlyCrawlGuidanceFile_addsFilePath()
throws Exception {
- String packageName = "app.package";
- AppCrawlTester suj = createPreparedTestSubject(packageName);
+ AppCrawlTester suj = createPreparedTestSubject();
Path loginFilesDir = mFileSystem.getPath("/login");
Files.createDirectory(loginFilesDir);
Path crawlGuideFile =
- Files.createFile(loginFilesDir.resolve(packageName + CRAWL_GUIDANCE_FILE_SUFFIX));
+ Files.createFile(loginFilesDir.resolve(PACKAGE_NAME + CRAWL_GUIDANCE_FILE_SUFFIX));
suj.setUiAutomatorMode(true);
suj.setLoginConfigDir(loginFilesDir);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().contains("--text-guide-file");
+ assertThat(result).asList().contains("--crawl-guidance-proto-path");
assertThat(result).asList().contains(crawlGuideFile.toString());
}
@Test
- public void createCrawlerRunCommand_loginDirContainsOnlyRoboscriptFile_addsFilePath()
+ public void createUtpCrawlerRunCommand_loginDirContainsOnlyRoboscriptFile_addsFilePath()
throws Exception {
- String packageName = "app.package";
- AppCrawlTester suj = createPreparedTestSubject(packageName);
+ AppCrawlTester suj = createPreparedTestSubject();
Path loginFilesDir = mFileSystem.getPath("/login");
Files.createDirectory(loginFilesDir);
Path roboscriptFile =
- Files.createFile(loginFilesDir.resolve(packageName + ROBOSCRIPT_FILE_SUFFIX));
+ Files.createFile(loginFilesDir.resolve(PACKAGE_NAME + ROBOSCRIPT_FILE_SUFFIX));
suj.setUiAutomatorMode(true);
suj.setLoginConfigDir(loginFilesDir);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().contains("--robo-script-file");
- assertThat(result).asList().contains(roboscriptFile.toString());
+ assertThat(result).asList().contains("--crawler-asset");
+ assertThat(result).asList().contains("robo.script=" + roboscriptFile.toString());
}
@Test
- public void createCrawlerRunCommand_loginDirContainsMultipleLoginFiles_addsRoboscriptFilePath()
- throws Exception {
- String packageName = "app.package";
- AppCrawlTester suj = createPreparedTestSubject(packageName);
+ public void
+ createUtpCrawlerRunCommand_loginDirContainsMultipleLoginFiles_addsRoboscriptFilePath()
+ throws Exception {
+ AppCrawlTester suj = createPreparedTestSubject();
Path loginFilesDir = mFileSystem.getPath("/login");
Files.createDirectory(loginFilesDir);
Path roboscriptFile =
- Files.createFile(loginFilesDir.resolve(packageName + ROBOSCRIPT_FILE_SUFFIX));
+ Files.createFile(loginFilesDir.resolve(PACKAGE_NAME + ROBOSCRIPT_FILE_SUFFIX));
Path crawlGuideFile =
- Files.createFile(loginFilesDir.resolve(packageName + CRAWL_GUIDANCE_FILE_SUFFIX));
+ Files.createFile(loginFilesDir.resolve(PACKAGE_NAME + CRAWL_GUIDANCE_FILE_SUFFIX));
suj.setUiAutomatorMode(true);
suj.setLoginConfigDir(loginFilesDir);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().contains("--robo-script-file");
- assertThat(result).asList().contains(roboscriptFile.toString());
+ assertThat(result).asList().contains("--crawler-asset");
+ assertThat(result).asList().contains("robo.script=" + roboscriptFile.toString());
assertThat(result).asList().doesNotContain(crawlGuideFile.toString());
}
@Test
- public void createCrawlerRunCommand_loginDirEmpty_doesNotAddFlag() throws Exception {
+ public void createUtpCrawlerRunCommand_loginDirEmpty_doesNotAddFlag() throws Exception {
AppCrawlTester suj = createPreparedTestSubject();
Path loginFilesDir = mFileSystem.getPath("/login");
Files.createDirectory(loginFilesDir);
@@ -490,14 +480,14 @@ public final class AppCrawlTesterTest {
suj.setUiAutomatorMode(true);
suj.setLoginConfigDir(loginFilesDir);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(result).asList().doesNotContain("--robo-script-file");
- assertThat(result).asList().doesNotContain("--text-guide-file");
+ assertThat(result).asList().doesNotContain("--crawler-asset");
+ assertThat(result).asList().doesNotContain("--crawl-guidance-proto-path");
}
@Test
- public void createCrawlerRunCommand_crawlerIsExecutedThroughJavaJar() throws Exception {
+ public void createUtpCrawlerRunCommand_crawlerIsExecutedThroughJavaJar() throws Exception {
Path apkRoot = mFileSystem.getPath("apk");
Files.createDirectories(apkRoot);
Files.createFile(apkRoot.resolve("some.apk"));
@@ -505,14 +495,14 @@ public final class AppCrawlTesterTest {
suj.setApkPath(apkRoot);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
assertThat(result).asList().contains("java");
assertThat(result).asList().contains("-jar");
}
@Test
- public void createCrawlerRunCommand_splitApksProvided_useApkFileAndSplitApkFilesParams()
+ public void createUtpCrawlerRunCommand_splitApksProvided_useApkFileAndSplitApkFilesParams()
throws Exception {
Path apkRoot = mFileSystem.getPath("apk");
Files.createDirectories(apkRoot);
@@ -523,19 +513,16 @@ public final class AppCrawlTesterTest {
suj.setApkPath(apkRoot);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(Arrays.asList(result).stream().filter(s -> s.equals("--apk-file")).count())
+ assertThat(Arrays.asList(result).stream().filter(s -> s.equals("--apks-to-crawl")).count())
+ .isEqualTo(1);
+ assertThat(Arrays.asList(result).stream().filter(s -> s.contains("config1.apk")).count())
.isEqualTo(1);
- assertThat(
- Arrays.asList(result).stream()
- .filter(s -> s.equals("--split-apk-files"))
- .count())
- .isEqualTo(2);
}
@Test
- public void createCrawlerRunCommand_uiAutomatorModeEnabled_doesNotContainApks()
+ public void createUtpCrawlerRunCommand_uiAutomatorModeEnabled_doesNotContainApks()
throws Exception {
Path apkRoot = mFileSystem.getPath("apk");
Files.createDirectories(apkRoot);
@@ -547,19 +534,14 @@ public final class AppCrawlTesterTest {
suj.setUiAutomatorMode(true);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
- assertThat(Arrays.asList(result).stream().filter(s -> s.equals("--apk-file")).count())
- .isEqualTo(0);
- assertThat(
- Arrays.asList(result).stream()
- .filter(s -> s.equals("--split-apk-files"))
- .count())
+ assertThat(Arrays.asList(result).stream().filter(s -> s.equals("--apks-to-crawl")).count())
.isEqualTo(0);
}
@Test
- public void createCrawlerRunCommand_uiAutomatorModeEnabled_containsUiAutomatorParam()
+ public void createUtpCrawlerRunCommand_uiAutomatorModeEnabled_containsUiAutomatorParam()
throws Exception {
Path apkRoot = mFileSystem.getPath("apk");
Files.createDirectories(apkRoot);
@@ -571,7 +553,7 @@ public final class AppCrawlTesterTest {
suj.setUiAutomatorMode(true);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
assertThat(
Arrays.asList(result).stream()
@@ -580,13 +562,13 @@ public final class AppCrawlTesterTest {
.isEqualTo(1);
assertThat(
Arrays.asList(result).stream()
- .filter(s -> s.equals("--app-package-name"))
+ .filter(s -> s.equals("--app-installed-on-device"))
.count())
.isEqualTo(1);
}
@Test
- public void createCrawlerRunCommand_doesNotContainNullOrEmptyStrings() throws Exception {
+ public void createUtpCrawlerRunCommand_doesNotContainNullOrEmptyStrings() throws Exception {
Path apkRoot = mFileSystem.getPath("apk");
Files.createDirectories(apkRoot);
Files.createFile(apkRoot.resolve("base.apk"));
@@ -596,10 +578,9 @@ public final class AppCrawlTesterTest {
suj.setApkPath(apkRoot);
suj.start();
- String[] result = suj.createCrawlerRunCommand(mTestInfo);
+ String[] result = suj.createUtpCrawlerRunCommand(mTestInfo);
assertThat(Arrays.asList(result).stream().filter(s -> s == null).count()).isEqualTo(0);
-
assertThat(Arrays.asList(result).stream().map(String::trim).filter(String::isEmpty).count())
.isEqualTo(0);
}
@@ -609,17 +590,20 @@ public final class AppCrawlTesterTest {
IRunUtil runUtil = Mockito.mock(IRunUtil.class);
Mockito.when(runUtil.runTimedCmd(Mockito.anyLong(), ArgumentMatchers.<String>any()))
.thenReturn(createSuccessfulCommandResult());
- AppCrawlTesterHostPreparer preparer = new AppCrawlTesterHostPreparer(() -> runUtil);
+ AppCrawlTesterHostPreparer preparer =
+ new AppCrawlTesterHostPreparer(() -> runUtil, mFileSystem);
OptionSetter optionSetter = new OptionSetter(preparer);
+
+ Path bin = Files.createDirectories(mFileSystem.getPath("/bin"));
+ Files.createFile(bin.resolve("utp-cli-android_deploy.jar"));
+
optionSetter.setOptionValue(
AppCrawlTesterHostPreparer.SDK_TAR_OPTION,
- Files.createDirectories(mFileSystem.getPath("sdk")).toString());
- optionSetter.setOptionValue(
- AppCrawlTesterHostPreparer.CRAWLER_BIN_OPTION,
- Files.createDirectories(mFileSystem.getPath("bin")).toString());
+ Files.createDirectories(mFileSystem.getPath("/sdk")).toString());
+ optionSetter.setOptionValue(AppCrawlTesterHostPreparer.CRAWLER_BIN_OPTION, bin.toString());
optionSetter.setOptionValue(
AppCrawlTesterHostPreparer.CREDENTIAL_JSON_OPTION,
- Files.createDirectories(mFileSystem.getPath("cred.json")).toString());
+ Files.createDirectories(mFileSystem.getPath("/cred.json")).toString());
preparer.setUp(mTestInfo);
}
@@ -627,23 +611,14 @@ public final class AppCrawlTesterTest {
Mockito.when(mRunUtil.runTimedCmd(Mockito.anyLong(), ArgumentMatchers.<String>any()))
.thenReturn(createSuccessfulCommandResult());
Mockito.when(mDevice.getSerialNumber()).thenReturn("serial");
- return new AppCrawlTester("package.name", mTestUtils, () -> mRunUtil);
+ return new AppCrawlTester(PACKAGE_NAME, mTestUtils, () -> mRunUtil, mFileSystem);
}
-
private AppCrawlTester createPreparedTestSubject()
throws IOException, ConfigurationException, TargetSetupError {
simulatePreparerWasExecutedSuccessfully();
Mockito.when(mRunUtil.runTimedCmd(Mockito.anyLong(), ArgumentMatchers.<String>any()))
.thenReturn(createSuccessfulCommandResult());
- return new AppCrawlTester("package.name", mTestUtils, () -> mRunUtil);
- }
-
- private AppCrawlTester createPreparedTestSubject(String packageName)
- throws IOException, ConfigurationException, TargetSetupError {
- simulatePreparerWasExecutedSuccessfully();
- Mockito.when(mRunUtil.runTimedCmd(Mockito.anyLong(), ArgumentMatchers.<String>any()))
- .thenReturn(createSuccessfulCommandResult());
- return new AppCrawlTester(packageName, mTestUtils, () -> mRunUtil);
+ return new AppCrawlTester(PACKAGE_NAME, mTestUtils, () -> mRunUtil, mFileSystem);
}
private TestUtils createTestUtils() throws DeviceNotAvailableException {