Project

General

Profile

« Previous | Next » 

Revision f0d48bd8

Added by Andreas Kohlbecker over 9 years ago

test for #4423 (DescriptionElement media no longer visible)

View differences:

7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/ElementUtils.java
12 12
import java.util.ArrayList;
13 13
import java.util.List;
14 14

  
15
import org.apache.log4j.Logger;
15 16
import org.openqa.selenium.By;
16 17
import org.openqa.selenium.WebElement;
18
import org.openqa.selenium.support.ui.WebDriverWait;
17 19

  
18 20
import eu.etaxonomy.dataportal.elements.BaseElement;
21
import eu.etaxonomy.dataportal.elements.GalleryImage;
19 22
import eu.etaxonomy.dataportal.elements.LinkElement;
23
import eu.etaxonomy.dataportal.pages.PortalPage;
24
import eu.etaxonomy.dataportal.selenium.AllTrue;
25
import eu.etaxonomy.dataportal.selenium.ChildElementVisible;
26
import eu.etaxonomy.dataportal.selenium.JUnitWebDriverWait;
20 27

  
21 28
/**
22 29
 * @author andreas
......
25 32
 */
26 33
public class ElementUtils {
27 34

  
28
	/**
29
	 * @param fnListElements
30
	 * @return
31
	 */
32
	public static List<BaseElement> baseElementsFromFootNoteListElements(List<WebElement> fnListElements) {
33
		List<BaseElement> footNotes = new ArrayList<BaseElement>();
34
		for(WebElement fn : fnListElements) {
35
			footNotes.add(new BaseElement(fn));
36
		}
37
		return footNotes;
38
	}
39

  
40
	/**
41
	 * @param fnkListElements
42
	 * @return
43
	 */
44
	public static List<LinkElement> linkElementsFromFootNoteKeyListElements(List<WebElement> fnkListElements) {
45
		List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
46
		for(WebElement fnk : fnkListElements) {
47
			footNoteKeys.add(new LinkElement(fnk));
48
		}
49
		return footNoteKeys;
50
	}
35

  
36
    public static final Logger logger = Logger.getLogger(ElementUtils.class);
37

  
38
    /**
39
     * @param fnListElements
40
     * @return
41
     */
42
    public static List<BaseElement> baseElementsFromFootNoteListElements(List<WebElement> fnListElements) {
43
        List<BaseElement> footNotes = new ArrayList<BaseElement>();
44
        for(WebElement fn : fnListElements) {
45
            footNotes.add(new BaseElement(fn));
46
        }
47
        return footNotes;
48
    }
49

  
50
    /**
51
     * @param fnkListElements
52
     * @return
53
     */
54
    public static List<LinkElement> linkElementsFromFootNoteKeyListElements(List<WebElement> fnkListElements) {
55
        List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
56
        for(WebElement fnk : fnkListElements) {
57
            footNoteKeys.add(new LinkElement(fnk));
58
        }
59
        return footNoteKeys;
60
    }
61

  
62
    /**
63
     * @param wait
64
     * @return a two dimensional array representing the media items in the gallery, or null if no gallery exists.
65
     */
66
    public static List<List<GalleryImage>> getGalleryImages(WebElement webElement, WebDriverWait wait) {
67

  
68

  
69
        WebElement gallery = webElement.findElement(By.className("media_gallery"));
70

  
71
        if( gallery == null){
72
            return null;
73
        }
74

  
75
        ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>();
76

  
77
        List<WebElement> tableRows = gallery.findElements(By.tagName("tr"));
78
        logger.debug("GalleryImages - total rows " + tableRows.size());
79
        // loop table rows
80
        for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){
81
            logger.debug("GalleryImages - gallery row " + rowId );
82
            List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td"));
83
            logger.debug("GalleryImages - number of image cells: " + imageCells.size());
84
            List<WebElement> captionCells = null;
85
            if(tableRows.size() > rowId * 2 + 1){
86
                captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td"));
87
                logger.debug("GalleryImages - number of caption cells: " + captionCells.size());
88
            }
89

  
90
            galleryImageRows.add(new ArrayList<GalleryImage>());
91

  
92
            // loop table cells in row
93
            for(int cellId = 0; cellId < imageCells.size(); cellId++) {
94
                logger.debug("cellId:" + cellId);
95
                WebElement imageCell = imageCells.get(cellId);
96
                WebElement captionCell = null;
97
                if(captionCells != null && captionCells.size() > cellId){
98
                    captionCell = captionCells.get(cellId);
99
                    wait.until(new AllTrue(
100
                            new ChildElementVisible(imageCell, By.tagName("img")),
101
                            new ChildElementVisible(captionCell, By.tagName("dl"))
102
                    ));
103

  
104
                } else {
105
                    wait.until(new ChildElementVisible(imageCell, By.tagName("img")));
106
                }
107
                galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell));
108
            }
109

  
110
        }
111

  
112
        return galleryImageRows;
113
    }
114

  
51 115

  
52 116
}

Also available in: Unified diff