8f1bccf9d1db89dbc3c3bb9cac38a28281188cad
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / testSuites / LoginTestSuite.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author purigarcia
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 package com.owncloud.android.test.ui.testSuites;
22
23 import static org.junit.Assert.*;
24 import io.appium.java_client.android.AndroidDriver;
25
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.experimental.categories.Category;
30 import org.junit.rules.TestName;
31 import org.junit.runners.MethodSorters;
32 import org.junit.FixMethodOrder;
33 import org.junit.Test;
34 import org.openqa.selenium.ScreenOrientation;
35
36 import com.owncloud.android.test.ui.actions.Actions;
37 import com.owncloud.android.test.ui.groups.*;
38 import com.owncloud.android.test.ui.models.LoginForm;
39 import com.owncloud.android.test.ui.models.FileListView;
40 import com.owncloud.android.test.ui.models.MenuList;
41 import com.owncloud.android.test.ui.models.SettingsView;
42
43 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
44 public class LoginTestSuite{
45 AndroidDriver driver;
46 Common common;
47
48 @Rule public TestName name = new TestName();
49
50 @Before
51 public void setUp() throws Exception {
52 common=new Common();
53 driver=common.setUpCommonDriver();
54 }
55
56 @Test
57 @Category({NoIgnoreTestCategory.class})
58 public void test1LoginPortrait () throws Exception {
59 driver.rotate(ScreenOrientation.PORTRAIT);
60
61 Actions.login(Config.URL, Config.user,
62 Config.password, Config.isTrusted, driver);
63 common.assertIsInFileListView();
64 }
65
66 @Test
67 @Category({NoIgnoreTestCategory.class})
68 public void test2LoginLandscape () throws Exception {
69 driver.rotate(ScreenOrientation.LANDSCAPE);
70 Actions.login(Config.URL, Config.user,
71 Config.password, Config.isTrusted, driver);
72 common.assertIsInFileListView();
73 }
74
75 @Test
76 @Category({NoIgnoreTestCategory.class})
77 public void testLoginAndShowFiles () throws Exception {
78 driver.rotate(ScreenOrientation.PORTRAIT);
79
80 FileListView fileListView = Actions.login(Config.URL, Config.user,
81 Config.password, Config.isTrusted, driver);
82 common.assertIsInFileListView();
83
84 fileListView.scrollTillFindElement(Config.fileWhichIsInTheServer1);
85 assertTrue(fileListView.getFileElement().isDisplayed());
86 }
87
88
89
90 @Test
91 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
92 public void test3MultiAccountRotate () throws Exception {
93 driver.rotate(ScreenOrientation.LANDSCAPE);
94 FileListView fileListView = Actions.login(Config.URL, Config.user,
95 Config.password, Config.isTrusted, driver);
96 common.assertIsInFileListView();
97
98 driver.rotate(ScreenOrientation.PORTRAIT);
99 MenuList menu = fileListView.clickOnMenuButton();
100 SettingsView settingsView = menu.clickOnSettingsButton();
101
102 settingsView.tapOnAddAccount(1, 1000);
103 fileListView = Actions.login(Config.URL2, Config.user2,
104 Config.password2, Config.isTrusted2, driver);
105 common.assertIsInSettingsView();
106 }
107
108 @Test
109 @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
110 public void testMultiAccountAndShowFiles () throws Exception {
111 driver.rotate(ScreenOrientation.LANDSCAPE);
112 FileListView fileListView = Actions.login(Config.URL, Config.user,
113 Config.password, Config.isTrusted, driver);
114 common.assertIsInFileListView();
115 fileListView.scrollTillFindElement(Config.fileWhichIsInTheServer1);
116 assertTrue(fileListView.getFileElement().isDisplayed());
117
118 driver.rotate(ScreenOrientation.PORTRAIT);
119 MenuList menu = fileListView.clickOnMenuButton();
120 SettingsView settingsView = menu.clickOnSettingsButton();
121
122 settingsView.tapOnAddAccount(1, 1000);
123 fileListView = Actions.login(Config.URL2, Config.user2,
124 Config.password2, Config.isTrusted2, driver);
125 common.assertIsInSettingsView();
126 settingsView.tapOnAccountElement(2,1, 100);
127 common.assertIsInFileListView();
128
129 fileListView.scrollTillFindElement(Config.fileWhichIsInTheServer2);
130 assertTrue(fileListView.getFileElement().isDisplayed());
131 }
132
133 @Test
134 @Category({NoIgnoreTestCategory.class})
135 public void test4ExistingAccountRotate () throws Exception {
136 driver.rotate(ScreenOrientation.PORTRAIT);
137 FileListView fileListView = Actions.login(Config.URL, Config.user,
138 Config.password, Config.isTrusted, driver);
139 common.assertIsInFileListView();
140
141 driver.rotate(ScreenOrientation.LANDSCAPE);
142 MenuList menu = fileListView.clickOnMenuButton();
143 SettingsView settingsView = menu.clickOnSettingsButton();
144 settingsView.tapOnAddAccount(1, 1000);
145
146 LoginForm loginForm = new LoginForm(driver);
147 fileListView = Actions.login(Config.URL, Config.user,Config.password,
148 Config.isTrusted, driver);
149 assertTrue(common.waitForTextPresent("An account for the same user and"
150 + " server already exists in the device",
151 loginForm.getAuthStatusText()));
152 }
153
154 @Test
155 @Category({NoIgnoreTestCategory.class})
156 public void test5ChangePasswordWrong () throws Exception {
157 driver.rotate(ScreenOrientation.PORTRAIT);
158 FileListView fileListView = Actions.login(Config.URL, Config.user,
159 Config.password, Config.isTrusted, driver);
160 common.assertIsInFileListView();
161 MenuList menu = fileListView.clickOnMenuButton();
162 SettingsView settingsView = menu.clickOnSettingsButton();
163 settingsView.tapOnAccountElement(1,1, 1000);
164 LoginForm changePasswordForm = settingsView
165 .clickOnChangePasswordElement();
166 changePasswordForm.typePassword("WrongPassword");
167 changePasswordForm.clickOnConnectButton();
168 assertTrue(common.waitForTextPresent("Wrong username or password",
169 changePasswordForm.getAuthStatusText()));
170 }
171
172
173 @After
174 public void tearDown() throws Exception {
175 common.takeScreenShotOnFailed(name.getMethodName());
176 driver.removeApp("com.owncloud.android");
177 driver.quit();
178 }
179
180
181 }