-
Notifications
You must be signed in to change notification settings - Fork 188
/
Search.java
144 lines (119 loc) · 5.63 KB
/
Search.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright (c) 2010-2018 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.schrodinger.component.common;
import com.codeborne.selenide.*;
import com.evolveum.midpoint.schrodinger.MidPoint;
import com.evolveum.midpoint.schrodinger.component.Component;
import com.evolveum.midpoint.schrodinger.util.Schrodinger;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Coordinates;
import static com.codeborne.selenide.Selectors.byText;
/**
* Created by Viliam Repan (lazyman).
*/
public class Search<T> extends Component<T> {
public Search(T parent, SelenideElement parentElement) {
super(parent, parentElement);
}
public SearchItemField<Search<T>> byName() {
choiceBasicSearch();
SelenideElement nameElement = getItemByName("Name");
SelenideElement nameInput = nameElement.parent().$x(".//input[@" + Schrodinger.DATA_S_ID + "='input']")
.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S);
return new SearchItemField(this, nameInput);
}
public Search<T> updateSearch(){
SelenideElement simpleSearchButton = getParentElement().$(Schrodinger.byDataId("searchSimple"))
.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S);
Actions builder = new Actions(WebDriverRunner.getWebDriver());
builder.moveToElement(simpleSearchButton, 5, 5).click().build().perform();
return this;
}
private void choiceBasicSearch() {
SelenideElement linksContainer = getParentElement().$(Schrodinger.byDataId("div", "linksContainer")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S);
try {
linksContainer.$(Schrodinger.byDataId("a", "basic")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click();
} catch (Throwable t) {
// all is ok, basic search is already selected option, TODO: Schrodinger should provide easy method to check component existence
}
}
public InputBox<Search<T>> byFullText() {
SelenideElement linksContainer = getParentElement().$(Schrodinger.byDataId("div", "linksContainer")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S);
try {
linksContainer.$(Schrodinger.byDataId("a", "fullText")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click();
} catch (Throwable t) {
// all is ok, fullText search is already selected option, TODO: Schrodinger should provide easy method to check component existence
}
// we assume fulltext is enabled in systemconfig, else error is thrown here:
SelenideElement fullTextField = getParentElement().$(Schrodinger.byDataId("input", "fullTextField")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S);
return new InputBox<> (this, fullTextField);
}
public Search<T> addSearchItem(String name) {
choiceBasicSearch();
getParentElement().$x(".//a[@"+Schrodinger.DATA_S_ID+"='more']").waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click();
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
SelenideElement popover = getDisplayedPopover();
popover.$x(".//input[@"+Schrodinger.DATA_S_ID+"='addText']").setValue(name);
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
popover.$x(".//a[@"+Schrodinger.DATA_S_ID+"='propLink']").click();
return this;
}
public Popover<Search<T>> byItem(String name) {
choiceBasicSearch();
SelenideElement item = getItemByName(name);
if (item == null) {
addSearchItem(name);
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
}
item = getItemByName(name);
if (item == null) {
throw new IllegalStateException("Couldn't find search item for name " + name);
}
item.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click();
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
return new Popover<>(this, getDisplayedPopover());
}
private SelenideElement getItemByName(String name) {
ElementsCollection items = getParentElement().findAll(By.className("search-item"));
for (SelenideElement item : items) {
if (item.$(byText(name)) != null) {
return item;
}
}
return null;
}
private SelenideElement getDisplayedPopover() {
ElementsCollection popoverElements = getParentElement().$$(Schrodinger.byDataId("popover"));
SelenideElement popover = null;
for (SelenideElement popoverElement : popoverElements) {
if (popoverElement.isDisplayed()) {
popover = popoverElement;
break;
}
popover = popoverElement;
}
return popover;
}
public Search<T> resetBasicSearch() {
choiceBasicSearch();
SelenideElement nameItem = getItemByName("Name");
if (nameItem != null) {
nameItem.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click();
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
new Popover<>(this, nameItem).inputValue("").updateSearch();
}
ElementsCollection deleteButtons = getParentElement().$$(Schrodinger.byDataId("deleteButton"));
for (SelenideElement deleteButton : deleteButtons) {
if (deleteButton.isDisplayed()) {
deleteButton.click();
}
}
Selenide.sleep(2000);
return this;
}
}