Skip to content

Commit 0e09c55

Browse files
stefan-niedermannAndyScherzinger
authored andcommitted
Merge import and verification tests
Signed-off-by: Stefan Niedermann <[email protected]> Signed-off-by: Andy Scherzinger <[email protected]>
1 parent 215b08e commit 0e09c55

File tree

1 file changed

+28
-41
lines changed
  • sample/src/androidTest/java/com/nextcloud/android/sso/sample

1 file changed

+28
-41
lines changed

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

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import androidx.test.uiautomator.UiObjectNotFoundException;
1717
import androidx.test.uiautomator.UiSelector;
1818

19-
import org.junit.After;
2019
import org.junit.Before;
2120
import org.junit.FixMethodOrder;
2221
import org.junit.Test;
@@ -29,27 +28,20 @@
2928
public class E2ETest {
3029

3130
private static final String TAG = "E2E";
31+
private static final int TIMEOUT = 60_000;
3232

3333
private UiDevice mDevice;
3434

35-
private static final int TIMEOUT = 60_000;
36-
37-
private static final String APP_NEXTCLOUD = "com.nextcloud.android.beta";
38-
// TODO This should be passed as argument
3935
private static final String APP_SAMPLE = BuildConfig.APPLICATION_ID;
36+
// TODO This should be passed as argument
37+
private static final String APP_NEXTCLOUD = "com.nextcloud.android.beta";
4038
private static final String SERVER_URL = "http://172.17.0.1:8080";
4139
private static final String SERVER_USERNAME = "Test";
4240
private static final String SERVER_PASSWORD = "Test";
4341

4442
@Before
4543
public void before() {
4644
mDevice = UiDevice.getInstance(getInstrumentation());
47-
mDevice.pressHome();
48-
}
49-
50-
@After
51-
public void after() {
52-
mDevice.pressHome();
5345
}
5446

5547
@Test
@@ -59,69 +51,69 @@ public void test_00_configureNextcloudAccount() throws UiObjectNotFoundException
5951

6052
final var loginButton = mDevice.findObject(new UiSelector().textContains("Log in"));
6153
loginButton.waitForExists(TIMEOUT);
62-
Log.d(TAG, "Login Button exists. Clicking on it...");
54+
Log.d(TAG, "Login Button exists. Clicking on it");
6355
loginButton.click();
6456
Log.d(TAG, "Login Button clicked.");
6557

6658
final var urlInput = mDevice.findObject(new UiSelector().focused(true));
6759
urlInput.waitForExists(TIMEOUT);
6860
Log.d(TAG, "URL input exists.");
69-
Log.d(TAG, "Entering URL...");
61+
Log.d(TAG, "Entering URL");
7062
urlInput.setText(SERVER_URL);
7163
Log.d(TAG, "URL entered.");
7264

73-
Log.d(TAG, "Pressing enter...");
65+
Log.d(TAG, "Pressing enter");
7466
mDevice.pressEnter();
7567
Log.d(TAG, "Enter pressed.");
7668

77-
Log.d(TAG, "Waiting for WebView...");
69+
Log.d(TAG, "Waiting for WebView");
7870
mDevice.wait(findObject(By.clazz(WebView.class)), TIMEOUT);
7971
Log.d(TAG, "WebView exists.");
8072

8173
final var webViewLoginButton = mDevice.findObject(new UiSelector()
8274
.instance(0)
8375
.className(Button.class));
84-
Log.d(TAG, "Waiting for WebView Login Button...");
76+
Log.d(TAG, "Waiting for WebView Login Button");
8577
webViewLoginButton.waitForExists(TIMEOUT);
86-
Log.d(TAG, "WebView Login Button exists. Clicking on it...");
78+
Log.d(TAG, "WebView Login Button exists. Clicking on it");
8779
webViewLoginButton.click();
8880

8981
final var usernameInput = mDevice.findObject(new UiSelector()
9082
.instance(0)
9183
.className(EditText.class));
92-
Log.d(TAG, "Waiting for Username Input...");
84+
Log.d(TAG, "Waiting for Username Input");
9385
usernameInput.waitForExists(TIMEOUT);
94-
Log.d(TAG, "Username Input exists. Setting text...");
86+
Log.d(TAG, "Username Input exists. Setting text");
9587
usernameInput.setText(SERVER_USERNAME);
9688
Log.d(TAG, "Username has been set.");
9789

9890
final var passwordInput = mDevice.findObject(new UiSelector()
9991
.instance(1)
10092
.className(EditText.class));
101-
Log.d(TAG, "Waiting for Password Input...");
93+
Log.d(TAG, "Waiting for Password Input");
10294
passwordInput.waitForExists(TIMEOUT);
103-
Log.d(TAG, "Password Input exists. Setting text...");
95+
Log.d(TAG, "Password Input exists. Setting text");
10496
passwordInput.setText(SERVER_PASSWORD);
10597

10698
final var webViewSubmitButton = mDevice.findObject(new UiSelector()
10799
.instance(0)
108100
.className(Button.class));
109-
Log.d(TAG, "Waiting for WebView Submit Button...");
101+
Log.d(TAG, "Waiting for WebView Submit Button");
110102
webViewSubmitButton.waitForExists(TIMEOUT);
111-
Log.d(TAG, "WebView Submit Button exists. Clicking on it...");
103+
Log.d(TAG, "WebView Submit Button exists. Clicking on it");
112104
webViewSubmitButton.click();
113105

114106
final var webViewGrantAccessButton = mDevice.findObject(new UiSelector()
115107
.instance(0)
116108
.className(Button.class));
117-
Log.d(TAG, "Waiting for WebView Grant Access Button...");
109+
Log.d(TAG, "Waiting for WebView Grant Access Button");
118110
webViewGrantAccessButton.waitForExists(TIMEOUT);
119-
Log.d(TAG, "WebView Grant Access Button exists. Clicking on it...");
111+
Log.d(TAG, "WebView Grant Access Button exists. Clicking on it");
120112
webViewGrantAccessButton.click();
121113
}
122114

