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

Commit

Permalink
HTML adaptor webdriver tests
Browse files Browse the repository at this point in the history
Basic tests for html file upload. Adds a very basic list of source
strings from the editor page and verifies the text.
  • Loading branch information
djansen-redhat committed Jan 21, 2014
1 parent 74eee0b commit afbf5cc
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
Expand Up @@ -26,4 +26,10 @@ public List<List<String>> getDocumentListTableContent() {
By.id("gwt-debug-documentListTable"));
}

public EditorPage clickDocumentLink(String path, String name) {
String id = "gwt-debug-docLabel-" + path + name;
getDriver().findElement(By.id(id)).click();
return new EditorPage(getDriver());
}

}
Expand Up @@ -4,12 +4,14 @@
import com.google.common.base.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;
import org.zanata.util.WebElementUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -70,4 +72,53 @@ public List<List<String>> apply(WebDriver input) {
});
}

/**
* Get a list of all source strings on the current page.
* These strings do not contain the tags, only the visible text.
* @return String list of source translation targets
*/
public List<String> getTranslationSourceTexts() {
return waitForTenSec().until(
new Function<WebDriver, List<String>>() {
@Override
public List<String> apply(WebDriver input) {
List<String> texts = new ArrayList<String>();
List<WebElement> sourceElements = getDriver()
.findElements(By.className("sourceTable"));
for (WebElement element : sourceElements) {
texts.add(element
.findElement(By.tagName("pre")).getText());
}
return texts;
}
});
}

/**
* Get a list of all source strings on the current page.
* These strings contain the tags in ASCII.
* @return String list of source translation targets HTML content
*/
public List<String> getTranslationSourceContents() {
return waitForTenSec().until(
new Function<WebDriver, List<String>>() {
@Override
public List<String> apply(WebDriver input) {
List<String> texts = new ArrayList<String>();
List<WebElement> sourceElements = getDriver()
.findElements(By.className("sourceTable"));
for (WebElement element : sourceElements) {
WebElement textElement = element
.findElement(By.tagName("pre"));
String elementContent =
(String)((JavascriptExecutor)getDriver())
.executeScript(
"return arguments[0].innerHTML;",
textElement);
texts.add(elementContent);
}
return texts;
}
});
}
}
Expand Up @@ -28,6 +28,6 @@
* href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({ UploadTest.class })
@Suite.SuiteClasses({ HTMLDocumentTypeTest.class, UploadTest.class })
public class DocumentTestSuite {
}
@@ -0,0 +1,107 @@
/*
* 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.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.feature.document;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.DetailedTest;
import org.zanata.page.projects.ProjectSourceDocumentsPage;
import org.zanata.page.webtrans.EditorPage;
import org.zanata.util.CleanDocumentStorageRule;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.TestFileGenerator;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;

import java.io.File;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.zanata.util.FunctionalTestHelper.assumeFalse;

/**
* @author Damian Jansen <a
* href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Category(DetailedTest.class)
public class HTMLDocumentTypeTest {
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();

@Rule
public CleanDocumentStorageRule documentStorageRule =
new CleanDocumentStorageRule();

private TestFileGenerator testFileGenerator = new TestFileGenerator();
private String documentStorageDirectory;

@Before
public void before() {
new BasicWorkFlow().goToHome().deleteCookiesAndRefresh();
documentStorageDirectory =
CleanDocumentStorageRule.getDocumentStoragePath()
.concat(File.separator).concat("documents")
.concat(File.separator);
assumeFalse("", new File(documentStorageDirectory).exists());
}

@Test
public void uploadHTMLFile() {
File htmlfile =
testFileGenerator.generateTestFileWithContent(
"testhtmlfile", ".html",
"<html><title>Test content</title><br>This is <b>Bold</b> text</html>");
String testFileName = htmlfile.getName();
String successfullyUploaded =
"Document file " + testFileName + " uploaded.";
ProjectSourceDocumentsPage projectSourceDocumentsPage =
new LoginWorkFlow().signIn("admin", "admin").goToProjects()
.goToProject("about fedora").goToVersion("master")
.goToSourceDocuments().pressUploadFileButton()
.enterFilePath(htmlfile.getAbsolutePath())
.submitUpload();
assertThat("Document uploaded notification shows",
projectSourceDocumentsPage.getNotificationMessage(),
Matchers.equalTo(successfullyUploaded));
assertThat("Document shows in table",
projectSourceDocumentsPage.sourceDocumentsContains(htmlfile
.getName()));

EditorPage editorPage = projectSourceDocumentsPage.goToProjects()
.goToProject("about fedora").goToVersion("master")
.translate("pl").clickDocumentLink("", testFileName);

assertThat("The first translation source is correct",
editorPage.getTranslationSourceTexts().get(0),
Matchers.equalTo("Test content"));
assertThat("The second translation source content is correct",
editorPage.getTranslationSourceContents().get(1),
Matchers.equalTo("This<span class=\"cm-space\"> </span>is"+
"<span class=\"cm-space\"> </span><span class=\""+
"cm-tag\">&lt;g2&gt;</span>Bold<span class=\"cm-tag\""+
">&lt;/g2&gt;</span><span class=\"cm-space\"> "+
"</span>text"));


}
}

0 comments on commit afbf5cc

Please sign in to comment.