Revision 28c5c87a
Added by Andreas Kohlbecker over 9 years ago
7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/elements/FeatureBlock.java | ||
---|---|---|
30 | 30 |
*/ |
31 | 31 |
public class FeatureBlock extends DrupalBlock { |
32 | 32 |
|
33 |
private List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
|
|
34 |
|
|
35 |
private List<BaseElement> footNotes = new ArrayList<BaseElement>();
|
|
36 |
|
|
37 |
private List<BaseElement> originalSources = new ArrayList<BaseElement>();
|
|
33 |
private List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
|
|
34 |
|
|
35 |
private List<BaseElement> footNotes = new ArrayList<BaseElement>();
|
|
36 |
|
|
37 |
private List<BaseElement> originalSources = new ArrayList<BaseElement>();
|
|
38 | 38 |
|
39 |
private List<DescriptionElementRepresentation> descriptionElements = new ArrayList<DescriptionElementRepresentation>();
|
|
40 |
|
|
41 |
private String featureType = null;
|
|
42 |
|
|
43 |
|
|
44 |
public List<LinkElement> getFootNoteKeys() {
|
|
45 |
return footNoteKeys;
|
|
46 |
}
|
|
47 |
|
|
48 |
public List<BaseElement> getFootNotes() {
|
|
49 |
return footNotes;
|
|
50 |
}
|
|
51 |
|
|
52 |
public List<BaseElement> getOriginalSourcesSections() {
|
|
53 |
return originalSources;
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
public List<DescriptionElementRepresentation> getDescriptionElements() {
|
|
58 |
return descriptionElements;
|
|
59 |
}
|
|
60 |
|
|
61 |
public String getFeatureType() {
|
|
62 |
return featureType;
|
|
63 |
}
|
|
64 |
|
|
65 |
|
|
66 |
/**
|
|
67 |
* @param element
|
|
68 |
*/
|
|
69 |
public FeatureBlock(WebElement element, String enclosingTag, String ... elementTags) {
|
|
70 |
super(element);
|
|
71 |
|
|
72 |
List<WebElement> fnkList = element.findElements(By.className("footnote-key"));
|
|
73 |
for(WebElement fnk : fnkList) {
|
|
74 |
footNoteKeys.add(new LinkElement(fnk.findElement(By.tagName("a"))));
|
|
75 |
}
|
|
76 |
|
|
77 |
List<WebElement> fnList = element.findElements(By.className("footnote"));
|
|
78 |
for(WebElement fn : fnList) {
|
|
79 |
footNotes.add(new BaseElement(fn));
|
|
80 |
}
|
|
81 |
|
|
82 |
List<WebElement> sourcesList = element.findElements(By.className("sources"));
|
|
83 |
for(WebElement source : sourcesList) {
|
|
84 |
originalSources.add(new BaseElement(source));
|
|
85 |
}
|
|
86 |
|
|
87 |
WebElement descriptionElementsRepresentation = element.findElement(By.className("description"));
|
|
88 |
featureType = descriptionElementsRepresentation.getAttribute("id");
|
|
89 |
|
|
90 |
//TODO throw exception instead of making an assetion! selenium should have appropriate exeptions
|
|
91 |
assertEquals("Unexpected tag enclosing description element representations", enclosingTag, descriptionElementsRepresentation.getTagName());
|
|
92 |
|
|
93 |
if(elementTags.length > 1){
|
|
94 |
|
|
95 |
// handle multipart elements e.g. <dt></dt><dd></dd>
|
|
96 |
HashMap<String, List<WebElement>> elementsByTag = new HashMap<String, List<WebElement>>();
|
|
97 |
Integer lastSize = null;
|
|
98 |
for (String elementTag : elementTags) {
|
|
99 |
List<WebElement> foundElements = descriptionElementsRepresentation.findElements(By.tagName(elementTag));
|
|
100 |
if(lastSize != null && foundElements.size() != lastSize){
|
|
101 |
throw new NoSuchElementException("Mulitpart element lists differ in size");
|
|
102 |
}
|
|
103 |
lastSize = foundElements.size();
|
|
104 |
elementsByTag.put(elementTag, foundElements);
|
|
105 |
}
|
|
106 |
|
|
107 |
for (int descriptionElementIndex = 0; descriptionElementIndex < lastSize; descriptionElementIndex++){
|
|
108 |
List<WebElement> elementsByIndex = new ArrayList<WebElement>();
|
|
109 |
for (String elementTag : elementTags) {
|
|
110 |
elementsByIndex.add(elementsByTag.get(elementTag).get(descriptionElementIndex));
|
|
111 |
}
|
|
112 |
descriptionElements.add(new MultipartDescriptionElementRepresentation(elementsByIndex.toArray(new WebElement[elementsByIndex.size()])));
|
|
113 |
|
|
114 |
}
|
|
115 |
} else {
|
|
116 |
// handle single elements
|
|
117 |
String elementTag = elementTags[0];
|
|
118 |
for(WebElement el : descriptionElementsRepresentation.findElements(By.tagName( elementTag ))) {
|
|
119 |
descriptionElements.add(new DescriptionElementRepresentation(el));
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
}
|
|
124 |
|
|
125 |
/**
|
|
126 |
* @param indent
|
|
127 |
* @param computedFontSize
|
|
128 |
* @param expectedCssDisplay
|
|
129 |
* @param expectedListStyleType only applies if cssDisplay equals list-item
|
|
130 |
* @param expectedListStylePosition only applies if cssDisplay equals list-item
|
|
131 |
* @param expectedListStyleImage only applies if cssDisplay equals list-item
|
|
132 |
*/
|
|
133 |
public void testDescriptionElementLayout(int descriptionElementId, int indent, int computedFontSize
|
|
134 |
, String expectedCssDisplay, String expectedListStyleType, String expectedListStylePosition, String expectedListStyleImage) {
|
|
135 |
|
|
136 |
DescriptionElementRepresentation firstDescriptionElement = getDescriptionElements().get(descriptionElementId);
|
|
137 |
|
|
138 |
if(firstDescriptionElement instanceof MultipartDescriptionElementRepresentation){
|
|
139 |
int multipartElementIndex = 0;
|
|
140 |
firstDescriptionElement = ((MultipartDescriptionElementRepresentation)firstDescriptionElement).multipartElements.get(multipartElementIndex);
|
|
141 |
}
|
|
142 |
int parentX = getElement().getLocation().getX();
|
|
143 |
int elementX = firstDescriptionElement.getElement().getLocation().getX();
|
|
144 |
double elementPadLeft = pxSizeToDouble(firstDescriptionElement.getElement().getCssValue("padding-left"));
|
|
145 |
|
|
146 |
assertEquals(indent, elementX - parentX + elementPadLeft, PIXEL_TOLERANCE);
|
|
147 |
assertEquals(computedFontSize, firstDescriptionElement.getComputedFontSize(), 0.5);
|
|
148 |
assertEquals(expectedCssDisplay, firstDescriptionElement.getElement().getCssValue("display"));
|
|
149 |
|
|
150 |
if(expectedCssDisplay.equals("list-item")){
|
|
151 |
assertEquals(expectedListStylePosition, firstDescriptionElement.getElement().getCssValue("list-style-position"));
|
|
152 |
assertEquals(expectedListStyleImage, firstDescriptionElement.getElement().getCssValue("list-style-image"));
|
|
153 |
assertEquals(expectedListStyleType, firstDescriptionElement.getElement().getCssValue("list-style-type"));
|
|
154 |
}
|
|
155 |
}
|
|
39 |
private List<DescriptionElementRepresentation> descriptionElements = new ArrayList<DescriptionElementRepresentation>();
|
|
40 |
|
|
41 |
private String featureType = null;
|
|
42 |
|
|
43 |
|
|
44 |
public List<LinkElement> getFootNoteKeys() {
|
|
45 |
return footNoteKeys;
|
|
46 |
}
|
|
47 |
|
|
48 |
public List<BaseElement> getFootNotes() {
|
|
49 |
return footNotes;
|
|
50 |
}
|
|
51 |
|
|
52 |
public List<BaseElement> getOriginalSourcesSections() {
|
|
53 |
return originalSources;
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
public List<DescriptionElementRepresentation> getDescriptionElements() {
|
|
58 |
return descriptionElements;
|
|
59 |
}
|
|
60 |
|
|
61 |
public String getFeatureType() {
|
|
62 |
return featureType;
|
|
63 |
}
|
|
64 |
|
|
65 |
|
|
66 |
/**
|
|
67 |
* @param element
|
|
68 |
*/
|
|
69 |
public FeatureBlock(WebElement element, String enclosingTag, String ... elementTags) {
|
|
70 |
super(element);
|
|
71 |
|
|
72 |
List<WebElement> fnkList = element.findElements(By.className("footnote-key"));
|
|
73 |
for(WebElement fnk : fnkList) {
|
|
74 |
footNoteKeys.add(new LinkElement(fnk.findElement(By.tagName("a"))));
|
|
75 |
}
|
|
76 |
|
|
77 |
List<WebElement> fnList = element.findElements(By.className("footnote"));
|
|
78 |
for(WebElement fn : fnList) {
|
|
79 |
footNotes.add(new BaseElement(fn));
|
|
80 |
}
|
|
81 |
|
|
82 |
List<WebElement> sourcesList = element.findElements(By.className("sources"));
|
|
83 |
for(WebElement source : sourcesList) {
|
|
84 |
originalSources.add(new BaseElement(source));
|
|
85 |
}
|
|
86 |
|
|
87 |
WebElement descriptionElementsRepresentation = element.findElement(By.className("feature-block-elements"));
|
|
88 |
featureType = descriptionElementsRepresentation.getAttribute("id");
|
|
89 |
|
|
90 |
//TODO throw exception instead of making an assetion! selenium should have appropriate exeptions
|
|
91 |
assertEquals("Unexpected tag enclosing description element representations", enclosingTag, descriptionElementsRepresentation.getTagName());
|
|
92 |
|
|
93 |
if(elementTags.length > 1){
|
|
94 |
|
|
95 |
// handle multipart elements e.g. <dt></dt><dd></dd>
|
|
96 |
HashMap<String, List<WebElement>> elementsByTag = new HashMap<String, List<WebElement>>();
|
|
97 |
Integer lastSize = null;
|
|
98 |
for (String elementTag : elementTags) {
|
|
99 |
List<WebElement> foundElements = descriptionElementsRepresentation.findElements(By.tagName(elementTag));
|
|
100 |
if(lastSize != null && foundElements.size() != lastSize){
|
|
101 |
throw new NoSuchElementException("Mulitpart element lists differ in size");
|
|
102 |
}
|
|
103 |
lastSize = foundElements.size();
|
|
104 |
elementsByTag.put(elementTag, foundElements);
|
|
105 |
}
|
|
106 |
|
|
107 |
for (int descriptionElementIndex = 0; descriptionElementIndex < lastSize; descriptionElementIndex++){
|
|
108 |
List<WebElement> elementsByIndex = new ArrayList<WebElement>();
|
|
109 |
for (String elementTag : elementTags) {
|
|
110 |
elementsByIndex.add(elementsByTag.get(elementTag).get(descriptionElementIndex));
|
|
111 |
}
|
|
112 |
descriptionElements.add(new MultipartDescriptionElementRepresentation(elementsByIndex.toArray(new WebElement[elementsByIndex.size()])));
|
|
113 |
|
|
114 |
}
|
|
115 |
} else {
|
|
116 |
// handle single elements
|
|
117 |
String elementTag = elementTags[0];
|
|
118 |
for(WebElement el : descriptionElementsRepresentation.findElements(By.tagName( elementTag ))) {
|
|
119 |
descriptionElements.add(new DescriptionElementRepresentation(el));
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
}
|
|
124 |
|
|
125 |
/**
|
|
126 |
* @param indent
|
|
127 |
* @param computedFontSize
|
|
128 |
* @param expectedCssDisplay
|
|
129 |
* @param expectedListStyleType only applies if cssDisplay equals list-item
|
|
130 |
* @param expectedListStylePosition only applies if cssDisplay equals list-item
|
|
131 |
* @param expectedListStyleImage only applies if cssDisplay equals list-item
|
|
132 |
*/
|
|
133 |
public void testDescriptionElementLayout(int descriptionElementId, int indent, int computedFontSize
|
|
134 |
, String expectedCssDisplay, String expectedListStyleType, String expectedListStylePosition, String expectedListStyleImage) {
|
|
135 |
|
|
136 |
DescriptionElementRepresentation firstDescriptionElement = getDescriptionElements().get(descriptionElementId);
|
|
137 |
|
|
138 |
if(firstDescriptionElement instanceof MultipartDescriptionElementRepresentation){
|
|
139 |
int multipartElementIndex = 0;
|
|
140 |
firstDescriptionElement = ((MultipartDescriptionElementRepresentation)firstDescriptionElement).multipartElements.get(multipartElementIndex);
|
|
141 |
}
|
|
142 |
int parentX = getElement().getLocation().getX();
|
|
143 |
int elementX = firstDescriptionElement.getElement().getLocation().getX();
|
|
144 |
double elementPadLeft = pxSizeToDouble(firstDescriptionElement.getElement().getCssValue("padding-left"));
|
|
145 |
|
|
146 |
assertEquals(indent, elementX - parentX + elementPadLeft, PIXEL_TOLERANCE);
|
|
147 |
assertEquals(computedFontSize, firstDescriptionElement.getComputedFontSize(), 0.5);
|
|
148 |
assertEquals(expectedCssDisplay, firstDescriptionElement.getElement().getCssValue("display"));
|
|
149 |
|
|
150 |
if(expectedCssDisplay.equals("list-item")){
|
|
151 |
assertEquals(expectedListStylePosition, firstDescriptionElement.getElement().getCssValue("list-style-position"));
|
|
152 |
assertEquals(expectedListStyleImage, firstDescriptionElement.getElement().getCssValue("list-style-image"));
|
|
153 |
assertEquals(expectedListStyleType, firstDescriptionElement.getElement().getCssValue("list-style-type"));
|
|
154 |
}
|
|
155 |
}
|
|
156 | 156 |
|
157 | 157 |
} |
Also available in: Unified diff
refactoring the feature node blocks - 1