Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/GmailTest.java

Issue 2692923010: Gmail open conversation test automation (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « android_webview/tools/automated_ui_tests/BUILD.gn ('k') | build/android/gmail_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.webview_ui_test.test;
6
7 import android.content.Intent;
8 import android.os.Build;
9 import android.os.RemoteException;
10 import android.os.SystemClock;
11 import android.support.test.InstrumentationRegistry;
12 import android.support.test.runner.AndroidJUnit4;
13 import android.support.test.uiautomator.UiDevice;
14 import android.support.test.uiautomator.UiObject;
15 import android.support.test.uiautomator.UiObjectNotFoundException;
16 import android.support.test.uiautomator.UiScrollable;
17 import android.support.test.uiautomator.UiSelector;
18
19 import android.support.test.filters.LargeTest;
20
21 import com.android.volley.DefaultRetryPolicy;
22 import com.android.volley.Request;
23 import com.android.volley.RequestQueue;
24 import com.android.volley.Response;
25 import com.android.volley.VolleyError;
26 import com.android.volley.toolbox.StringRequest;
27 import com.android.volley.toolbox.Volley;
28
29 import org.junit.After;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34
35 import org.chromium.base.Log;
36
37 @RunWith(AndroidJUnit4.class)
38 public class GmailTest {
39 private UiDevice mDevice;
40
41 private static final int UI_TIMEOUT = 10 * 1000;
42 private static final int EMAIL_WAIT = 20 * 1000;
43 private static final int WEBVIEW_CONTENT_WAIT = 30 * 1000;
44 private int mCenterX;
45 private int mCenterY;
46 private String mTitleType;
47
48 private RequestQueue mRequestQueue =
49 Volley.newRequestQueue(InstrumentationRegistry.getContext());
50
51 private boolean startTracingResponse;
52 private boolean endTracingResponse;
53
54 public static String UNREAD_CENTITHREAD_EMAIL_DESC = "Unread Yoland Yan abou t Unread Test %s.*";
55 public static String UNREAD_SINGLE_EMAIL_DESC =
56 "Unread Yoland Yan about Unread Test Single %s.*";
57 public static String READ_CENTITHREAD_EMAIL_DESC = " *me about Read Test %s. *";
58 public static String READ_SINGLE_EMAIL_DESC = " *me about Read Test Single % s.*";
59
60 @Before
61 public void setUp() throws RemoteException, UiObjectNotFoundException, Inter ruptedException {
62 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentatio n());
63 mDevice.setOrientationNatural();
64 mDevice.wakeUp();
65 mCenterX = mDevice.getDisplayWidth() / 2;
66 mCenterY = mDevice.getDisplayHeight() / 2;
67 mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
68 mTitleType = InstrumentationRegistry.getArguments().getString("title");
69 if (mTitleType == null) {
70 mTitleType = "Long Text";
71 }
72 mRequestQueue.start();
73 }
74
75 @After
76 public void tearDown() throws RemoteException, UiObjectNotFoundException, In terruptedException {
77 closeRecentActivity();
78 endTracing();
79 Thread.sleep(3000);
80 mDevice.unfreezeRotation();
81 mRequestQueue.stop();
82 }
83
84 // @Test
85 // public void testUnreadCentiThread() throws RemoteException, UiObjectNo tFoundException {
86 // //STUB
87 // }
88
89 // @Test
90 // public void testUnreadSingleThread() throws RemoteException, UiObjectN otFoundException {
91 // //STUB
92 // }
93
94 // Test for CentiThread
95 @Test
96 @LargeTest
97 public void testReadCentiThread()
98 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
99 Log.d("#YOLAND", "open_conversation soon for " + mTitleType + " testRead CentiThread");
100 startTracing("testReadCentiThread");
101 openGmail();
102 clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
103 waitForWebView();
104 }
105
106 @Test
107 @LargeTest
108 public void testReadGoBackReadAgainCentiThread()
109 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
110 Log.d("#YOLAND",
111 "open_conversation soon for " + mTitleType + " testReadGoBackRea dAgainCentiThread");
112 startTracing("testReadGoBackReadAgainCentiThread");
113 openGmail();
114 clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
115 waitForWebView();
116 clickBack();
117 Thread.sleep(5000);
118 clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
119 waitForWebView();
120 }
121
122 @Test
123 @LargeTest
124 public void testReadGoBackLockReadAgainCentiThread()
125 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
126 Log.d("#YOLAND", "open_conversation soon for " + mTitleType
127 + " testReadGoBackLockReadAgainCentiThread");
128 startTracing("testReadGoBackLockReadAgainCentiThread");
129 openGmail();
130 clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
131 waitForWebView();
132 clickBack();
133 mDevice.sleep();
134 Thread.sleep(5000);
135 mDevice.wakeUp();
136 mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
137 clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
138 waitForWebView();
139 }
140
141 @Test
142 @LargeTest
143 public void testReadLockReadAgainCentiThread()
144 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
145 Log.d("#YOLAND",
146 "open_conversation soon for " + mTitleType + " testReadLockReadA gainCentiThread");
147 startTracing("testReadLockReadAgainCentiThread");
148 openGmail();
149 clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
150 waitForWebView();
151 mDevice.sleep();
152 Thread.sleep(5000);
153 mDevice.wakeUp();
154 mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
155 waitForWebView();
156 }
157
158 // Test for Single Email Thread
159 @Test
160 @LargeTest
161 public void testReadSingleThread()
162 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
163 Log.d("#YOLAND", "open_conversation soon for " + mTitleType + " testRead SingleThread");
164 startTracing("testReadSingleThread");
165 openGmail();
166 clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
167 waitForWebView();
168 }
169
170 @Test
171 @LargeTest
172 public void testReadGoBackReadAgainSingleThread()
173 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
174 Log.d("#YOLAND", "open_conversation soon for " + mTitleType
175 + " testReadGoBackReadAgainSingleThread");
176 startTracing("testReadGoBackReadAgainSingleThread");
177 openGmail();
178 clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
179 waitForWebView();
180 clickBack();
181 Thread.sleep(5000);
182 clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
183 waitForWebView();
184 }
185
186 @Test
187 @LargeTest
188 public void testReadGoBackLockReadAgainSingleThread()
189 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
190 Log.d("#YOLAND", "open_conversation soon for " + mTitleType
191 + " testReadGoBackLockReadAgainSingleThread");
192 startTracing("testReadGoBackLockReadAgainSingleThread");
193 openGmail();
194 clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
195 waitForWebView();
196 clickBack();
197 mDevice.sleep();
198 Thread.sleep(5000);
199 mDevice.wakeUp();
200 mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
201 clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
202 waitForWebView();
203 }
204
205 @Test
206 @LargeTest
207 public void testReadLockReadAgainSingleThread()
208 throws RemoteException, UiObjectNotFoundException, InterruptedExcept ion {
209 Log.d("#YOLAND",
210 "open_conversation soon for " + mTitleType + " testReadLockReadA gainSingleThread");
211 startTracing("testReadLockReadAgainSingleThread");
212 openGmail();
213 clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
214 waitForWebView();
215 mDevice.sleep();
216 Thread.sleep(5000);
217 mDevice.wakeUp();
218 mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
219 waitForWebView();
220 }
221
222 // Private helper method from here on
223 private void clickBack() throws UiObjectNotFoundException {
224 UiObject back = mDevice.findObject(new UiSelector().descriptionMatches(" Navigate up"));
225 Assert.assertTrue(
226 "Backbutton not found, wtf, check if the title is wrong, current ly looking for back button",
227 back.waitForExists(UI_TIMEOUT));
228 back.click();
229 }
230
231 private void lockScreen() throws UiObjectNotFoundException {}
232
233 private void clickEmail(String descRegex) throws UiObjectNotFoundException {
234 UiObject emailThread = mDevice.findObject(new UiSelector().descriptionMa tches(descRegex));
235 Assert.assertTrue(
236 "New email not found, wtf, check if the title is wrong, currentl y looking for email titled "
237 + descRegex,
238 emailThread.waitForExists(UI_TIMEOUT));
239 emailThread.click();
240 }
241
242 private void startTracing(String name) throws InterruptedException {
243 // adhoc way of notifying the host side to start tracing
244 Log.d("#YOLAND", "start tracing");
245 startTracingResponse = false;
246 String url = "http://localhost:7777/start-tracing/" + name;
247
248 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
249 new Response.Listener<String>() {
250 @Override
251 public void onResponse(String response) {
252 Log.d("#YOLAND", "start tracing response: " + response);
253 startTracingResponse = true;
254 }
255 },
256 new Response.ErrorListener() {
257 @Override
258 public void onErrorResponse(VolleyError error) {
259 Log.d("#YOLAND", "start tracing error: " + error.getMess age());
260 }
261 });
262 stringRequest.setRetryPolicy(new DefaultRetryPolicy(
263 DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, DefaultRetryPolicy.DEF AULT_BACKOFF_MULT));
264 mRequestQueue.add(stringRequest);
265 }
266
267 private void endTracing() throws InterruptedException {
268 // adhoc way of notifying the host side to end tracing
269 Log.d("#YOLAND", "end tracing");
270 endTracingResponse = false;
271 String url = "http://localhost:7777/end-tracing";
272 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
273 new Response.Listener<String>() {
274 @Override
275 public void onResponse(String response) {
276 Log.d("#YOLAND", "end tracing response: " + response);
277 endTracingResponse = true;
278 }
279 },
280 new Response.ErrorListener() {
281 @Override
282 public void onErrorResponse(VolleyError error) {
283 Log.d("#YOLAND", "end tracing error: " + error.getMessag e());
284 }
285 });
286 stringRequest.setRetryPolicy(new DefaultRetryPolicy(
287 DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, DefaultRetryPolicy.DEF AULT_BACKOFF_MULT));
288 mRequestQueue.add(stringRequest);
289 }
290
291 // private void waitForNewEmail() {
292 // long start = SystemClock.elapsedRealtime();
293 // while (!mNewEmailThread.waitForExists(UI_TIMEOUT) && SystemClock.e lapsedRealtime() -
294 // start < EMAIL_WAIT) {
295 // mDevice.swipe(mCenterX, mCenterY, mCenterX, mDevice.getDisplay Height(), 10);
296 // }
297 // Assert.assertTrue("New email not found, wtf",
298 // mNewEmailThread.waitForExists(UI_TIMEOUT));
299 // }
300
301 private void waitForWebView() throws InterruptedException {
302 UiObject webviewContent =
303 mDevice.findObject(new UiSelector().descriptionMatches("^Test co ntent:.*"));
304 if (!webviewContent.waitForExists(WEBVIEW_CONTENT_WAIT)) {
305 Log.d("#YOLAND", "WebView Content never came up!!!!");
306 throw new AssertionError("Webview content never came up");
307 }
308 Thread.sleep(1000);
309 }
310
311 private void openGmail() {
312 Intent i =
313 InstrumentationRegistry.getContext().getPackageManager().getLaun chIntentForPackage(
314 "com.google.android.gm");
315 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
316 InstrumentationRegistry.getContext().startActivity(i);
317 }
318
319 private void openApp(String appName) throws UiObjectNotFoundException, Remot eException {
320 mDevice.pressHome();
321 openAppsMenu();
322 UiScrollable appMenu = new UiScrollable(new UiSelector().resourceIdMatch es(
323 ".*(apps_customize_pane_content|apps_list_view)"));
324 appMenu.setAsHorizontalList();
325 appMenu.getChildByText(new UiSelector().className(android.widget.TextVie w.class), appName)
326 .click();
327 }
328
329 private void openAppsMenu() throws UiObjectNotFoundException {
330 if (Build.DEVICE.equals("sailfish")) {
331 // UiObject pageIndicator = mDevice.findObject(new
332 // UiSelector().resourceIdMatches(".*page_indicator"));
333 // Assert.assertTrue("Apps menu button was not found.",
334 // pageIndicator.waitForExists(UI_TIMEOUT));
335 // pageIndicator.swipeUp(10);
336 mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 10);
337 } else {
338 UiObject appsMenuButton = mDevice.findObject(new UiSelector().descri ption("Apps"));
339 Assert.assertTrue(
340 "Apps menu button was not found.", appsMenuButton.waitForExi sts(UI_TIMEOUT));
341 appsMenuButton.click();
342 }
343 }
344
345 private void closeRecentActivity()
346 throws UiObjectNotFoundException, RemoteException, InterruptedExcept ion {
347 mDevice.pressRecentApps();
348 Thread.sleep(500);
349 mDevice.swipe(mCenterX, mCenterY, mDevice.getDisplayWidth(), mCenterY, 5 );
350 mDevice.pressHome();
351 }
352 }
OLDNEW
« no previous file with comments | « android_webview/tools/automated_ui_tests/BUILD.gn ('k') | build/android/gmail_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698