|
@@ -1,20 +1,19 @@
|
|
|
/**
|
|
|
- * 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://www.gnu.org/licenses/>.
|
|
|
- *
|
|
|
+ * ownCloud Android client application
|
|
|
+ * <p/>
|
|
|
+ * Copyright (C) 2015 ownCloud Inc.
|
|
|
+ * <p/>
|
|
|
+ * 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.
|
|
|
+ * <p/>
|
|
|
+ * 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.
|
|
|
+ * <p/>
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
package com.owncloud.android.uiautomator;
|
|
@@ -32,6 +31,9 @@ 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.UiObject;
|
|
|
+import android.support.test.uiautomator.UiObjectNotFoundException;
|
|
|
+import android.support.test.uiautomator.UiSelector;
|
|
|
import android.support.test.uiautomator.Until;
|
|
|
|
|
|
|
|
@@ -39,23 +41,37 @@ import static org.hamcrest.CoreMatchers.notNullValue;
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
|
/**
|
|
|
- * UI Automator test to launch the owncloud app through the system
|
|
|
+ * UI Automator tests
|
|
|
*/
|
|
|
@RunWith(AndroidJUnit4.class)
|
|
|
@SdkSuppress(minSdkVersion = 18)
|
|
|
-public class LaunchAppTest {
|
|
|
+public class InitialTest {
|
|
|
|
|
|
private static final String OWNCLOUD_APP_PACKAGE = "com.owncloud.android";
|
|
|
+ private static final String ANDROID_SETTINGS_PACKAGE = "com.android.settings";
|
|
|
+
|
|
|
|
|
|
private static final int LAUNCH_TIMEOUT = 5000;
|
|
|
|
|
|
private UiDevice mDevice;
|
|
|
|
|
|
@Before
|
|
|
- public void startMainActivityFromHomeScreen() {
|
|
|
+ public void initializeDevice() {
|
|
|
// Initialize UiDevice instance
|
|
|
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void checkPreconditions() {
|
|
|
+ assertThat(mDevice, notNullValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Start owncloud app
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void startAppFromHomeScreen() {
|
|
|
// Perform a short press on the HOME button
|
|
|
mDevice.pressHome();
|
|
|
|
|
@@ -75,9 +91,30 @@ public class LaunchAppTest {
|
|
|
mDevice.wait(Until.hasObject(By.pkg(OWNCLOUD_APP_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Start Settings app
|
|
|
+ *
|
|
|
+ * @throws UiObjectNotFoundException
|
|
|
+ */
|
|
|
@Test
|
|
|
- public void checkPreconditions() {
|
|
|
- assertThat(mDevice, notNullValue());
|
|
|
+ public void startSettingsFromHomeScreen() throws UiObjectNotFoundException {
|
|
|
+
|
|
|
+ mDevice.pressHome();
|
|
|
+
|
|
|
+ // Wait for launcher
|
|
|
+ final String launcherPackage = getLauncherPackageName();
|
|
|
+ assertThat(launcherPackage, notNullValue());
|
|
|
+ mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
|
|
|
+
|
|
|
+ // Launch the app
|
|
|
+ Context context = InstrumentationRegistry.getContext();
|
|
|
+ final Intent intent = context.getPackageManager()
|
|
|
+ .getLaunchIntentForPackage(ANDROID_SETTINGS_PACKAGE);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
+ context.startActivity(intent);
|
|
|
+
|
|
|
+ clickByText("Data usage");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -95,4 +132,26 @@ public class LaunchAppTest {
|
|
|
ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
|
return resolveInfo.activityInfo.packageName;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Helper to click on objects that match the content-description text
|
|
|
+ *
|
|
|
+ * @param text
|
|
|
+ * @throws UiObjectNotFoundException
|
|
|
+ */
|
|
|
+ private void clickByDescription(String text) throws UiObjectNotFoundException {
|
|
|
+ UiObject obj = new UiObject(new UiSelector().description(text));
|
|
|
+ obj.clickAndWaitForNewWindow();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Helper to click on object that match the text value
|
|
|
+ *
|
|
|
+ * @param text
|
|
|
+ * @throws UiObjectNotFoundException
|
|
|
+ */
|
|
|
+ private void clickByText(String text) throws UiObjectNotFoundException {
|
|
|
+ UiObject obj = new UiObject(new UiSelector().text(text));
|
|
|
+ obj.clickAndWaitForNewWindow();
|
|
|
+ }
|
|
|
}
|