From: purigarcia Date: Fri, 13 Mar 2015 08:42:18 +0000 (+0100) Subject: upload a few automated test X-Git-Tag: oc-android-1.7.2~1^2~32^2~33 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/3aa425a7b576c2e74672eb3a8731cf03afd8f38d upload a few automated test --- diff --git a/automationTest/.classpath b/automationTest/.classpath new file mode 100644 index 00000000..53c35984 --- /dev/null +++ b/automationTest/.classpath @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/automationTest/.gitignore b/automationTest/.gitignore new file mode 100644 index 00000000..7326dd9f --- /dev/null +++ b/automationTest/.gitignore @@ -0,0 +1,2 @@ +/target/ +.DS_Store \ No newline at end of file diff --git a/automationTest/.project b/automationTest/.project new file mode 100644 index 00000000..b1e58409 --- /dev/null +++ b/automationTest/.project @@ -0,0 +1,23 @@ + + + androidtest + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/automationTest/.settings/org.eclipse.core.resources.prefs b/automationTest/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..f9fe3459 --- /dev/null +++ b/automationTest/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/automationTest/.settings/org.eclipse.jdt.core.prefs b/automationTest/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..abec6ca3 --- /dev/null +++ b/automationTest/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/automationTest/.settings/org.eclipse.m2e.core.prefs b/automationTest/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/automationTest/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/automationTest/pom.xml b/automationTest/pom.xml new file mode 100644 index 00000000..373128be --- /dev/null +++ b/automationTest/pom.xml @@ -0,0 +1,55 @@ + + +4.0.0 + +com.owncloud +androidtest +1.0-SNAPSHOT + + + + junit + junit + 4.11 + + + org.seleniumhq.selenium + selenium-java + 2.44.0 + + + io.selendroid + 0.9.0 + selendroid-standalone + + + io.selendroid + 0.9.0 + selendroid-client + + + io.appium + java-client + 2.1.0 + + + commons-lang + commons-lang + 2.6 + + + org.apache.httpcomponents + httpclient + 4.3.1 + + + com.google.android + android + 4.1.1.4 + provided + + + + \ No newline at end of file diff --git a/automationTest/src/test/java/androidtest/actions/Actions.java b/automationTest/src/test/java/androidtest/actions/Actions.java new file mode 100644 index 00000000..952b01fd --- /dev/null +++ b/automationTest/src/test/java/androidtest/actions/Actions.java @@ -0,0 +1,26 @@ +package androidtest.actions; + +import io.appium.java_client.android.AndroidDriver; +import androidtest.models.MainView; +import androidtest.models.SettingsView; + +public class Actions { + + public static void deleteAccount (MainView mainView) { + mainView.clickOnMenuButton(); + SettingsView settingView = mainView.clickOnSettingsButton(); + deleteAccount(settingView); + + } + + public static void deleteAccount (SettingsView settingsView) { + settingsView.tapOnAccountElement(1, 1000); + settingsView.clickOnDeleteAccountElement(); + } + + public static void clickOnMainLayout(AndroidDriver driver){ + driver.tap(1, 0, 0, 1); + } + + +} diff --git a/automationTest/src/test/java/androidtest/models/AppDetailsView.java b/automationTest/src/test/java/androidtest/models/AppDetailsView.java new file mode 100644 index 00000000..75ce4d9f --- /dev/null +++ b/automationTest/src/test/java/androidtest/models/AppDetailsView.java @@ -0,0 +1,41 @@ +package androidtest.models; + +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.pagefactory.AndroidFindBy; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; + +import org.openqa.selenium.support.CacheLookup; +import org.openqa.selenium.support.PageFactory; + +public class AppDetailsView { + final AndroidDriver driver; + + @CacheLookup + @AndroidFindBy(name = "Keep file up to date") + private AndroidElement keepFileUpToDateCheckbox; + + @AndroidFindBy(id = "com.owncloud.android:id/fdProgressBar") + private AndroidElement progressBar; + + public AppDetailsView (AndroidDriver driver) { + this.driver = driver; + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + } + + public void checkKeepFileUpToDateCheckbox () { + if(keepFileUpToDateCheckbox.getAttribute("checked").equals("false")){ + keepFileUpToDateCheckbox.click(); + } + } + + public void unCheckKeepFileUpToDateCheckbox () { + if(keepFileUpToDateCheckbox.getAttribute("checked").equals("true")){ + keepFileUpToDateCheckbox.click(); + } + } + + public AndroidElement getProgressBar (){ + return progressBar; + } +} diff --git a/automationTest/src/test/java/androidtest/models/FilesView.java b/automationTest/src/test/java/androidtest/models/FilesView.java new file mode 100644 index 00000000..73fb67f9 --- /dev/null +++ b/automationTest/src/test/java/androidtest/models/FilesView.java @@ -0,0 +1,50 @@ +package androidtest.models; + +import java.util.HashMap; + +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.pagefactory.AndroidFindBy; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; + +import org.openqa.selenium.remote.RemoteWebElement; +import org.openqa.selenium.support.CacheLookup; +import org.openqa.selenium.support.PageFactory; + +public class FilesView { + final AndroidDriver driver; + + @CacheLookup + @AndroidFindBy(id = "com.owncloud.android:id/list_root") + private AndroidElement fileLayout; + + @CacheLookup + @AndroidFindBy(id = "com.owncloud.android:id/upload_files_btn_upload") + private AndroidElement uploadButton; + + private AndroidElement fileElement; + + public FilesView (AndroidDriver driver) { + this.driver = driver; + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + } + + public MainView clickOnUploadButton () { + uploadButton.click(); + MainView mainView = new MainView (driver); + return mainView; + } + + public void scrollTillFindFile (String fileName) { + HashMap scrollObject = new HashMap(); + scrollObject.put("text", fileName); + scrollObject.put("element", ( (RemoteWebElement) fileLayout).getId()); + driver.executeScript("mobile: scrollTo", scrollObject); + fileElement = (AndroidElement) driver.findElementByName(fileName); + } + + public void clickOnFileName (String fileName) { + scrollTillFindFile(fileName); + fileElement.click(); + } +} diff --git a/automationTest/src/test/java/androidtest/models/LoginForm.java b/automationTest/src/test/java/androidtest/models/LoginForm.java new file mode 100644 index 00000000..23542691 --- /dev/null +++ b/automationTest/src/test/java/androidtest/models/LoginForm.java @@ -0,0 +1,75 @@ +package androidtest.models; + +import org.openqa.selenium.support.CacheLookup; +import org.openqa.selenium.support.PageFactory; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.pagefactory.AndroidFindBy; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; + +public class LoginForm { + final AndroidDriver driver; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Server address\")") + private AndroidElement hostUrlInput; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Username\")") + private AndroidElement userNameInput; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Password\")") + private AndroidElement passwordInput; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Connect\")") + private AndroidElement connectButton; + + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Testing connection\")") + private AndroidElement serverStatusText; + + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Wrong username or password\")") + private AndroidElement authStatusText; + + public LoginForm (AndroidDriver driver) { + this.driver = driver; + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + } + + public void typeHostUrl (String hostUrl) { + hostUrlInput.clear(); + hostUrlInput.sendKeys(hostUrl); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + } + + public void clickOnUserName () { + userNameInput.click(); + } + + public void typeUserName (String userName) { + userNameInput.clear(); + userNameInput.sendKeys(userName); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + } + + public void typePassword (String password) { + passwordInput.clear(); + passwordInput.sendKeys(password); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + } + + public MainView clickOnConnectButton () { + connectButton.click(); + MainView mainView = new MainView(driver); + return mainView; + } + + public AndroidElement getServerStatusTextElement () { + return serverStatusText; + } + + public AndroidElement getAuthStatusText () { + return authStatusText; + } +} diff --git a/automationTest/src/test/java/androidtest/models/MainView.java b/automationTest/src/test/java/androidtest/models/MainView.java new file mode 100644 index 00000000..66523f9a --- /dev/null +++ b/automationTest/src/test/java/androidtest/models/MainView.java @@ -0,0 +1,179 @@ +package androidtest.models; + +import java.util.HashMap; +import java.util.List; + +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.pagefactory.AndroidFindBy; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; + +import org.openqa.selenium.remote.RemoteWebElement; +import org.openqa.selenium.support.CacheLookup; +import org.openqa.selenium.support.PageFactory; + +public class MainView { + final AndroidDriver driver; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"More options\")") + private AndroidElement menuButton; + + @CacheLookup + @AndroidFindBy(id = "com.owncloud.android:id/list_root") + private AndroidElement filesLayout; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/action_bar_title\")") + private AndroidElement titleText; + + @AndroidFindBy(name = "Settings") + private AndroidElement settingsButton; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"New folder\")") + private AndroidElement newFolderButton; + + @CacheLookup + @AndroidFindBy(uiAutomator = "new UiSelector().description(\"Upload\")") + private AndroidElement uploadButton; + + @AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.owncloud.android:id/user_input\")") + private AndroidElement newFolderNameField; + + @AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/button1\")") + private AndroidElement newFolderOkButton; + + private AndroidElement waitAMomentText; + + @AndroidFindBy(id = "com.owncloud.android:id/ListItemLayout") + private List listItemLayout; + + @AndroidFindBy(id = "com.owncloud.android:id/list_root") + private AndroidElement listRootLayout; + + @AndroidFindBy(name = "Remove") + private AndroidElement removeFileElement; + + @AndroidFindBy(name = "Details") + private AndroidElement detailsFileElement; + + @AndroidFindBy(name = "Remote and local") + private AndroidElement remoteAndLocalButton; + + @AndroidFindBy(name = "Files") + private AndroidElement filesElementUploadFile; + + private AndroidElement fileElement; + + private AndroidElement fileElementLayout; + + + public MainView (AndroidDriver driver) { + this.driver = driver; + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + } + + public void clickOnMenuButton () { + //TODO. DETECT WHEN HAPPENS WHEN THERE IS NOT BUTTON IN THE TOPBAR + //if(menuButton.exists()){ + //menuButton.click(); + //}else{ + //Thread.sleep(10000); + //getUiDevice().pressMenu(); + //} + menuButton.click(); + } + + public SettingsView clickOnSettingsButton () { + settingsButton.click(); + SettingsView settingsView = new SettingsView(driver); + return settingsView; + } + + public SettingsView getSettingsView () { + SettingsView settingsView = new SettingsView(driver); + return settingsView; + } + + public void clickOnNewFolderButton () { + newFolderButton.click(); + } + + public void clickOnRemoveFileElement () { + removeFileElement.click(); + } + + public AppDetailsView clickOnDetailsFileElement () { + detailsFileElement.click(); + AppDetailsView appDetailsView = new AppDetailsView(driver); + return appDetailsView; + } + + public void typeNewFolderName (String newFolderName) { + newFolderNameField.clear(); + newFolderNameField.sendKeys(newFolderName); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + } + + public void clickOnNewFolderOkButton () { + newFolderOkButton.click(); + waitAMomentText = (AndroidElement) driver.findElementByName("Wait a moment"); + } + + public void clickOnRemoteAndLocalButton () { + remoteAndLocalButton.click(); + waitAMomentText = (AndroidElement) driver.findElementByName("Wait a moment"); + } + + public void clickOnUploadButton () { + uploadButton.click(); + } + + public FilesView clickOnFilesElementUploadFile () { + filesElementUploadFile.click(); + FilesView filesView = new FilesView(driver); + return filesView; + } + + public AndroidElement getTitleTextElement () { + return titleText; + } + + public AndroidElement getWaitAMomentTextElement () { + return waitAMomentText; + } + + public AndroidElement getListRootElement () { + return listRootLayout; + } + + public List getListItemLayout () { + return listItemLayout; + } + + public AndroidElement getFileElement () { + return fileElement; + } + + public void tapOnFileElement (String fileName) { + scrollTillFindElement(fileName); + fileElement.tap(1, 1000); + } + + public AndroidElement scrollTillFindElement (String fileName) { + HashMap scrollObject = new HashMap(); + scrollObject.put("text", fileName); + scrollObject.put("element", ( (RemoteWebElement) filesLayout).getId()); + if(filesLayout.getAttribute("scrollable").equals("true")){ + driver.executeScript("mobile: scrollTo", scrollObject); + } + fileElement = (AndroidElement) driver.findElementByName(fileName); + fileElementLayout = (AndroidElement) driver.findElementByAndroidUIAutomator("new UiSelector().description(\"LinearLayout-"+ fileName +"\")"); + return fileElement; + } + + public AndroidElement getFileElementLayout () { + return fileElementLayout; + } +} diff --git a/automationTest/src/test/java/androidtest/models/SettingsView.java b/automationTest/src/test/java/androidtest/models/SettingsView.java new file mode 100644 index 00000000..18c9c008 --- /dev/null +++ b/automationTest/src/test/java/androidtest/models/SettingsView.java @@ -0,0 +1,59 @@ +package androidtest.models; + +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.pagefactory.AndroidFindBy; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; + +import org.openqa.selenium.support.CacheLookup; +import org.openqa.selenium.support.PageFactory; + +import androidtest.tests.Config; + +public class SettingsView { + final AndroidDriver driver; + + @CacheLookup + @AndroidFindBy(name = Config.userAccount) + private AndroidElement accountElement; + + @CacheLookup + @AndroidFindBy(name = Config.userAccount2) + private AndroidElement accountElement2; + + @AndroidFindBy(name = "Delete account") + private AndroidElement deleteAccountElement; + + @AndroidFindBy(name = "Change password") + private AndroidElement changePasswordElement; + + @AndroidFindBy(name = "Add account") + private AndroidElement addAccountElement; + + public SettingsView (AndroidDriver driver) { + this.driver = driver; + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + } + + public void tapOnAccountElement (int fingers, int milliSeconds) { + accountElement.tap(fingers, milliSeconds); + } + + + public void tapOnAddAccount (int fingers, int milliSeconds) { + addAccountElement.tap(fingers, milliSeconds); + } + + public LoginForm clickOnDeleteAccountElement () { + deleteAccountElement.click(); + LoginForm loginForm = new LoginForm(driver); + return loginForm; + } + + public LoginForm clickOnChangePasswordElement () { + changePasswordElement.click(); + LoginForm loginForm = new LoginForm(driver); + return loginForm; + } + +} diff --git a/automationTest/src/test/java/androidtest/tests/CommonTest.java b/automationTest/src/test/java/androidtest/tests/CommonTest.java new file mode 100644 index 00000000..b8195449 --- /dev/null +++ b/automationTest/src/test/java/androidtest/tests/CommonTest.java @@ -0,0 +1,69 @@ +package androidtest.tests; + +import java.io.File; +import java.net.URL; + +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.remote.DesiredCapabilities; + +import androidtest.models.LoginForm; +import androidtest.models.MainView; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; +import junit.framework.TestCase; + +public class CommonTest extends TestCase{ + AndroidDriver driver; + final int waitingTime = 30; + + protected void setUpCommonDriver () throws Exception { + File rootPath = new File(System.getProperty("user.dir")); + File appDir = new File(rootPath,"src/test/resources"); + File app = new File(appDir,"ownCloud.apk"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability("platformName", "Android"); + capabilities.setCapability("deviceName", "Device"); + capabilities.setCapability("app", app.getAbsolutePath()); + capabilities.setCapability("app-package", "com.owncloud.android"); + capabilities.setCapability("app-activity", ".ui.activity.FileDisplayActivity"); + capabilities.setCapability("appWaitActivity", ".authentication.AuthenticatorActivity"); + driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); + } + + protected boolean waitForTextPresent(String text, AndroidElement element) throws InterruptedException{ + for (int second = 0;;second++){ + if (second >= waitingTime) + return false; + try{ + if (text.equals(element.getText())) + break; + } catch (Exception e){ + + } + Thread.sleep(1000); + } + return true; + } + + protected boolean isElementPresent(AndroidElement element, By by) { + try { + element.findElement(by); + return true; + } catch (NoSuchElementException e) { + return false; + } + } + + protected MainView login(String url, String user, String password) throws InterruptedException { + LoginForm loginForm = new LoginForm(driver); + loginForm.typeHostUrl(url); + loginForm.clickOnUserName(); + waitForTextPresent("Secure connection established", loginForm.getServerStatusTextElement()); + assertTrue(waitForTextPresent("Secure connection established", loginForm.getServerStatusTextElement())); + loginForm.typeUserName(user); + loginForm.typePassword(password); + return loginForm.clickOnConnectButton(); + } + +} diff --git a/automationTest/src/test/java/androidtest/tests/Config.java b/automationTest/src/test/java/androidtest/tests/Config.java new file mode 100644 index 00000000..4e1b0fe9 --- /dev/null +++ b/automationTest/src/test/java/androidtest/tests/Config.java @@ -0,0 +1,24 @@ +package androidtest.tests; + +public final class Config { + + public static final String server = "owncloudServerVar"; + public static final Boolean hasSubdirectory = false; + public static String URL = GetURl(hasSubdirectory); + + public static final String user = "owncloudUserVar"; + public static final String password = "owncloudPasswordVar"; + public static final String user2 = "owncloudUser2Var"; + public static final String password2 = "owncloudPassword2Var"; + public static final String userAccount = user + "@"+server; + public static final String userAccount2 = user2 + "@"+server; + + public static String GetURl(Boolean hasSubdirectory){ + if(hasSubdirectory){ + return server + "/owncloud"; + }else{ + return server; + } + } + +} diff --git a/automationTest/src/test/java/androidtest/tests/CreateFolderTestSuite.java b/automationTest/src/test/java/androidtest/tests/CreateFolderTestSuite.java new file mode 100644 index 00000000..87363840 --- /dev/null +++ b/automationTest/src/test/java/androidtest/tests/CreateFolderTestSuite.java @@ -0,0 +1,54 @@ +package androidtest.tests; + +import io.appium.java_client.android.AndroidElement; + +import org.junit.After; +import org.junit.Before; +import org.junit.runners.MethodSorters; +import org.junit.FixMethodOrder; +import org.junit.Test; + + +import androidtest.actions.Actions; +import androidtest.models.MainView; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CreateFolderTestSuite extends CommonTest{ + + @Before + public void setUp() throws Exception { + setUpCommonDriver(); + } + + + @Test + public void test6CreateNewFolder () throws Exception { + String NEW_FOLDER_NAME = "testCreateFolder"; + + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + mainView.clickOnNewFolderButton(); + mainView.typeNewFolderName(NEW_FOLDER_NAME); + mainView.clickOnNewFolderOkButton(); + assertTrue(waitForTextPresent("Wait a moment" , mainView.getWaitAMomentTextElement())); + while(mainView.getWaitAMomentTextElement().isDisplayed()){} + AndroidElement newFolderElement = mainView.scrollTillFindElement(NEW_FOLDER_NAME); + assertTrue(newFolderElement.isDisplayed()); + newFolderElement.tap(1, 1000); + mainView.clickOnRemoveFileElement(); + mainView.clickOnRemoteAndLocalButton(); + assertTrue(waitForTextPresent("Wait a moment" , mainView.getWaitAMomentTextElement())); + while(mainView.getWaitAMomentTextElement().isDisplayed()){} + Actions.deleteAccount(mainView); + } + + + @After + public void tearDown() throws Exception { + driver.removeApp("com.owncloud.android"); + driver.quit(); + } + +} + diff --git a/automationTest/src/test/java/androidtest/tests/LoginTestSuite.java b/automationTest/src/test/java/androidtest/tests/LoginTestSuite.java new file mode 100644 index 00000000..a4cbda66 --- /dev/null +++ b/automationTest/src/test/java/androidtest/tests/LoginTestSuite.java @@ -0,0 +1,128 @@ +package androidtest.tests; + +import org.junit.After; +import org.junit.Before; +import org.junit.runners.MethodSorters; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.openqa.selenium.ScreenOrientation; + + +import androidtest.actions.Actions; +import androidtest.models.LoginForm; +import androidtest.models.MainView; +import androidtest.models.SettingsView; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class LoginTestSuite extends CommonTest{ + + @Before + public void setUp() throws Exception { + setUpCommonDriver(); + } + + @Test + public void test1LoginPortrait () throws Exception { + + System.out.println("Hello" + Config.server); + String testName = "loginPortrait"; + driver.rotate(ScreenOrientation.PORTRAIT); + + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + //TO DO. detect in which view is. it can be files view or settings view + /*if(mainView.getTitleTextElement().equals("ownCloud") || mainView.getTitleTextElement().equals("Settings")){ + if(mainView.getTitleTextElement().getText().equals("ownCloud")){ + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + }else{ + assertTrue(waitForTextPresent("Settings", mainView.getTitleTextElement())); + } + fail(testName); + }*/ + Actions.deleteAccount(mainView); + } + + @Test + public void test2LoginLandscape () throws Exception { + + String testName = "loginLandscape"; + driver.rotate(ScreenOrientation.LANDSCAPE); + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + //TO DO. detect in which view is. it can be files view or settings view + Actions.deleteAccount(mainView); + } + + + @Test + public void test3MultiAccountRotate () throws Exception { + + String testName = "MultiAccountRotate"; + driver.rotate(ScreenOrientation.LANDSCAPE); + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + + driver.rotate(ScreenOrientation.PORTRAIT); + mainView.clickOnMenuButton(); + SettingsView settingsView = mainView.clickOnSettingsButton(); + settingsView.tapOnAddAccount(1, 1000); + mainView = login(Config.URL, Config.user2,Config.password2); + + assertTrue(waitForTextPresent("Settings", mainView.getTitleTextElement())); + //TO DO. detect in which view is. it can be files view or settings view + //Actions.deleteAccount(mainView); + Actions.deleteAccount(settingsView); + //TO DO. Delete the second user + } + + @Test + public void test4ExistingAccountRotate () throws Exception { + + String testName = "ExistingAccountRotate"; + driver.rotate(ScreenOrientation.PORTRAIT); + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + + driver.rotate(ScreenOrientation.LANDSCAPE); + mainView.clickOnMenuButton(); + SettingsView settingsView = mainView.clickOnSettingsButton(); + settingsView.tapOnAddAccount(1, 1000); + LoginForm loginForm = new LoginForm(driver); + loginForm.typeHostUrl(Config.URL); + loginForm.clickOnUserName(); + waitForTextPresent("Secure connection established", loginForm.getServerStatusTextElement()); + assertTrue(waitForTextPresent("Secure connection established", loginForm.getServerStatusTextElement())); + loginForm.typeUserName(Config.user); + loginForm.typePassword(Config.password); + mainView = loginForm.clickOnConnectButton(); + + assertTrue(waitForTextPresent("An account for the same user and server already exists in the device", loginForm.getAuthStatusText())); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + Actions.deleteAccount(settingsView); + } + + + public void test5ChangePasswordWrong () throws Exception { + + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + mainView.clickOnMenuButton(); + SettingsView settingView = mainView.clickOnSettingsButton(); + settingView.tapOnAccountElement(1, 1000); + LoginForm changePasswordForm = settingView.clickOnChangePasswordElement(); + changePasswordForm.typePassword("WrongPassword"); + changePasswordForm.clickOnConnectButton(); + assertTrue(waitForTextPresent("Wrong username or password", changePasswordForm.getAuthStatusText())); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + Actions.deleteAccount(settingView); + } + + + @After + public void tearDown() throws Exception { + driver.removeApp("com.owncloud.android"); + driver.quit(); + } + + +} diff --git a/automationTest/src/test/java/androidtest/tests/UploadTestSuite.java b/automationTest/src/test/java/androidtest/tests/UploadTestSuite.java new file mode 100644 index 00000000..4b1a5006 --- /dev/null +++ b/automationTest/src/test/java/androidtest/tests/UploadTestSuite.java @@ -0,0 +1,88 @@ +package androidtest.tests; + + +import io.appium.java_client.MobileBy; + +import org.junit.After; +import org.junit.Before; +import org.junit.runners.MethodSorters; +import org.junit.FixMethodOrder; +import org.junit.Test; + +import androidtest.actions.Actions; +import androidtest.models.AppDetailsView; +import androidtest.models.FilesView; +import androidtest.models.MainView; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class UploadTestSuite extends CommonTest{ + + @Before + public void setUp() throws Exception { + setUpCommonDriver(); + } + + @Test + public void test1UploadFile () throws Exception { + String FILE_NAME = "test"; + + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + mainView.clickOnUploadButton(); + FilesView filesView = mainView.clickOnFilesElementUploadFile(); + filesView.clickOnFileName(FILE_NAME); + MainView mainViewAfterUploadFile = filesView.clickOnUploadButton(); + //TO DO. detect when the file is successfully uploaded + Thread.sleep(3000); + mainViewAfterUploadFile.scrollTillFindElement(FILE_NAME); + assertTrue(mainViewAfterUploadFile.getFileElement().isDisplayed()); + mainViewAfterUploadFile.tapOnFileElement(FILE_NAME); + mainViewAfterUploadFile.clickOnRemoveFileElement(); + mainViewAfterUploadFile.clickOnRemoteAndLocalButton(); + assertTrue(waitForTextPresent("Wait a moment" , mainViewAfterUploadFile.getWaitAMomentTextElement())); + while(mainViewAfterUploadFile.getWaitAMomentTextElement().isDisplayed()){} + Actions.deleteAccount(mainViewAfterUploadFile); + + } + + @Test + public void test2KeepFileUpToDate () throws Exception { + String FILE_NAME = "test"; + + MainView mainView = login(Config.URL, Config.user,Config.password); + assertTrue(waitForTextPresent("ownCloud", mainView.getTitleTextElement())); + mainView.clickOnUploadButton(); + FilesView filesView = mainView.clickOnFilesElementUploadFile(); + filesView.clickOnFileName(FILE_NAME); + MainView mainViewAfterUploadFile = filesView.clickOnUploadButton(); + //TO DO. detect when the file is successfully uploaded + Thread.sleep(3000); + mainViewAfterUploadFile.scrollTillFindElement(FILE_NAME); + assertTrue(mainViewAfterUploadFile.getFileElement().isDisplayed()); + mainViewAfterUploadFile.tapOnFileElement(FILE_NAME); + AppDetailsView appDetailsView = mainViewAfterUploadFile.clickOnDetailsFileElement(); + appDetailsView.checkKeepFileUpToDateCheckbox(); + //assertTrue(appDetailsView.getProgressBar().isDisplayed()); + Thread.sleep(3000); + driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK); + assertTrue(isElementPresent(mainViewAfterUploadFile.getFileElementLayout(), MobileBy.id("com.owncloud.android:id/imageView3"))); + mainViewAfterUploadFile.tapOnFileElement(FILE_NAME); + mainViewAfterUploadFile.clickOnRemoveFileElement(); + mainViewAfterUploadFile.clickOnRemoteAndLocalButton(); + assertTrue(waitForTextPresent("Wait a moment" , mainViewAfterUploadFile.getWaitAMomentTextElement())); + while(mainViewAfterUploadFile.getWaitAMomentTextElement().isDisplayed()){} + Actions.deleteAccount(mainViewAfterUploadFile); + + } + + + @After + public void tearDown() throws Exception { + driver.removeApp("com.owncloud.android"); + driver.quit(); + } + + +} +