This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
EditorPage.java
139 lines (125 loc) · 5.23 KB
/
EditorPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.zanata.page.webtrans;
import java.util.Collections;
import java.util.List;
import org.openqa.selenium.By;
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 com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import lombok.extern.slf4j.Slf4j;
/**
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Slf4j
public class EditorPage extends BasePage {
// first %d is row index, second %d is plural form index (i.e. 0 or 1)
private static final String SOURCE_ID_FMT =
"gwt-debug-%d-source-panel-%d-container";
private static final int SINGULAR = 0;
private static final int PLURAL = 1;
// first %d is row index, second %d is plural form index (i.e. 0-6)
private static final String TARGET_ID_FMT = "gwt-debug-%d-target-%d";
private final By glossaryTableBy = By.id("gwt-debug-glossaryResultTable");
private final By glossaryNoResultBy = By.id("gwt-debug-glossaryNoResult");
@FindBy(id = "gwt-debug-transUnitTable")
private WebElement transUnitTable;
public EditorPage(WebDriver driver) {
super(driver);
}
public EditorPage searchGlossary(final String term) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return input.findElements(glossaryNoResultBy).size() == 1
|| input.findElements(glossaryTableBy).size() == 1;
}
});
WebElement searchBox =
getDriver().findElement(By.id("gwt-debug-glossaryTextBox"));
searchBox.clear();
searchBox.sendKeys(term);
WebElement searchButton =
getDriver()
.findElement(By.id("gwt-debug-glossarySearchButton"));
searchButton.click();
return this;
}
/**
* First row is header: SourceTerm, TargetTerm, Action, Details.
*
* @return a table representing the searchResultTable
*/
public List<List<String>> getGlossaryResultTable() {
return waitForTenSec().until(
new Function<WebDriver, List<List<String>>>() {
@Override
public List<List<String>> apply(WebDriver input) {
if (input.findElements(glossaryNoResultBy).size() == 1) {
return Collections.emptyList();
}
List<List<String>> resultTable =
WebElementUtil.getTwoDimensionList(input,
glossaryTableBy);
log.info("glossary result: {}", resultTable);
return resultTable;
}
});
}
/**
* Get content of a text flow source at given row.
* This assumes the text flow has singular form (i.e. no plural).
* If a test requires to access plural content, this can be changed.
* TODO pahuang rename method name
*
* @param rowIndex
* row index
* @return content of the source
*/
public String getTranslationSourceAtRowIndex(final int rowIndex) {
return getCodeMirrorContent(rowIndex, SOURCE_ID_FMT, SINGULAR);
}
public String getMessageSourceAtRowIndex(int rowIndex, int pluralIndex) {
Preconditions.checkArgument(
pluralIndex == SINGULAR || pluralIndex == PLURAL,
"plural index must be 0 or 1");
return getCodeMirrorContent(rowIndex, SOURCE_ID_FMT, pluralIndex);
}
/**
* Get content of a text flow target at given row.
* This assumes the text flow has singular form (i.e. no plural).
* If a test requires to access plural content, this can be changed.
*
* @param rowIndex
* row index
* @return content of the target
*/
public String getTranslationTargetAtRowIndex(final int rowIndex) {
return getCodeMirrorContent(rowIndex, TARGET_ID_FMT, SINGULAR);
}
private String getCodeMirrorContent(final long rowIndex,
final String idFormat, final int pluralIndex) {
return waitForTenSec().until(new Function<WebDriver, String>() {
@Override
public String apply(WebDriver input) {
// code mirror will turn text into list of <pre>.
List<WebElement> cmTextLines = input.findElement(
By.id(String.format(idFormat, rowIndex, pluralIndex)))
.findElements(By.tagName("pre"));
List<String> contents =
WebElementUtil.elementsToText(cmTextLines);
return Joiner.on("\n").skipNulls().join(contents);
}
});
}
public String getMessageTargetAtRowIndex(int rowIndex, int pluralIndex) {
Preconditions.checkArgument(pluralIndex >= 0 && pluralIndex <= 6,
"plural index must be in range [0,6]");
return getCodeMirrorContent(rowIndex, TARGET_ID_FMT, pluralIndex);
}
}