123115
@Test
124-
public void test_01_importAccountIntoSampleApp() throws UiObjectNotFoundException, InterruptedException {
116+
public void test_01_importAccountIntoSampleApp() throws UiObjectNotFoundException {
125117
Log.i(TAG, "Import account into sample app");
126118
launch(APP_SAMPLE);
127119

@@ -141,12 +133,11 @@ public void test_01_importAccountIntoSampleApp() throws UiObjectNotFoundExceptio
141133

142134
mDevice.waitForWindowUpdate(null, TIMEOUT);
143135

144-
Thread.sleep(10_000);
145136
final var okButton = mDevice.findObject(new UiSelector()
146137
.textContains("OK"));
147-
Log.d(TAG, "Waiting for OK Button...");
138+
Log.d(TAG, "Waiting for OK Button");
148139
okButton.waitForExists(TIMEOUT);
149-
Log.d(TAG, "OK Button exists. Clicking on it...");
140+
Log.d(TAG, "OK Button exists. Clicking on it");
150141
okButton.click();
151142
Log.d(TAG, "OK Button clicked");
152143

@@ -155,31 +146,27 @@ public void test_01_importAccountIntoSampleApp() throws UiObjectNotFoundExceptio
155146
final var allowButton = mDevice.findObject(new UiSelector()
156147
.instance(1)
157148
.className(Button.class));
158-
Log.d(TAG, "Waiting for Allow Button...");
149+
Log.d(TAG, "Waiting for Allow Button");
159150
allowButton.waitForExists(TIMEOUT);
160-
Log.d(TAG, "Allow Button exists. Clicking on it...");
151+
Log.d(TAG, "Allow Button exists. Clicking on it");
161152
allowButton.click();
162153
Log.d(TAG, "Allow Button clicked");
163154

164-
Log.d(TAG, "Waiting for finished import...");
155+
Log.d(TAG, "Waiting for finished import");
165156
final var welcomeText = mDevice.findObject(new UiSelector().description("Filter"));
166157
welcomeText.waitForExists(TIMEOUT);
167158
Log.d(TAG, "Import finished.");
168-
}
169159

170-
@Test
171-
public void test_02_verifyResult() throws UiObjectNotFoundException {
172-
Log.i(TAG, "Verify successful import");
173-
launch(APP_SAMPLE);
174-
175-
final var result = mDevice.findObject(new UiSelector()
176-
.textContains("Test on Nextcloud"));
160+
Log.i(TAG, "Verify successful import…");
161+
final var expectedToContain = "Test on Nextcloud";
162+
final var result = mDevice.findObject(new UiSelector().textContains(expectedToContain));
177163
result.waitForExists(TIMEOUT);
178-
System.out.println("Found: " + result.getText());
164+
Log.i(TAG, "Expected UI to display '" + expectedToContain + "'. Found: '" + result.getText() + "'.");
179165
}
180166

181167
private void launch(@NonNull String packageName) {
182168
Log.d(TAG, "Launching " + packageName);
169+
mDevice.pressHome();
183170
final var context = getInstrumentation().getContext();
184171
context.startActivity(context
185172
.getPackageManager()

0 commit comments

Comments
 (0)