Project

General

Profile

« Previous | Next » 

Revision adfb51b3

Added by Andreas Kohlbecker over 11 years ago

fixing #2987 (selenium test Illicium@floramalesiana(eu.etaxonomy.dataportal.selenium.tests.flMalesiana.FloraMalesiana_OriginalSourceTest) fails due to timeouts) and adapting code to selenium 2.26.0 in pom

View differences:

7.x/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/TaxonSearchResultPage.java
35 35
 */
36 36
public class TaxonSearchResultPage extends GenericPortalPage {
37 37

  
38
	public static final Logger logger = Logger.getLogger(TaxonSearchResultPage.class);
39

  
40
	private static String drupalPagePathBase = "cdm_dataportal/search/taxon";
41

  
42
	@FindBy(id="search_results")
43
	@CacheLookup
44
	private WebElement searchResults;
45

  
46
	//class=page_options
47
	@FindBy(className="page_options")
48
	@CacheLookup
49
	private WebElement pageOptions;
50

  
51
	//class=pager
52
	@FindBy(className="pager")
53
	@CacheLookup
54
	private WebElement pager;
55

  
56

  
57
	/* (non-Javadoc)
58
	 * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
59
	 */
60
	@Override
61
	protected String getDrupalPageBase() {
62
		return drupalPagePathBase;
63
	}
64

  
65
	/**
66
	 * @param driver
67
	 * @param context
68
	 * @throws Exception
69
	 */
70
	public TaxonSearchResultPage(WebDriver driver, DataPortalContext context) throws Exception {
71
		super(driver, context);
72
	}
73

  
74

  
75
	/**
76
	 * Find and return the result n-th item of the result list.
77
	 * The item can be specified by the index paramter.
78
	 * @param index 1-based index to identify the resultset item.
79
	 * This index will be used in a xpath query.
80
	 * @return
81
	 */
82
	public TaxonListElement getResultItem(int index) {
83

  
84
		TaxonListElement entry = new TaxonListElement(searchResults.findElement(By.xpath("ul/li[" + index + "]")));
85

  
86
		return entry;
87
	}
88

  
89
	/**
90
	 * Find and returns all items of the result list.
91
	 * @return
92
	 */
93
	public List<TaxonListElement> getResultItems() {
94

  
95
		List<WebElement> entryList = searchResults.findElements(By.xpath("/ul/li"));
96
		List<TaxonListElement> taxonListElements = new ArrayList<TaxonListElement>();
97
		for(WebElement entry : entryList){
98
			taxonListElements.add(new TaxonListElement(entry));
99
		}
100
		return taxonListElements;
101
	}
102

  
103
	/**
104
	 * @throws Exception
105
	 *
106
	 */
107
	@SuppressWarnings("unchecked")
108
	public <T extends PortalPage> T  clickTaxonName(TaxonListElement taxonListElement) throws Exception {
109

  
110
		LinkElement taxonlink = new LinkElement(taxonListElement.getElement().findElement(By.tagName("a")));
111
		return (T) clickLink(taxonlink, new VisibilityOfElementLocated(By.id("featureTOC")), TaxonProfilePage.class, 2l, TimeUnit.MINUTES);
112

  
113
	}
114

  
115
	/**
116
	 * @return a two dimensional array representing the media items in the gallery, or null if no gallery exists.
117
	 */
118
	public List<List<GalleryImage>> getGalleryImagesOf(TaxonListElement taxonListElement) {
119

  
120

  
121
		WebElement gallery = taxonListElement.getElement().findElement(By.className("media_gallery"));
122

  
123
		if( gallery == null){
124
			return null;
125
		}
126

  
127
		ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>();
128

  
129
		List<WebElement> tableRows = gallery.findElements(By.tagName("tr"));
130
		logger.debug("GalleryImages - total rows " + tableRows.size());
131
		// loop table rows
132
		for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){
133
			logger.debug("GalleryImages - gallery row " + rowId );
134
			List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td"));
135
			logger.debug("GalleryImages - number of image cells: " + imageCells.size());
136
			List<WebElement> captionCells = null;
137
			if(tableRows.size() > rowId * 2 + 1){
138
				captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td"));
139
				logger.debug("GalleryImages - number of caption cells: " + captionCells.size());
140
			}
141

  
142
			galleryImageRows.add(new ArrayList<GalleryImage>());
143

  
144
			// loop table cells in row
145
			for(int cellId = 0; cellId < imageCells.size(); cellId++) {
146
				logger.debug("cellId:" + cellId);
147
				WebElement imageCell = imageCells.get(cellId);
148
				WebElement captionCell = null;
149
				if(captionCells != null && captionCells.size() > cellId){
150
					captionCell = captionCells.get(cellId);
151
					wait.until(new AllTrue(
152
							new ChildElementVisible(imageCell, By.tagName("img")),
153
							new ChildElementVisible(captionCell, By.tagName("dl"))
154
					));
155

  
156
				} else {
157
					wait.until(new ChildElementVisible(imageCell, By.tagName("img")));
158
				}
159
				galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell));
160
			}
161

  
162
		}
163

  
164
		return galleryImageRows;
165
	}
