fix upload test cases
authorpurigarcia <pgarcia@solidgear.es>
Thu, 14 May 2015 08:13:14 +0000 (10:13 +0200)
committerpurigarcia <pgarcia@solidgear.es>
Thu, 14 May 2015 08:13:14 +0000 (10:13 +0200)
automationTest/src/test/java/com/owncloud/android/test/ui/models/GmailEmailListView.java
automationTest/src/test/java/com/owncloud/android/test/ui/models/ImageView.java
automationTest/src/test/java/com/owncloud/android/test/ui/testSuites/Common.java
automationTest/src/test/java/com/owncloud/android/test/ui/testSuites/UploadTestSuite.java

index 8690eb5..43084ff 100644 (file)
@@ -4,6 +4,8 @@ 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.NoSuchElementException;
 import org.openqa.selenium.support.PageFactory;
 
 public class GmailEmailListView {
@@ -12,6 +14,9 @@ public class GmailEmailListView {
        
        @AndroidFindBy(uiAutomator = "new UiSelector().description(\"me about UploadFile,  on May 11, conversation read\")")
        private AndroidElement email;
+       @AndroidFindBy(uiAutomator = "new UiSelector().description(\"me about UploadFile,  on 11 May, conversation read\")")
+       private AndroidElement email2;
+       
                
        public GmailEmailListView (AndroidDriver driver) {
                this.driver = driver;
@@ -19,7 +24,11 @@ public class GmailEmailListView {
        }
        
        public GmailEmailView clickOnEmail (){
-               email.click();
+               try{
+                       email.click();
+               }catch (NoSuchElementException e) {
+                       email2.click();
+               }
                GmailEmailView gmailEmailView = new GmailEmailView(driver);
                return gmailEmailView;
        }
index da8c30b..8803b29 100644 (file)
@@ -4,52 +4,55 @@ 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 com.owncloud.android.test.ui.actions.Actions;
+import com.owncloud.android.test.ui.testSuites.Common;
 
 
 public class ImageView {
        final AndroidDriver driver;
-       
+
        @CacheLookup
        @AndroidFindBy(uiAutomator = "new UiSelector().description(\"More options\")")
        private AndroidElement optionsButton;
-       
+
        @AndroidFindBy(name = "Share")
        private AndroidElement shareButton;
-       
+
        @AndroidFindBy(name = "ownCloud")
        private AndroidElement ownCloudButton;
-       
+
+       @AndroidFindBy(name = "Share with ownCloud")
+       private AndroidElement shareWithOwnCloudButton;
+
        @AndroidFindBy(name = "Just once")
        private AndroidElement justOnceButton;
-       
+
        @AndroidFindBy(id = "android:id/resolver_list")
        private AndroidElement sharingAppsLayout;
-       
+
        public ImageView (AndroidDriver driver) {
                this.driver = driver;
                PageFactory.initElements(new AppiumFieldDecorator(driver), this);
        }
-       
+
        public void clickOnOptionsButton(){
                optionsButton.click();
        }
-       
+
        public void clickOnShareButton(){
                shareButton.click();
        }
-       
+
        public void clickOnOwnCloudButton(){
-               if (! ownCloudButton.isDisplayed()) {
+               if(Common.isElementPresent(ownCloudButton)){
                        Actions.scrollTillFindElement("ownCloud", sharingAppsLayout, driver);
-               }
-               ownCloudButton.click();
+                       ownCloudButton.click();
+               }else if(Common.isElementPresent(shareWithOwnCloudButton)){}
        }
-       
+
        public void clickOnJustOnceButton(){
                justOnceButton.click();
        }
index d34e6e2..4e45bb6 100644 (file)
@@ -67,7 +67,7 @@ public class Common{
                }
        }
 
-       protected boolean isElementPresent(AndroidElement element) {
+       public static boolean isElementPresent(AndroidElement element) {
                try{
                        element.isDisplayed();
                } catch (NoSuchElementException e){
index 5e1354c..84c228e 100644 (file)
@@ -14,12 +14,14 @@ import org.junit.runners.MethodSorters;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 
 import com.owncloud.android.test.ui.actions.Actions;
 import com.owncloud.android.test.ui.groups.FailingTestCategory;
 import com.owncloud.android.test.ui.groups.IgnoreTestCategory;
 import com.owncloud.android.test.ui.groups.NoIgnoreTestCategory;
+import com.owncloud.android.test.ui.groups.UnfinishedTestCategory;
 import com.owncloud.android.test.ui.models.FileDetailsView;
 import com.owncloud.android.test.ui.models.ElementMenuOptions;
 import com.owncloud.android.test.ui.models.GmailEmailListView;
@@ -36,9 +38,12 @@ public class UploadTestSuite{
        AndroidDriver driver;
        Common common;
        String FILE_NAME = Config.fileToTestName;
-       
+       String FILE_GMAIL_NAME = Config.fileToTestSendByEmailName;
+       private Boolean fileHasBeenUploadedFromGmail = false;
+       private Boolean fileHasBeenUploaded = false;
+
        @Rule public TestName name = new TestName();
-       
+
 
        @Before
        public void setUp() throws Exception {
@@ -63,11 +68,13 @@ public class UploadTestSuite{
                Common.waitTillElementIsNotPresent(fileListViewAfterUploadFile.getProgressCircular(), 1000);
                common.wait.until(ExpectedConditions.visibilityOf(fileListViewAfterUploadFile.getFileElementLayout().findElement(By.id(FileListView.getLocalFileIndicator()))));
                assertTrue(fileListViewAfterUploadFile.getFileElementLayout().findElement(By.id(FileListView.getLocalFileIndicator())).isDisplayed());
-
+               fileListView = new FileListView(driver);
+               fileListView.scrollTillFindElement(FILE_NAME);
+               assertTrue(fileHasBeenUploaded = fileListView.getFileElement().isDisplayed());
        }
-       
+
        @Test
-       @Category(IgnoreTestCategory.class)
+       @Category(UnfinishedTestCategory.class)
        public void testUploadFromGmail () throws Exception {
                FileListView fileListView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
                driver.startActivity("com.google.android.gm", ".ConversationListActivityGmail");
@@ -78,17 +85,26 @@ public class UploadTestSuite{
                imageView.clickOnOptionsButton();
                imageView.clickOnShareButton();
                imageView.clickOnOwnCloudButton();
-               imageView.clickOnJustOnceButton();
+               //justonce button do not appear always
+               try{
+                       imageView.clickOnJustOnceButton();
+               }catch (NoSuchElementException e) {
+               }
                UploadView uploadView = new UploadView(driver);
                uploadView.clickOUploadButton();
+               driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME);
                driver.startActivity("com.owncloud.android", ".ui.activity.FileDisplayActivity");
-               common.wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name(Config.fileToTestSendByEmailName)));
-               assertEquals(Config.fileToTestSendByEmailName , driver.findElementByName(Config.fileToTestSendByEmailName).getText());
+               common.wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name(FILE_GMAIL_NAME)));
+               assertEquals(Config.fileToTestSendByEmailName , driver.findElementByName(FILE_GMAIL_NAME).getText());
+               fileListView = new FileListView(driver);
+               fileListView.scrollTillFindElement(FILE_GMAIL_NAME);
+               assertTrue(fileHasBeenUploadedFromGmail = fileListView.getFileElement().isDisplayed());
+               //TODO. correct assert if fileListView is shown in grid mode
        }
 
-       
+
        @Test   
-       @Category({IgnoreTestCategory.class, FailingTestCategory.class})
+       @Category({FailingTestCategory.class})
        public void testKeepFileUpToDate () throws Exception {
 
                FileListView fileListView = Actions.login(Config.URL, Config.user,Config.password, Config.isTrusted, driver);
@@ -105,9 +121,8 @@ public class UploadTestSuite{
                fileDetailsView.checkKeepFileUpToDateCheckbox();
                Thread.sleep(3000);
                driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_BACK);
-               //assertTrue(common.isElementPresent(fileListViewAfterUploadFile.getFileElementLayout(), MobileBy.id(FileListView.getFavoriteFileIndicator())));
+               assertTrue(common.isElementPresent(fileListViewAfterUploadFile.getFileElementLayout(), MobileBy.id(FileListView.getFavoriteFileIndicator())));
                assertTrue(fileListViewAfterUploadFile.getFileElementLayout().findElement(By.id(FileListView.getFavoriteFileIndicator())).isDisplayed());
-
        }
 
 
@@ -115,7 +130,13 @@ public class UploadTestSuite{
        public void tearDown() throws Exception {
                common.takeScreenShotOnFailed(name.getMethodName());
                FileListView fileListView = new FileListView(driver);
-               Actions.deleteElement(FILE_NAME,fileListView, driver);
+               if (fileHasBeenUploadedFromGmail) {
+                       Actions.deleteElement(FILE_GMAIL_NAME,fileListView, driver);
+               }
+               if(fileHasBeenUploaded){
+                       Actions.deleteElement(FILE_NAME,fileListView, driver);
+               }
+
                driver.removeApp("com.owncloud.android");
                driver.quit();
        }