11package com .nextcloud .android .sso .sample ;
22
33import static androidx .test .platform .app .InstrumentationRegistry .getInstrumentation ;
4- import static androidx .test .uiautomator .Until .findObject ;
54import static androidx .test .uiautomator .Until .hasObject ;
65
76import 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