38
    public static final Logger logger = Logger.getLogger(TaxonSearchResultPage.class);
39

  
40
    private static String drupalPagePathBase = "cdm_dataportal/search/taxon";
41

  
42
    @FindBy(id="search_results")
43
    @CacheLookup
44
    private WebElement searchResults;
45

  
46
    //class=page_options
47
    @FindBy(className="page_options")
48
    @CacheLookup
49
    private WebElement pageOptions;
50

  
51
    //class=pager
52
    @FindBy(className="pager")
53
    @CacheLookup
54
    private WebElement pager;
55

  
56

  
57
    /* (non-Javadoc)
58
     * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
59
     */
60
    @Override
61
    protected String getDrupalPageBase() {
62
        return drupalPagePathBase;
63
    }
64

  
65
    /**
66
     * @param driver
67
     * @param context
68
     * @throws Exception
69
     */
70
    public TaxonSearchResultPage(WebDriver driver, DataPortalContext context) throws Exception {
71
        super(driver, context);
72
    }
73

  
74

  
75
    /**
76
     * Find and return the result n-th item of the result list.
77
     * The item can be specified by the index paramter.
78
     * @param index 1-based index to identify the resultset item.
79
     * This index will be used in a xpath query.
80
     * @return
81
     */
82
    public TaxonListElement getResultItem(int index) {
83

  
84
        TaxonListElement entry = new TaxonListElement(searchResults.findElement(By.xpath("ul/li[" + index + "]")));
85

  
86
        return entry;
87
    }
88

  
89
    /**
90
     * Find and returns all items of the result list.
91
     * @return
92
     */
93
    public List<TaxonListElement> getResultItems() {
94

  
95
        List<WebElement> entryList = searchResults.findElements(By.xpath("/ul/li"));
96
        List<TaxonListElement> taxonListElements = new ArrayList<TaxonListElement>();
97
        for(WebElement entry : entryList){
98
            taxonListElements.add(new TaxonListElement(entry));
99
        }
100
        return taxonListElements;
101
    }
102

  
103
    /**
104
     * @throws Exception
105
     *
106
     */
107
    @SuppressWarnings("unchecked")
108
    public <T extends PortalPage> T  clickTaxonName(TaxonListElement taxonListElement, Class<T> pageClass) throws Exception {
109

  
110
        LinkElement taxonlink = new LinkElement(taxonListElement.getElement().findElement(By.tagName("a")));
111
        logger.debug("taxonlink to click: " + taxonlink.toString() + " [" + taxonlink.getElement().toString() + "]");
112
        return (T) clickLink(taxonlink, new VisibilityOfElementLocated(By.id("featureTOC")), pageClass, 2l, TimeUnit.MINUTES);
113

  
114
    }
115

  
116
    /**
117
     * @return a two dimensional array representing the media items in the gallery, or null if no gallery exists.
118
     */
119
    public List<List<GalleryImage>> getGalleryImagesOf(TaxonListElement taxonListElement) {
120

  
121

  
122
        WebElement gallery = taxonListElement.getElement().findElement(By.className("media_gallery"));
123

  
124
        if( gallery == null){
125
            return null;
126
        }
127

  
128
        ArrayList<List<GalleryImage>> galleryImageRows = new ArrayList<List<GalleryImage>>();
129

  
130
        List<WebElement> tableRows = gallery.findElements(By.tagName("tr"));
131
        logger.debug("GalleryImages - total rows " + tableRows.size());
132
        // loop table rows
133
        for(int rowId = 0; rowId * 2 < tableRows.size() && tableRows.size() > 0; rowId++ ){
134
            logger.debug("GalleryImages - gallery row " + rowId );
135
            List<WebElement> imageCells = tableRows.get(rowId * 2).findElements(By.tagName("td"));
136
            logger.debug("GalleryImages - number of image cells: " + imageCells.size());
137
            List<WebElement> captionCells = null;
138
            if(tableRows.size() > rowId * 2 + 1){
139
                captionCells = tableRows.get(rowId * 2 + 1).findElements(By.tagName("td"));
140
                logger.debug("GalleryImages - number of caption cells: " + captionCells.size());
141
            }
142

  
143
            galleryImageRows.add(new ArrayList<GalleryImage>());
144

  
145
            // loop table cells in row
146
            for(int cellId = 0; cellId < imageCells.size(); cellId++) {
147
                logger.debug("cellId:" + cellId);
148
                WebElement imageCell = imageCells.get(cellId);
149
                WebElement captionCell = null;
150
                if(captionCells != null && captionCells.size() > cellId){
151
                    captionCell = captionCells.get(cellId);
152
                    wait.until(new AllTrue(
153
                            new ChildElementVisible(imageCell, By.tagName("img")),
154
                            new ChildElementVisible(captionCell, By.tagName("dl"))
155
                    ));
156

  
157
                } else {
158
                    wait.until(new ChildElementVisible(imageCell, By.tagName("img")));
159
                }
160
                galleryImageRows.get(rowId).add(new GalleryImage(imageCell, captionCell));
161
            }
162

  
163
        }
164

  
165
        return galleryImageRows;
166
    }
166 167

  
167 168

  
168 169

  

Also available in: Unified diff