Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Update UploadTest on review comments
Browse files Browse the repository at this point in the history
Don't use globals for elements that may not exist.
Clear cached data between functions.
Wrong licence year.
Also added a test step for verifying the file is saved to the intended
location.
  • Loading branch information
djansen-redhat committed Sep 10, 2013
1 parent 59906ef commit 1ad284d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
Expand All @@ -20,7 +20,6 @@
*/
package org.zanata.page.projects;

import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -29,50 +28,37 @@

import java.util.List;

@Slf4j
public class ProjectSourceDocumentsPage extends BasePage
{
@FindBy(id = "iterationDocumentsForm:data_table:tb")
private WebElement documentTableTBody;

@FindBy(id = "uploadSidebar:uploadDocumentButton")
private WebElement uploadDocumentButton;

@FindBy(id = "uploadDocForm:uploadFilename")
private WebElement uploadFilenameInput;

@FindBy(id = "uploadDocForm:uploadButton")
private WebElement uploadButton;

@FindBy(id = "uploadDocForm:cancelUploadButton")
private WebElement cancelUploadButton;

public ProjectSourceDocumentsPage(final WebDriver driver)
{
super(driver);
}

public ProjectSourceDocumentsPage pressUploadFileButton()
{
uploadDocumentButton.click();
getDriver().findElement(By.id("uploadSidebar:uploadDocumentButton")).click();
return new ProjectSourceDocumentsPage(getDriver());
}

public ProjectSourceDocumentsPage enterFilePath(String filePath)
{
uploadFilenameInput.sendKeys(filePath);
getDriver().findElement(By.id("uploadDocForm:uploadFilename")).sendKeys(filePath);
return new ProjectSourceDocumentsPage(getDriver());
}

public ProjectSourceDocumentsPage cancelUpload()
{
cancelUploadButton.click();
getDriver().findElement(By.id("uploadDocForm:cancelUploadButton")).click();
return new ProjectSourceDocumentsPage(getDriver());
}

public ProjectSourceDocumentsPage submitUpload()
{
uploadButton.click();
getDriver().findElement(By.id("uploadDocForm:uploadButton")).click();
return new ProjectSourceDocumentsPage(getDriver());
}

Expand Down
Expand Up @@ -21,13 +21,15 @@
package org.zanata.feature.document;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.DetailedTest;
import org.zanata.page.projects.ProjectSourceDocumentsPage;
import org.zanata.util.PropertiesHolder;
import org.zanata.util.ResetDatabaseRule;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;

import java.io.File;
Expand All @@ -45,26 +47,40 @@ public class UploadTest
@ClassRule
public static ResetDatabaseRule resetDatabaseRule = new ResetDatabaseRule(ResetDatabaseRule.Config.WithData);

@Before
public void before()
{
new BasicWorkFlow().goToHome().deleteCookiesAndRefresh();
}

@Test
public void uploadedDocumentIsInFilesystem()
{
String successfullyUploaded = "Document file uploadedDocumentIsInFilesystem.txt uploaded.";
String testFileName = "uploadedDocumentIsInFilesystem.txt";
String filePath = PropertiesHolder.getProperty("zanata.testdata.directory")
String originalFilePath = PropertiesHolder.getProperty("zanata.testdata.directory")
.concat(File.separator)
.concat(testFileName);
String newFilePath = PropertiesHolder.getProperty("document.storage.directory")
.concat(File.separator).concat("documents");

assertThat("Data file "+testFileName+" exists", new File(filePath).exists());
assertThat("Data file "+testFileName+" exists", new File(originalFilePath).exists());
// We should be able to assume the target dir is non-existent
assertThat("Target directory does not exist", !(new File(newFilePath).exists()));

ProjectSourceDocumentsPage projectSourceDocumentsPage = new LoginWorkFlow().signIn("admin", "admin")
.goToProjects()
.goToProject("about fedora")
.goToVersion("master")
.goToSourceDocuments()
.pressUploadFileButton()
.enterFilePath(filePath)
.enterFilePath(originalFilePath)
.submitUpload();

// We should be able to assume the new file is the only file
assertThat("There is only one uploaded source file", new File(newFilePath).list().length,
Matchers.equalTo(1));

assertThat("Document uploaded notification shows",
projectSourceDocumentsPage.getNotificationMessage(), Matchers.equalTo(successfullyUploaded));
assertThat("Document shows in table", projectSourceDocumentsPage.sourceDocumentsContains(testFileName));
Expand Down Expand Up @@ -170,4 +186,5 @@ public void failOnInvalidFileUpload()
projectSourceDocumentsPage.assertNoCriticalErrors();
// TODO: Verify graceful handling of scenario
}

}

0 comments on commit 1ad284d

Please sign in to comment.