diff options
author | Álvaro Brey Vilas <alvaro.brey@nextcloud.com> | 2022-04-26 10:51:39 +0300 |
---|---|---|
committer | Álvaro Brey Vilas <alvaro.brey@nextcloud.com> | 2022-04-26 10:51:39 +0300 |
commit | dd4a69d58c3003c897fbc831ce5c0ef294326c9c (patch) | |
tree | e38ac3ba07559edb9d41b5ce83dcbbc1dde5f368 | |
parent | 85b5bf68755ea81fc97a1f19eb8dcda38c090f33 (diff) |
LoginIT: convert to Kotlinfix/loginIT-master
While we're at it
Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
-rw-r--r-- | app/src/androidTest/java/com/owncloud/android/ui/LoginIT.java | 140 | ||||
-rw-r--r-- | app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt | 124 |
2 files changed, 124 insertions, 140 deletions
diff --git a/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.java b/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.java deleted file mode 100644 index 1be45db500..0000000000 --- a/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2020 Tobias Kaminsky - * Copyright (C) 2020 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -package com.owncloud.android.ui; - -import android.accounts.Account; -import android.content.Context; -import android.os.Bundle; - -import com.nextcloud.client.GrantStoragePermissionRule; -import com.nextcloud.client.RetryTestRule; -import com.nextcloud.client.account.UserAccountManager; -import com.nextcloud.client.account.UserAccountManagerImpl; -import com.owncloud.android.AbstractIT; -import com.owncloud.android.R; -import com.owncloud.android.authentication.AuthenticatorActivity; - -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; - -import androidx.test.core.app.ActivityScenario; -import androidx.test.espresso.web.webdriver.DriverAtoms; -import androidx.test.espresso.web.webdriver.Locator; -import androidx.test.filters.LargeTest; -import androidx.test.platform.app.InstrumentationRegistry; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.typeText; -import static androidx.test.espresso.action.ViewActions.typeTextIntoFocusedView; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.web.sugar.Web.onWebView; -import static androidx.test.espresso.web.webdriver.DriverAtoms.findElement; -import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick; -import static org.junit.Assert.assertEquals; - - -@LargeTest -public class LoginIT extends AbstractIT { - @Rule - public final TestRule permissionRule = GrantStoragePermissionRule.grant(); - @Rule - public RetryTestRule retryTestRule = new RetryTestRule(); - - @Before - public void setUp() { - tearDown(); - - ActivityScenario.launch(AuthenticatorActivity.class); - } - - @AfterClass - public static void tearDown() { - Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext); - - if (accountManager.getAccounts().length > 0) { - accountManager.removeAllAccounts(); - } - } - - @Test - public void login() throws InterruptedException { - Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments(); - - String baseUrl = arguments.getString("TEST_SERVER_URL"); - String loginName = arguments.getString("TEST_SERVER_USERNAME"); - String password = arguments.getString("TEST_SERVER_PASSWORD"); - - onView(withId(R.id.login)).perform(click()); - onView(withId(R.id.host_url_input)).perform(typeText(baseUrl)); - onView(withId(R.id.host_url_input)).perform(typeTextIntoFocusedView("\n")); - - Thread.sleep(3000); - - onWebView().forceJavascriptEnabled(); - - // click on login - onWebView() - .withElement(findElement(Locator.XPATH, "//p[@id='redirect-link']/a")) - .perform(webClick()); - - // username - onWebView() - .withElement(findElement(Locator.XPATH, "//input[@id='user']")) - .perform(DriverAtoms.webKeys(loginName)); - - // password - onWebView() - .withElement(findElement(Locator.XPATH, "//input[@id='password']")) - .perform(DriverAtoms.webKeys(password)); - - // click login - onWebView() - .withElement(findElement(Locator.XPATH, "//input[@type='submit']")) - .perform(webClick()); - - Thread.sleep(2000); - - // grant access - onWebView() - .withElement(findElement(Locator.XPATH, "//input[@type='submit']")) - .perform(webClick()); - - Thread.sleep(5 * 1000); - - // check for account - Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext); - - assertEquals(1, accountManager.getAccounts().length); - - Account account = accountManager.getAccounts()[0]; - - // account.name is loginName@baseUrl (without protocol) - assertEquals(loginName, account.name.split("@")[0]); - assertEquals(baseUrl.split("//")[1], account.name.split("@")[1]); - } -} diff --git a/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt new file mode 100644 index 0000000000..2f62bbf336 --- /dev/null +++ b/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt @@ -0,0 +1,124 @@ +/* + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2020 Tobias Kaminsky + * Copyright (C) 2020 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +package com.owncloud.android.ui + +import androidx.test.core.app.ActivityScenario +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.web.sugar.Web +import androidx.test.espresso.web.webdriver.DriverAtoms +import androidx.test.espresso.web.webdriver.Locator +import androidx.test.filters.LargeTest +import androidx.test.platform.app.InstrumentationRegistry +import com.nextcloud.client.GrantStoragePermissionRule +import com.nextcloud.client.RetryTestRule +import com.nextcloud.client.account.UserAccountManager +import com.nextcloud.client.account.UserAccountManagerImpl +import com.owncloud.android.AbstractIT +import com.owncloud.android.R +import com.owncloud.android.authentication.AuthenticatorActivity +import org.junit.AfterClass +import org.junit.Assert +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +@LargeTest +class LoginIT : AbstractIT() { + @get:Rule + val permissionRule = GrantStoragePermissionRule.grant() + + @get:Rule + var retryTestRule = RetryTestRule() + + @Before + fun setUp() { + tearDown() + ActivityScenario.launch(AuthenticatorActivity::class.java) + } + + @Test + @Throws(InterruptedException::class) + @Suppress("MagicNumber") + fun login() { + val arguments = InstrumentationRegistry.getArguments() + val baseUrl = arguments.getString("TEST_SERVER_URL")!! + val loginName = arguments.getString("TEST_SERVER_USERNAME")!! + val password = arguments.getString("TEST_SERVER_PASSWORD")!! + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withId(R.id.host_url_input)).perform(ViewActions.typeText(baseUrl)) + Espresso.onView(ViewMatchers.withId(R.id.host_url_input)).perform(ViewActions.typeTextIntoFocusedView("\n")) + Thread.sleep(3000) + Web.onWebView().forceJavascriptEnabled() + + // click on login + Web.onWebView() + .withElement(DriverAtoms.findElement(Locator.XPATH, "//p[@id='redirect-link']/a")) + .perform(DriverAtoms.webClick()) + + // username + Web.onWebView() + .withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@id='user']")) + .perform(DriverAtoms.webKeys(loginName)) + + // password + Web.onWebView() + .withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@id='password']")) + .perform(DriverAtoms.webKeys(password)) + + // click login + Web.onWebView() + .withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@type='submit']")) + .perform(DriverAtoms.webClick()) + Thread.sleep(2000) + + // grant access + Web.onWebView() + .withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@type='submit']")) + .perform(DriverAtoms.webClick()) + Thread.sleep((5 * 1000).toLong()) + + // check for account + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext + val accountManager: UserAccountManager = UserAccountManagerImpl.fromContext(targetContext) + Assert.assertEquals(1, accountManager.accounts.size.toLong()) + val account = accountManager.accounts[0] + + // account.name is loginName@baseUrl (without protocol) + Assert.assertEquals(loginName, account.name.split("@".toRegex()).toTypedArray()[0]) + Assert.assertEquals( + baseUrl.split("//".toRegex()).toTypedArray()[1], + account.name.split("@".toRegex()).toTypedArray()[1] + ) + } + + companion object { + @AfterClass + fun tearDown() { + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext + val accountManager: UserAccountManager = UserAccountManagerImpl.fromContext(targetContext) + if (accountManager.accounts.isNotEmpty()) { + accountManager.removeAllAccounts() + } + } + } +} |