diff options
author | dyu <dyu@google.com> | 2017-05-02 21:35:45 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-05-02 21:35:47 +0000 |
commit | fa8fa49af590d449a4f7af7e6406be200b5855e8 (patch) | |
tree | 44e30a071461ca3c986168a8df3ed34713f788e5 | |
parent | 2f5fa33d66e09b0841b78ba92b83f716f00e8d0c (diff) | |
parent | a663e8a589ff590b2a378b1965764a8c77adcd6f (diff) | |
download | adt-infra-fa8fa49af590d449a4f7af7e6406be200b5855e8.tar.gz |
Merge "Add two system image UI tests for Play Store." into emu-master-dev
-rw-r--r-- | system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java | 124 | ||||
-rw-r--r-- | system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java | 2 | ||||
-rw-r--r-- | system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java | 36 | ||||
-rw-r--r-- | system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java (renamed from system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java) | 41 |
4 files changed, 166 insertions, 37 deletions
diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java index 34e43559..45b9a062 100644 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java +++ b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java @@ -19,9 +19,7 @@ package com.android.devtools.systemimage.uitest.smoke; import android.app.Instrumentation; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.UiDevice; -import android.support.test.uiautomator.UiObject; import android.support.test.uiautomator.UiObjectNotFoundException; -import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import com.android.devtools.systemimage.uitest.annotations.TestInfo; @@ -29,7 +27,7 @@ import com.android.devtools.systemimage.uitest.common.Res; import com.android.devtools.systemimage.uitest.framework.SystemImageTestFramework; import com.android.devtools.systemimage.uitest.utils.PlayStoreUtil; import com.android.devtools.systemimage.uitest.utils.Wait; -import com.android.devtools.systemimage.uitest.unittest.watchers.PlayStoreConfirmationWatcher; +import com.android.devtools.systemimage.uitest.watchers.PlayStoreConfirmationWatcher; import org.junit.Ignore; import org.junit.Rule; @@ -65,6 +63,7 @@ public class PlayStoreTest { * 3. Confirm that Play Store is present, then launch. * 5. Search for free app in store. * 6. If app is available for install, begin installation. + * 7. Uninstall the app. * Verify: * 1a. If Install button is displayed, allow installation to complete then * confirm that the Open button to launch the app is present. @@ -98,6 +97,125 @@ public class PlayStoreTest { assertTrue("Unable to uninstall the application from Google Play", PlayStoreUtil.uninstallApplication(instrumentation)); + + PlayStoreUtil.resetPlayStore(instrumentation); + device.pressHome(); + } + } + } + + /** + * Verify that an app can be installed and launched from Play Store. + * <p> + * TR ID: C14603433 + * <p> + * <pre> + * Test Steps: + * 1. Start an emulator and launch home screen. + * 2. Open Apps. + * 3. Confirm that Play Store is present, then launch. + * 5. Search for free app in store. + * 6. If app is available for install, begin installation. + * 7. Launch the application. + * 7. Close and uninstall the app. + * Verify: + * 1. App is installed without errors. + * 2. App is launched without errors. + * </pre> + */ + @Ignore("Testing play store requires google login that may trigger 2-auth factor. Test to be initiated manually by tester.") + @Test + @TestInfo(id = "14578827") + public void testAppInstallationAndLaunch() throws Exception { + Instrumentation instrumentation = testFramework.getInstrumentation(); + final UiDevice device = UiDevice.getInstance(instrumentation); + final String application = "Trello"; + + if (testFramework.getApi() >= 24 && testFramework.isGoogleApiImage()) { + device.pressHome(); + device.findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow(); + + boolean playStoreInstalled = PlayStoreUtil.isPlayStoreInstalled(instrumentation); + + if (playStoreInstalled) { + PlayStoreUtil.searchGooglePlay(instrumentation, application); + PlayStoreUtil.selectFromGooglePlay( + instrumentation, "App: "+application); + + new PlayStoreConfirmationWatcher(device).checkForCondition(); + + assertTrue("Unable to install the application from Google Play", + PlayStoreUtil.installApplication(instrumentation)); + + device.findObject(new UiSelector().text("OPEN")).clickAndWaitForNewWindow(); + assertTrue("App could not be opened", + new Wait().until(new Wait.ExpectedCondition() { + @Override + public boolean isTrue() throws UiObjectNotFoundException { + return device.findObject(new UiSelector() + .packageName("com.trello")).exists(); + } + })); + + device.pressBack(); + + assertTrue("Unable to uninstall the application from Google Play", + PlayStoreUtil.uninstallApplication(instrumentation)); + + PlayStoreUtil.resetPlayStore(instrumentation); + device.pressHome(); + } + } + } + + /** + * Verify that Google Play can reach the payment method prompt during paid app installation. + * <p> + * TR ID: C14603432 + * <p> + * <pre> + * Test Steps: + * 1. Start an emulator and launch home screen. + * 2. Open Apps. + * 3. Confirm that Play Store is present, then launch. + * 4. Search for pay app in store. + * Verify: + * 1. Confirm that user is presented with a Pay Button with a $. + * </pre> + */ + @Ignore("Testing play store requires google login that may trigger 2-auth factor. Test to be initiated manually by tester.") + @Test + @TestInfo(id = "14578827") + public void testPayAppVerification() throws Exception { + Instrumentation instrumentation = testFramework.getInstrumentation(); + final UiDevice device = UiDevice.getInstance(instrumentation); + final String application = "Weather Live"; + + if (testFramework.getApi() >= 24 && testFramework.isGoogleApiImage()) { + device.pressHome(); + device.findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow(); + + boolean playStoreInstalled = PlayStoreUtil.isPlayStoreInstalled(instrumentation); + + if (playStoreInstalled) { + PlayStoreUtil.searchGooglePlay(instrumentation, application); + PlayStoreUtil.selectFromGooglePlay(instrumentation, "App: "+application); + + new PlayStoreConfirmationWatcher(device).checkForCondition(); + + assertTrue( + "Target application is not a pay app", new Wait().until( + new Wait.ExpectedCondition() { + @Override + public boolean isTrue() throws UiObjectNotFoundException { + return device.findObject(new UiSelector() + .resourceId( + Res.GOOGLE_PLAY_BUY_BUTTON_RES).textContains("$")).exists(); + } + })); + + PlayStoreUtil.resetPlayStore(instrumentation); + device.pressHome(); } } } diff --git a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java index 32da225a..f852b00e 100644 --- a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java +++ b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java @@ -71,8 +71,8 @@ public class Res { public static final String GOOGLE_PLAY_IDLE_RES = "com.android.vending:id/search_box_idle_text"; public static final String GOOGLE_PLAY_INPUT_RES = "com.android.vending:id/search_box_text_input"; - public static final String GOOGLE_PLAY_NAV_RES = "com.android.vending:id/navigation_button"; public static final String GOOGLE_PLAY_BUY_BUTTON_RES = "com.android.vending:id/buy_button"; + public static final String GOOGLE_PLAY_CONTINUE_BUTTON_RES = "com.android.vending:id/continue_button"; public static final String DIALER_BUTTON_RES = "com.android.dialer:id/dialpad_floating_action_button"; diff --git a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java index 3fbc99ba..91eb4f62 100644 --- a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java +++ b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java @@ -24,6 +24,7 @@ import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import com.android.devtools.systemimage.uitest.common.Res; +import com.android.devtools.systemimage.uitest.watchers.PlayStoreConfirmationWatcher; import java.util.concurrent.TimeUnit; @@ -61,28 +62,28 @@ public class PlayStoreUtil { } /** - * Launches Google Play and then searches for an application + * Backtracks to the opening Play Store screen. + */ + public static void resetPlayStore(Instrumentation instrumentation) { + final UiDevice device = UiDevice.getInstance(instrumentation); + + for (int i = 0; i < 5; i++) { + device.pressBack(); + } + } + + /** + * Launches Play Store and then searches for an application. */ public static void searchGooglePlay(Instrumentation instrumentation, String appName) throws Exception { final UiDevice device = UiDevice.getInstance(instrumentation); final String playStore = "Play Store"; final String application = appName; - device.findObject(new UiSelector().text(playStore)).clickAndWaitForNewWindow(); - boolean backButtonExists = new Wait().until(new Wait.ExpectedCondition() { - @Override - public boolean isTrue() throws UiObjectNotFoundException { - return device.findObject( - new UiSelector().resourceId(Res.GOOGLE_PLAY_NAV_RES) - .description("Back")).exists(); - } - }); - - if (backButtonExists) { - device.findObject( - new UiSelector().resourceId(Res.GOOGLE_PLAY_NAV_RES) - .description("Back")).click(); - } + device.findObject(new UiSelector().text(playStore)).clickAndWaitForNewWindow(); + resetPlayStore(instrumentation); + device.pressHome(); + device.findObject(new UiSelector().text(playStore)).clickAndWaitForNewWindow(); boolean idleTextFieldExists = new Wait().until(new Wait.ExpectedCondition() { @Override @@ -115,7 +116,7 @@ public class PlayStoreUtil { } /** - * Selects an application listed in Google Play + * Selects an application listed in the Play Store. */ public static void selectFromGooglePlay(Instrumentation instrumentation, String appDescription) throws Exception { final UiDevice device = UiDevice.getInstance(instrumentation); @@ -162,6 +163,7 @@ public class PlayStoreUtil { } device.findObject(new UiSelector().text("INSTALL")).clickAndWaitForNewWindow(); + new PlayStoreConfirmationWatcher(device).checkForCondition(); UiObject openButton = device.findObject(new UiSelector().text("OPEN")); boolean isAppInstalled = openButton.waitForExists(TimeUnit.SECONDS.toMillis(60)); diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java index ff203529..b4b7c627 100644 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java +++ b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java @@ -14,17 +14,14 @@ * limitations under the License. */ -package com.android.devtools.systemimage.uitest.unittest.watchers; - +package com.android.devtools.systemimage.uitest.watchers; 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.UiWatcher; -import com.android.devtools.systemimage.uitest.common.Res; -import com.android.devtools.systemimage.uitest.utils.Wait; +import java.util.concurrent.TimeUnit; /** * VPN app popup watcher that monitors and dismisses the VPN popup dialog. @@ -40,21 +37,33 @@ public class PlayStoreConfirmationWatcher implements UiWatcher { @Override public boolean checkForCondition() { - UiObject confirmBox = mDevice.findObject(new UiSelector().text("CONFIRM")); - UiObject okBox = mDevice.findObject(new UiSelector().text("OK")); + boolean condition = false; + boolean isSuccess = + mDevice.findObject(new UiSelector().text("CONTINUE")) + .waitForExists(TimeUnit.MILLISECONDS.convert(3L, TimeUnit.SECONDS)); try { - if (confirmBox.exists()) { - confirmBox.click(); + if (isSuccess) { + mDevice.findObject(new UiSelector().text("CONTINUE")).click(); + condition = true; } - if (okBox.exists()) { - okBox.click(); - return true; + isSuccess = + mDevice.findObject(new UiSelector().text("CONFIRM")) + .waitForExists(TimeUnit.MILLISECONDS.convert(3L, TimeUnit.SECONDS)); + if (isSuccess) { + mDevice.findObject(new UiSelector().text("CONFIRM")).click(); + condition = true; } - else { - return false; + isSuccess = + mDevice.findObject(new UiSelector().text("SKIP")) + .waitForExists(TimeUnit.MILLISECONDS.convert(3L, TimeUnit.SECONDS)); + if (isSuccess) { + mDevice.findObject(new UiSelector().text("SKIP")).click(); + condition = true; } - } catch (UiObjectNotFoundException e) { - throw new AssertionError("Failed to dismiss the VPN popup dialog"); } + catch (UiObjectNotFoundException e) { + throw new AssertionError("Failed to dismiss the play store popup dialogs"); + } + return condition; } }
\ No newline at end of file |