summaryrefslogtreecommitdiff
path: root/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/MapsTest.java
blob: b7daf59594186e10d6ae6ec09c019c608371efb9 (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
/*
* 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.UiObject;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

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.AppLauncher;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.TimeUnit;

/**
 * Sanity test for Maps App
 */

@RunWith(AndroidJUnit4.class)
public class MapsTest {
    private static final String QUERY_STRING = "San Francisco";

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

    /**
     * Verify the functionality of navigation overview in Google Maps app.
     * <p>
     * This is run to qualify releases. Please involve the test team in substantial changes.
     * <p>
     * TR ID: T145493594
     * <p>
     * <pre>
     *   Test Steps:
     *   1. Launch emulator avd.
     *   2. Open Maps app.
     *   3. Accept terms and condition.
     *   4. Tap on search bar.
     *   5. Enter search query, "San Francisco", select it from the auto fill results.
     *   6. "San Francisco" location card opens.
     *   7. Select "San Francisco".
     *   8. Tap on the Drive icon.
     *   Verify:
     *   1. Map points to San Francisco location.
     *   2. Navigation overview is displayed.
     *   </pre>
     */
    @Test
    @TestInfo(id = "145493594")
    public void testMapsApp() throws Exception {
        Instrumentation instrumentation = testFramework.getInstrumentation();
        UiDevice mDevice = testFramework.getDevice();

        AppLauncher.launch(instrumentation, "Maps");
        UiObject acceptButton =
                mDevice.findObject(new UiSelector().textContains("ACCEPT & CONTINUE"));

        // "Accept & Continue" occurs only on first time Maps gets launched.
        if (acceptButton.exists()) {
            acceptButton.clickAndWaitForNewWindow();
        }

        // SKIP button only exist's occurs only on first time Maps gets launched.
        UiObject skipText = mDevice.findObject(new UiSelector().textContains("SKIP"));
        if (skipText.exists()) {
            skipText.clickAndWaitForNewWindow();
        }

        // "Got IT" only exist's only on first time Maps gets launched.
        UiObject gotItTutorialButton = mDevice.findObject(new UiSelector().textContains("GOT IT"));
        if (gotItTutorialButton.exists()) {
            gotItTutorialButton.clickAndWaitForNewWindow();
        }

        UiObject searchUiObject = mDevice.findObject(new UiSelector().
                resourceIdMatches(Res.SEARCH_TEXT_BOX));

        // Adding extra wait to avoid the system freeze on API 24.
        searchUiObject.waitForExists(TimeUnit.SECONDS.toMillis(3L));
        searchUiObject.clickAndWaitForNewWindow();

        UiObject searchEditText;
        UiObject selectedLocation;

        if(testFramework.getApi() > 19) {
            searchEditText =
                    searchUiObject.getChild(new UiSelector().className(EditText.class.getName()));
            searchEditText.setText(QUERY_STRING);
            UiScrollable scrollView =
                    new UiScrollable(new UiSelector().className(ScrollView.class.getName()));
            scrollView.scrollIntoView(new UiSelector().text(QUERY_STRING));
            selectedLocation =
                    scrollView.getChildByText(new UiSelector()
                            .className(TextView.class.getName()), QUERY_STRING);
            Assert.assertTrue(selectedLocation.exists());
            selectedLocation.clickAndWaitForNewWindow();

            // Verify the Query String is present after completing search.
            UiObject searchTextView =
                    searchUiObject.getChild(new UiSelector().className(TextView.class.getName()));
            Assert.assertTrue(searchTextView.getText().contains(QUERY_STRING));
        } else {
            searchEditText =
                    mDevice.findObject(new UiSelector().className(EditText.class.getName()));
            searchEditText.setText(QUERY_STRING);
            UiScrollable listViewSelector =
                    new UiScrollable(new UiSelector().className(ListView.class.getName()));
            selectedLocation =
                    listViewSelector.getChildByText(new UiSelector()
                            .className(TextView.class.getName()), QUERY_STRING);
            selectedLocation.clickAndWaitForNewWindow();

            // Verify the Query String is present after completing search.
            Assert.assertTrue(searchEditText.getText().contains(QUERY_STRING));
        }

        // Verify the directions/route link exists and clicking on it opens the directions page
        // verify query string is pre filled in the destination("to") field.
        UiObject directions =
                mDevice.findObject(new UiSelector().descriptionMatches(".*Directions.*|.*Route.*"));
        directions.clickAndWaitForNewWindow();
        UiObject destination = mDevice.findObject(new UiSelector().textContains(QUERY_STRING));
        Assert.assertTrue(destination.exists());
    }
}