1
|
/**
|
2
|
* Copyright (C) 2011 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.dataportal.pages;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
import java.util.concurrent.TimeUnit;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.openqa.selenium.By;
|
18
|
import org.openqa.selenium.WebDriver;
|
19
|
import org.openqa.selenium.WebElement;
|
20
|
import org.openqa.selenium.support.CacheLookup;
|
21
|
import org.openqa.selenium.support.FindBy;
|
22
|
|
23
|
import eu.etaxonomy.dataportal.DataPortalContext;
|
24
|
import eu.etaxonomy.dataportal.elements.LinkElement;
|
25
|
import eu.etaxonomy.dataportal.elements.TaxonListElement;
|
26
|
import eu.etaxonomy.dataportal.selenium.VisibilityOfElementLocated;
|
27
|
|
28
|
/**
|
29
|
* @author andreas
|
30
|
* @since Aug 12, 2011
|
31
|
*
|
32
|
*/
|
33
|
public class TaxonSearchResultPage extends GenericPortalPage {
|
34
|
|
35
|
public static final Logger logger = Logger.getLogger(TaxonSearchResultPage.class);
|
36
|
|
37
|
private static String drupalPagePathBase = "cdm_dataportal/search/taxon";
|
38
|
|
39
|
@FindBy(id="search_results")
|
40
|
@CacheLookup
|
41
|
private WebElement searchResults;
|
42
|
|
43
|
//class=page_options
|
44
|
@FindBy(className="page_options")
|
45
|
@CacheLookup
|
46
|
private WebElement pageOptions;
|
47
|
|
48
|
//class=pager
|
49
|
@FindBy(className="pager")
|
50
|
@CacheLookup
|
51
|
private WebElement pager;
|
52
|
|
53
|
|
54
|
/* (non-Javadoc)
|
55
|
* @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
|
56
|
*/
|
57
|
@Override
|
58
|
protected String getDrupalPageBase() {
|
59
|
return drupalPagePathBase;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* @param driver
|
64
|
* @param context
|
65
|
*/
|
66
|
public TaxonSearchResultPage(WebDriver driver, DataPortalContext context) throws Exception {
|
67
|
super(driver, context);
|
68
|
}
|
69
|
|
70
|
|
71
|
/**
|
72
|
* Find and return the result n-th item of the result list.
|
73
|
* The item can be specified by the index paramter.
|
74
|
* @param index 1-based index to identify the resultset item.
|
75
|
* This index will be used in a xpath query.
|
76
|
|
77
|
*/
|
78
|
public TaxonListElement getResultItem(int index) {
|
79
|
|
80
|
TaxonListElement entry = new TaxonListElement(searchResults.findElement(By.xpath("div/div[" + index + "]")));
|
81
|
|
82
|
return entry;
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Find and returns all items of the result list.
|
87
|
*/
|
88
|
public List<TaxonListElement> getResultItems() {
|
89
|
|
90
|
List<WebElement> entryList = searchResults.findElements(By.xpath("/ul/li"));
|
91
|
List<TaxonListElement> taxonListElements = new ArrayList<TaxonListElement>();
|
92
|
for(WebElement entry : entryList){
|
93
|
taxonListElements.add(new TaxonListElement(entry));
|
94
|
}
|
95
|
return taxonListElements;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* @throws Exception
|
100
|
*
|
101
|
*/
|
102
|
@SuppressWarnings("unchecked")
|
103
|
public <T extends PortalPage> T clickTaxonName(TaxonListElement taxonListElement, Class<T> pageClass, UUID taxonUuid) throws Exception {
|
104
|
|
105
|
LinkElement taxonlink = new LinkElement(taxonListElement.getElement().findElement(By.tagName("a")));
|
106
|
logger.debug("taxonlink to click: " + taxonlink.toString() + " [" + taxonlink.getElement().toString() + "]");
|
107
|
logger.debug(" waiting for visibility of css selector: .page-cdm-dataportal-taxon-" + taxonUuid.toString() + " ...");
|
108
|
return clickLink(taxonlink, new VisibilityOfElementLocated(By.cssSelector(".page-cdm-dataportal-taxon-" + taxonUuid.toString())),
|
109
|
pageClass, 2l, TimeUnit.MINUTES);
|
110
|
|
111
|
}
|
112
|
|
113
|
|
114
|
|
115
|
}
|