summaryrefslogtreecommitdiff
path: root/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java
blob: 45b9a06224c1b1882c6b40a7b2affa66e02caf10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * Copyright (c) 2016 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.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.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;

import com.android.devtools.systemimage.uitest.annotations.TestInfo;
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.watchers.PlayStoreConfirmationWatcher;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertTrue;

/**
 * Test to verify that Play Store services are available on Google API with Play Store images.
 */

@RunWith(AndroidJUnit4.class)
public class PlayStoreTest {
    private static final String WIDGET_TEXT_VIEW_CLASS = "android.widget.TextView";

    @Rule
    public final SystemImageTestFramework testFramework = new SystemImageTestFramework();

    @Rule
    public Timeout globalTimeout = Timeout.seconds(120);

    /**
     * Verify that Google Play can install and uninstall a free app on the device.
     * <p>
     * TR ID: C14578827
     * <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. 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.
     *      1b. If Install button is not displayed, confirm that the Open button to
     *      launch the app is present.
     *      2. Confirm that the app was subsequently uninstalled.
     *   </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 testAppInstallation() throws Exception {
        Instrumentation instrumentation = testFramework.getInstrumentation();
        final UiDevice device = UiDevice.getInstance(instrumentation);
        final String application = "Google Translate";

        if (testFramework.getApi() >= 24 && testFramework.isGoogleApiAndPlayImage()) {
            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));

                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();
            }
        }
    }
}