Browse Source

Turn on device screen before Espress tests start

David A. Velasco 9 năm trước cách đây
mục cha
commit
2dfd98cbdd

+ 3 - 2
.travis.yml

@@ -2,8 +2,9 @@ sudo: false
 language: android
 android:
   components:
-  - platform-tools
   - tools
+  - tools
+  - platform-tools
   - build-tools-23.0.3
   - android-23
   - extra-android-m2repository
@@ -19,7 +20,7 @@ script:
 # run all the local unit tests of app module
   - ./gradlew :testDebug
 # run all the instrumented tests of app module
-  - ./gradlew connectedDebugAndroidTest
+  - ./gradlew connectedDebugAndroidTest --info
 # install app, then assemble and install instrumented tests of app module
 # - ./gradlew :installDebug
 # - ./gradlew :installDebugAndroidTest

+ 7 - 0
androidTest/AndroidManifest.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest
+    xmlns:tools="http://schemas.android.com/tools"
+    package="com.owncloud.android">
+
+    <uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
+</manifest>

+ 23 - 1
androidTest/java/com/owncloud/android/authentication/AuthenticatorActivityTest.java

@@ -21,15 +21,19 @@ package com.owncloud.android.authentication;
 
 import android.content.Context;
 import android.content.Intent;
+import android.graphics.Point;
 import android.os.Bundle;
+import android.os.RemoteException;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.rule.ActivityTestRule;
 import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
 import android.test.suitebuilder.annotation.LargeTest;
 
 import static org.junit.Assert.assertTrue;
 import com.owncloud.android.R;
 
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -71,12 +75,30 @@ public class AuthenticatorActivityTest {
             Context targetContext = InstrumentationRegistry.getInstrumentation()
                     .getTargetContext();
             Intent result = new Intent(targetContext, AuthenticatorActivity.class);
-            result.putExtra(EXTRA_ACTION, "");
+            result.putExtra(EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE);
             result.putExtra(EXTRA_ACCOUNT, "");
             return result;
         }
     };
 
+    @Before
+    public void init(){
+        UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        Point[] coordinates = new Point[4];
+        coordinates[0] = new Point(248, 1020);
+        coordinates[1] = new Point(248, 429);
+        coordinates[2] = new Point(796, 1020);
+        coordinates[3] = new Point(796, 429);
+        try {
+            if (!uiDevice.isScreenOn()) {
+                uiDevice.wakeUp();
+                //uiDevice.swipe(coordinates, 10);
+            }
+        } catch (RemoteException e) {
+            e.printStackTrace();
+        }
+    }
+
     @Test
     public void check_login()
         throws InterruptedException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

+ 2 - 0
build.gradle

@@ -54,6 +54,8 @@ dependencies {
     // Espresso core
     androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
 
+    // UIAutomator - needed to grant emulator screen is turned on before every Espresso test
+    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
 }
 
 tasks.withType(Test) {