Revision fdd6dc54
Added by Andreas Kohlbecker about 3 years ago
src/main/java/eu/etaxonomy/dataportal/elements/BaseElement.java | ||
---|---|---|
32 | 32 |
public class BaseElement { |
33 | 33 |
|
34 | 34 |
public static final Logger logger = Logger.getLogger(BaseElement.class); |
35 |
|
|
35 | 36 |
/** |
36 | 37 |
* Default tolerance for testing sizes and positions |
37 | 38 |
*/ |
... | ... | |
52 | 53 |
return element; |
53 | 54 |
} |
54 | 55 |
|
56 |
/** |
|
57 |
* Null save factory method |
|
58 |
* |
|
59 |
* @param we |
|
60 |
* May be <code>null</code> |
|
61 |
* @return |
|
62 |
* The new BaseElement or <code>null</code>. |
|
63 |
*/ |
|
64 |
public static BaseElement from(WebElement we) { |
|
65 |
if(we != null) { |
|
66 |
return new BaseElement(we); |
|
67 |
} |
|
68 |
return null; |
|
69 |
} |
|
70 |
|
|
55 | 71 |
public String getText() { |
56 | 72 |
if(text == null) { |
57 | 73 |
text = element.getText(); |
src/main/java/eu/etaxonomy/dataportal/elements/DerivedUnitTree.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2021 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.elements; |
|
10 |
|
|
11 |
import org.openqa.selenium.By; |
|
12 |
import org.openqa.selenium.WebElement; |
|
13 |
|
|
14 |
/** |
|
15 |
* @author a.kohlbecker |
|
16 |
* @since Mar 18, 2021 |
|
17 |
*/ |
|
18 |
public class DerivedUnitTree extends BaseElement { |
|
19 |
|
|
20 |
|
|
21 |
private DerivedUnitTreeNode rootNode = null; |
|
22 |
|
|
23 |
|
|
24 |
public DerivedUnitTree(WebElement element) { |
|
25 |
super(element); |
|
26 |
rootNode = new DerivedUnitTreeNode(element.findElement(By.cssSelector(".derived-unit-tree-root"))); |
|
27 |
} |
|
28 |
|
|
29 |
public static DerivedUnitTree from(WebElement element) { |
|
30 |
return new DerivedUnitTree(element); |
|
31 |
} |
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
public DerivedUnitTreeNode getRootNode() { |
|
36 |
return rootNode; |
|
37 |
} |
|
38 |
|
|
39 |
} |
src/main/java/eu/etaxonomy/dataportal/elements/DerivedUnitTreeNode.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2021 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.elements; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
import java.util.stream.Collectors; |
|
14 |
|
|
15 |
import org.openqa.selenium.By; |
|
16 |
import org.openqa.selenium.WebElement; |
|
17 |
|
|
18 |
import eu.etaxonomy.dataportal.selenium.XPathTools; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author a.kohlbecker |
|
22 |
* @since Mar 18, 2021 |
|
23 |
*/ |
|
24 |
public class DerivedUnitTreeNode extends BaseElement { |
|
25 |
|
|
26 |
private List<DerivedUnitTreeNode> subNodes = new ArrayList<>(); |
|
27 |
|
|
28 |
public DerivedUnitTreeNode(WebElement element) { |
|
29 |
super(element); |
|
30 |
// > .item-list > ul.derived-unit-sub-tree > li.derived-unit-item |
|
31 |
String xpathStr = |
|
32 |
"./div" + XPathTools.classAttrContains("item-list") |
|
33 |
+ "/ul" + XPathTools.classAttrContains("derived-unit-sub-tree") |
|
34 |
+ "/li" + XPathTools.classAttrContains("derived-unit-item"); |
|
35 |
subNodes = element.findElements(By.xpath(xpathStr)) |
|
36 |
.stream() |
|
37 |
.map(e -> new DerivedUnitTreeNode(e)) |
|
38 |
.collect(Collectors.toList()); |
|
39 |
} |
|
40 |
|
|
41 |
public BaseElement getHeader() { |
|
42 |
return BaseElement.from(getElement().findElement(By.cssSelector(".unit-header"))); |
|
43 |
} |
|
44 |
|
|
45 |
public BaseElement getContent() { |
|
46 |
return BaseElement.from(getElement().findElement(By.cssSelector(".unit-content"))); |
|
47 |
} |
|
48 |
|
|
49 |
public DetailsTable getDetailsTable(String tableClassAttribute) { |
|
50 |
return DetailsTable.from(getContent().getElement().findElement(By.cssSelector("table." + tableClassAttribute))); |
|
51 |
} |
|
52 |
|
|
53 |
public String getDerivationEvent() { |
|
54 |
return getContent().getElement().findElement(By.cssSelector("div.derivation-event")).getText(); |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
public List<DerivedUnitTreeNode> getSubNodes() { |
|
59 |
return subNodes; |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
} |
src/main/java/eu/etaxonomy/dataportal/elements/DetailsTable.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2021 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.elements; |
|
10 |
|
|
11 |
import org.openqa.selenium.WebElement; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author a.kohlbecker |
|
15 |
* @since Mar 18, 2021 |
|
16 |
*/ |
|
17 |
public class DetailsTable extends Table { |
|
18 |
|
|
19 |
boolean withLabelColumn = true; |
|
20 |
|
|
21 |
|
|
22 |
public DetailsTable(WebElement element) { |
|
23 |
super(element); |
|
24 |
} |
|
25 |
|
|
26 |
public static DetailsTable from(WebElement element) { |
|
27 |
if(element != null) { |
|
28 |
return new DetailsTable(element); |
|
29 |
} |
|
30 |
return null; |
|
31 |
} |
|
32 |
|
|
33 |
public String getHeaderText() { |
|
34 |
return getHeaderCellText(0, 0); |
|
35 |
} |
|
36 |
|
|
37 |
public BaseElement getDetailsValueCell(String labelText) { |
|
38 |
return getBodyCell(labelText, 0, 1); |
|
39 |
} |
|
40 |
|
|
41 |
public String getDetailsValueCellText(String labelText) { |
|
42 |
return getBodyCellText(labelText, 0, 1); |
|
43 |
} |
|
44 |
|
|
45 |
public static String tableClassAttrFrom(String headerLabel) { |
|
46 |
return headerLabel = "details-table-" + headerLabel |
|
47 |
.toLowerCase() |
|
48 |
.replaceAll("\\s", "_") |
|
49 |
.replaceAll("[^a-z0-9\\-_]", ""); |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
} |
src/main/java/eu/etaxonomy/dataportal/elements/Table.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2021 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.elements; |
|
10 |
|
|
11 |
import org.openqa.selenium.By; |
|
12 |
import org.openqa.selenium.WebElement; |
|
13 |
|
|
14 |
/** |
|
15 |
* @author a.kohlbecker |
|
16 |
* @since Mar 18, 2021 |
|
17 |
*/ |
|
18 |
public class Table extends BaseElement { |
|
19 |
|
|
20 |
|
|
21 |
public Table(WebElement element) { |
|
22 |
super(element); |
|
23 |
} |
|
24 |
|
|
25 |
public static Table from(WebElement element) { |
|
26 |
if(element != null) { |
|
27 |
return new Table(element); |
|
28 |
} |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
public BaseElement getHeaderCell(int cellId, int rowId) { |
|
33 |
return BaseElement.from(getElement().findElement(By.xpath("./thead[1]/tr[" + (rowId + 1) + "]/th[" + (cellId + 1)+ "]"))); |
|
34 |
} |
|
35 |
|
|
36 |
public String getHeaderCellText(int cellId, int rowId) { |
|
37 |
BaseElement cell = getHeaderCell(cellId, rowId); |
|
38 |
if(cell!= null) { |
|
39 |
return cell.getText(); |
|
40 |
} |
|
41 |
return null; |
|
42 |
} |
|
43 |
|
|
44 |
public BaseElement getBodyCell(int cellId, int rowId) { |
|
45 |
return BaseElement.from(getElement().findElement(By.xpath("./tbody[1]/tr[" + (rowId + 1) + "]/td[" + (cellId + 1) + "]"))); |
|
46 |
} |
|
47 |
|
|
48 |
public String getBodyCellText(int cellId, int rowId) { |
|
49 |
BaseElement cell = getBodyCell(cellId, rowId); |
|
50 |
if(cell!= null) { |
|
51 |
return cell.getText(); |
|
52 |
} |
|
53 |
return null; |
|
54 |
} |
|
55 |
|
|
56 |
public BaseElement getBodyCell(String cellText, int searchRowId, int returnRowId) { |
|
57 |
String xpathStr = "./tbody/tr/td[" + (searchRowId + 1) + "][text()='" + cellText + "']/following-sibling::td[" + (returnRowId - searchRowId) + "]"; |
|
58 |
return BaseElement.from(getElement().findElement(By.xpath(xpathStr))); |
|
59 |
} |
|
60 |
|
|
61 |
public String getBodyCellText(String cellText, int rowId, int returnRowId) { |
|
62 |
BaseElement cell = getBodyCell(cellText, rowId, returnRowId); |
|
63 |
if(cell!= null) { |
|
64 |
return cell.getText(); |
|
65 |
} |
|
66 |
return null; |
|
67 |
} |
|
68 |
|
|
69 |
} |
src/main/java/eu/etaxonomy/dataportal/selenium/XPathTools.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2021 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.selenium; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 19, 2021 |
|
14 |
*/ |
|
15 |
public class XPathTools { |
|
16 |
|
|
17 |
public static String classAttrContains(String className) { |
|
18 |
return "[contains(concat(' ',normalize-space(@class),' '),' " + className + " ')]"; |
|
19 |
} |
|
20 |
|
|
21 |
} |
Also available in: Unified diff
ref #7599 ref #6866 specimen details tables - selenium elements