50ddb3904264b8b80fd6c7f93f935fdb25d10a02
[pub/Android/ownCloud.git] / automationTest / src / test / java / com / owncloud / android / test / ui / testSuites / UploadTestSuite.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
24 import static org.junit.Assert.*;
25 import io.appium.java_client.MobileBy;
26 import io.appium.java_client.android.AndroidDriver;
27
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.experimental.categories.Category;
32 import org.junit.rules.TestName;
33 import org.junit.runners.MethodSorters;
34 import org.junit.FixMethodOrder;
35 import org.junit.Test;
36 import org.openqa.selenium.By;
37 import org.openqa.selenium.NoSuchElementException;
38 import org.openqa.selenium.support.ui.ExpectedConditions;
39
40 import com.owncloud.android.test.ui.actions.Actions;
41 import com.owncloud.android.test.ui.groups.FailingTestCategory;
42 import com.owncloud.android.test.ui.groups.IgnoreTestCategory;
43 import com.owncloud.android.test.ui.groups.NoIgnoreTestCategory;
44 import com.owncloud.android.test.ui.groups.UnfinishedTestCategory;
45 import com.owncloud.android.test.ui.models.FileDetailsView;
46 import com.owncloud.android.test.ui.models.ElementMenuOptions;
47 import com.owncloud.android.test.ui.models.GmailEmailListView;
48 import com.owncloud.android.test.ui.models.GmailEmailView;
49 import com.owncloud.android.test.ui.models.ImageView;
50 import com.owncloud.android.test.ui.models.FileListView;
51 import com.owncloud.android.test.ui.models.UploadView;
52
53
54 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
55 @Category({NoIgnoreTestCategory.class})
56 public class UploadTestSuite{
57
58 AndroidDriver driver;
59 Common common;
60 String FILE_NAME = Config.fileToTestName;
61 String FILE_GMAIL_NAME = Config.fileToTestSendByEmailName;
62 private Boolean fileHasBeenUploadedFromGmail = false;
63 private Boolean fileHasBeenUploaded = false;
64
65 @Rule public TestName name = new TestName();
66
67
68 @Before
69 public void setUp() throws Exception {
70 common=new Common();
71 driver=common.setUpCommonDriver();
72 }
73
74 @Test
75 @Category(NoIgnoreTestCategory.class)
76 public void testUploadFile () throws Exception {
77
78 FileListView fileListView = Actions.login(Config.URL, Config.user,
79 Config.password, Config.isTrusted, driver);
80 common.assertIsInFileListView();
81
82 //check if the file already exists and if true, delete it
83 Actions.deleteElement(FILE_NAME, fileListView, driver);
84
85 FileListView fileListViewAfterUploadFile = Actions
86 .uploadFile(FILE_NAME, fileListView);
87
88 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
89 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
90 Common.waitTillElementIsNotPresent(
91 fileListViewAfterUploadFile.getProgressCircular(), 1000);
92 common.wait.until(ExpectedConditions.visibilityOf(
93 fileListViewAfterUploadFile.getFileElementLayout()
94 .findElement(By.id(FileListView.getLocalFileIndicator()))));
95 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
96 .findElement(By.id(FileListView.getLocalFileIndicator()))
97 .isDisplayed());
98 fileListView = new FileListView(driver);
99 fileListView.scrollTillFindElement(FILE_NAME);
100 assertTrue(
101 fileHasBeenUploaded = fileListView.getFileElement().isDisplayed());
102 }
103
104 @Test
105 @Category(UnfinishedTestCategory.class)
106 public void testUploadFromGmail () throws Exception {
107 FileListView fileListView = Actions.login(Config.URL, Config.user,
108 Config.password, Config.isTrusted, driver);
109 driver.startActivity("com.google.android.gm",
110 ".ConversationListActivityGmail");
111 GmailEmailListView gmailEmailListView = new GmailEmailListView(driver);
112 Thread.sleep(3000);
113 GmailEmailView gmailEmailView = gmailEmailListView.clickOnEmail();
114 ImageView imageView = gmailEmailView.clickOnfileButton();
115 imageView.clickOnOptionsButton();
116 imageView.clickOnShareButton();
117 imageView.clickOnOwnCloudButton();
118 //justonce button do not appear always
119 try{
120 imageView.clickOnJustOnceButton();
121 }catch (NoSuchElementException e) {
122 }
123 UploadView uploadView = new UploadView(driver);
124 uploadView.clickOUploadButton();
125 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
126 driver.startActivity("com.owncloud.android",
127 ".ui.activity.FileDisplayActivity");
128 common.wait.until(ExpectedConditions
129 .visibilityOfAllElementsLocatedBy(By.name(FILE_GMAIL_NAME)));
130 assertEquals(Config.fileToTestSendByEmailName ,
131 driver.findElementByName(FILE_GMAIL_NAME).getText());
132 fileListView = new FileListView(driver);
133 fileListView.scrollTillFindElement(FILE_GMAIL_NAME);
134 assertTrue(fileHasBeenUploadedFromGmail = fileListView
135 .getFileElement().isDisplayed());
136 //TODO. correct assert if fileListView is shown in grid mode
137 }
138
139
140 @Test
141 @Category({FailingTestCategory.class})
142 public void testKeepFileUpToDate () throws Exception {
143
144 FileListView fileListView = Actions.login(Config.URL, Config.user,
145 Config.password, Config.isTrusted, driver);
146 common.assertIsInFileListView();
147
148 Common.waitTillElementIsNotPresent(fileListView.getProgressCircular(),
149 1000);
150
151 FileListView fileListViewAfterUploadFile = Actions
152 .uploadFile(FILE_NAME, fileListView);
153 fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
154 assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
155
156 ElementMenuOptions menuOptions = fileListViewAfterUploadFile
157 .longPressOnElement(FILE_NAME);
158 FileDetailsView fileDetailsView = menuOptions.clickOnDetails();
159 fileDetailsView.checkKeepFileUpToDateCheckbox();
160 Thread.sleep(3000);
161 driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
162 assertTrue(common.isElementPresent(
163 fileListViewAfterUploadFile.getFileElementLayout(),
164 MobileBy.id(FileListView.getFavoriteFileIndicator())));
165 assertTrue(fileListViewAfterUploadFile.getFileElementLayout()
166 .findElement(By.id(FileListView.getFavoriteFileIndicator()))
167 .isDisplayed());
168 }
169
170
171 @After
172 public void tearDown() throws Exception {
173 common.takeScreenShotOnFailed(name.getMethodName());
174 FileListView fileListView = new FileListView(driver);
175 if (fileHasBeenUploadedFromGmail) {
176 Actions.deleteElement(FILE_GMAIL_NAME,fileListView, driver);
177 }
178 if(fileHasBeenUploaded){
179 Actions.deleteElement(FILE_NAME,fileListView, driver);
180 }
181
182 driver.removeApp("com.owncloud.android");
183 driver.quit();
184 }
185
186
187 }
188