|
@@ -0,0 +1,98 @@
|
|
|
+
|
|
|
+ * ownCloud Android client application
|
|
|
+ *
|
|
|
+ * Copyright (C) 2015 ownCloud Inc.
|
|
|
+ *
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License version 2,
|
|
|
+ * as published by the Free Software Foundation.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http:
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+package com.owncloud.android.uiautomator;
|
|
|
+
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.content.pm.ResolveInfo;
|
|
|
+import android.support.test.InstrumentationRegistry;
|
|
|
+import android.support.test.filters.SdkSuppress;
|
|
|
+import android.support.test.runner.AndroidJUnit4;
|
|
|
+import android.support.test.uiautomator.By;
|
|
|
+import android.support.test.uiautomator.UiDevice;
|
|
|
+import android.support.test.uiautomator.Until;
|
|
|
+
|
|
|
+
|
|
|
+import static org.hamcrest.CoreMatchers.notNullValue;
|
|
|
+import static org.junit.Assert.assertThat;
|
|
|
+
|
|
|
+
|
|
|
+ * UI Automator test to launch the owncloud app through the system
|
|
|
+ */
|
|
|
+@RunWith(AndroidJUnit4.class)
|
|
|
+@SdkSuppress(minSdkVersion = 18)
|
|
|
+public class LaunchAppTest {
|
|
|
+
|
|
|
+ private static final String OWNCLOUD_APP_PACKAGE = "com.owncloud.android";
|
|
|
+
|
|
|
+ private static final int LAUNCH_TIMEOUT = 5000;
|
|
|
+
|
|
|
+ private UiDevice mDevice;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void startMainActivityFromHomeScreen() {
|
|
|
+
|
|
|
+ mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
|
|
+
|
|
|
+
|
|
|
+ mDevice.pressHome();
|
|
|
+
|
|
|
+
|
|
|
+ final String launcherPackage = getLauncherPackageName();
|
|
|
+ assertThat(launcherPackage, notNullValue());
|
|
|
+ mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
|
|
|
+
|
|
|
+
|
|
|
+ Context context = InstrumentationRegistry.getContext();
|
|
|
+ final Intent intent = context.getPackageManager()
|
|
|
+ .getLaunchIntentForPackage(OWNCLOUD_APP_PACKAGE);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
+ context.startActivity(intent);
|
|
|
+
|
|
|
+
|
|
|
+ mDevice.wait(Until.hasObject(By.pkg(OWNCLOUD_APP_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void checkPreconditions() {
|
|
|
+ assertThat(mDevice, notNullValue());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Uses package manager to find the package name of the device launcher. Usually this package
|
|
|
+ * is "com.android.launcher" but can be different at times. This is a generic solution which
|
|
|
+ * works on all platforms.`
|
|
|
+ */
|
|
|
+ private String getLauncherPackageName() {
|
|
|
+
|
|
|
+ final Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
+ intent.addCategory(Intent.CATEGORY_HOME);
|
|
|
+
|
|
|
+
|
|
|
+ PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
|
|
|
+ ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
|
+ return resolveInfo.activityInfo.packageName;
|
|
|
+ }
|
|
|
+}
|