Skip to content

Commit 5ff896f

Browse files
stefan-niedermannAndyScherzinger
authored andcommitted
chore(e2e): Move setup from CI to gradle task for easier local run
Signed-off-by: Stefan Niedermann <[email protected]>
1 parent 2637ef1 commit 5ff896f

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

.github/workflows/e2e.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,7 @@ jobs:
7777
force-avd-creation: false
7878
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
7979
disable-animations: true
80-
# FIXME Execution of connectedDebugAndroidTest fails
81-
# TODO latest.apk should be cached when matrix testing is used
8280
script: |
83-
adb shell pm uninstall -k --user 0 com.nextcloud.android.beta || true
84-
wget -q https://download.nextcloud.com/android/dev/latest.apk
85-
adb install latest.apk
86-
adb shell pm grant com.nextcloud.android.beta android.permission.READ_EXTERNAL_STORAGE
8781
adb logcat -c || true
8882
adb logcat -s "E2E" -v color &
8983
adb logcat *:I -v color &

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ buildscript {
1515
}
1616
}
1717

18+
plugins {
19+
id "de.undercouch.download" version "5.4.0"
20+
}
21+
1822
allprojects {
1923
repositories {
2024
google()

sample/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import com.android.ddmlib.AndroidDebugBridge
2+
import com.android.ddmlib.NullOutputReceiver
3+
4+
import java.util.concurrent.TimeUnit
5+
16
apply plugin: 'com.android.application'
27

38
android {
@@ -28,6 +33,34 @@ android {
2833
}
2934
}
3035

36+
task downloadNextcloudApk(type: Download) {
37+
src 'https://download.nextcloud.com/android/dev/latest.apk'
38+
dest new File(buildDir, 'latest.apk')
39+
overwrite true
40+
}
41+
42+
task setupNextcloudEnvironment(dependsOn: downloadNextcloudApk) {
43+
def bridge = AndroidDebugBridge.createBridge(android.adbExecutable.path, false, 10, TimeUnit.SECONDS)
44+
doLast {
45+
bridge.devices.each { device ->
46+
println "Uninstall Nextcloud apk from ${device.name}"
47+
device.uninstallPackage("com.nextcloud.android.beta")
48+
49+
println "Install Nextcloud apk on ${device.name}"
50+
device.installPackage(new File(buildDir, 'latest.apk').getAbsolutePath(), true)
51+
52+
println "Grant permissions to Nextcloud"
53+
device.executeShellCommand("pm grant com.nextcloud.android.beta android.permission.READ_EXTERNAL_STORAGE", NullOutputReceiver.receiver, 3, TimeUnit.SECONDS)
54+
}
55+
}
56+
}
57+
58+
tasks.whenTaskAdded { taskItem ->
59+
if (taskItem.name.contains("connected") && taskItem.name.endsWith("AndroidTest")) {
60+
taskItem.dependsOn setupNextcloudEnvironment
61+
}
62+
}
63+
3164
dependencies {
3265
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
3366
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.9.22"))

sample/src/androidTest/java/com/nextcloud/android/sso/sample/E2ETest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.nextcloud.android.sso.sample;
22

33
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
4-
import static androidx.test.uiautomator.Until.findObject;
54
import static androidx.test.uiautomator.Until.hasObject;
65

76
import android.content.Intent;
@@ -45,7 +44,7 @@ public void before() {
4544
}
4645

4746
@Test
48-
public void test_00_configureNextcloudAccount() throws UiObjectNotFoundException {
47+
public void test_00_configureNextcloudAccount() throws UiObjectNotFoundException, InterruptedException {
4948
Log.i(TAG, "Configure Nextcloud account");
5049
launch(APP_NEXTCLOUD);
5150

@@ -66,8 +65,10 @@ public void test_00_configureNextcloudAccount() throws UiObjectNotFoundException
6665
mDevice.pressEnter();
6766
Log.d(TAG, "Enter pressed.");
6867

68+
final var webView = mDevice.findObject(new UiSelector().instance(0).className(WebView.class));
6969
Log.d(TAG, "Waiting for WebView…");
70-
mDevice.wait(findObject(By.clazz(WebView.class)), TIMEOUT);
70+
// mDevice.wait(findObject(By.clazz(WebView.class)), TIMEOUT);
71+
webView.waitForExists(TIMEOUT);
7172
Log.d(TAG, "WebView exists.");
7273

7374
final var webViewLoginButton = mDevice.findObject(new UiSelector()
@@ -76,6 +77,13 @@ public void test_00_configureNextcloudAccount() throws UiObjectNotFoundException
7677
Log.d(TAG, "Waiting for WebView Login Button…");
7778
webViewLoginButton.waitForExists(TIMEOUT);
7879
Log.d(TAG, "WebView Login Button exists. Clicking on it…");
80+
81+
// TODO Find better way to scroll the Login button to the visible area
82+
// Log.d(TAG, "Scroll to bottom of WebView…");
83+
// mDevice.findObject(By.clazz(WebView.class)).swipe(Direction.UP, 1f);
84+
// Log.d(TAG, "Finished scrolling");
85+
webViewLoginButton.dragTo(0,0, 40);
86+
7987
webViewLoginButton.click();
8088

8189
final var usernameInput = mDevice.findObject(new UiSelector()
@@ -95,21 +103,32 @@ public void test_00_configureNextcloudAccount() throws UiObjectNotFoundException
95103
Log.d(TAG, "Password Input exists. Setting text…");
96104
passwordInput.setText(SERVER_PASSWORD);
97105

106+
// mDevice.pressEnter();
98107
final var webViewSubmitButton = mDevice.findObject(new UiSelector()
99-
.instance(0)
108+
.instance(1) // First button is password visibility toggle
100109
.className(Button.class));
101110
Log.d(TAG, "Waiting for WebView Submit Button…");
102111
webViewSubmitButton.waitForExists(TIMEOUT);
103112
Log.d(TAG, "WebView Submit Button exists. Clicking on it…");
104113
webViewSubmitButton.click();
105114

115+
webViewSubmitButton.waitUntilGone(TIMEOUT);
116+
106117
final var webViewGrantAccessButton = mDevice.findObject(new UiSelector()
107118
.instance(0)
108119
.className(Button.class));
109120
Log.d(TAG, "Waiting for WebView Grant Access Button…");
110121
webViewGrantAccessButton.waitForExists(TIMEOUT);
111122
Log.d(TAG, "WebView Grant Access Button exists. Clicking on it…");
112123
webViewGrantAccessButton.click();
124+
125+
webView.waitUntilGone(TIMEOUT);
126+
127+
mDevice.waitForIdle(TIMEOUT);
128+
129+
Log.d(TAG, "Wait for Nextcloud files app…");
130+
Thread.sleep(3_000);
131+
Log.d(TAG, "Finishing setup…");
113132
}
114133

115134
@Test

0 commit comments

Comments
 (0)