Skip to content

Commit c5e0b61

Browse files
committed
Add new element: MultiChoiceCombobox
This element can be used to work with Comboboxes that allow several elements to be selected
1 parent dbc9c7a commit c5e0b61

File tree

9 files changed

+134
-3
lines changed

9 files changed

+134
-3
lines changed

src/main/java/aquality/selenium/elements/ComboBox.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ public void clickAndSelectByText(String value) {
4949
@Override
5050
public void selectByContainingText(String text) {
5151
logElementAction("loc.combobox.select.by.text", text);
52-
selectOptionThatContains(WebElement::getText,
52+
applySelectFuncToOptionThatContains(WebElement::getText,
5353
Select::selectByVisibleText,
5454
text);
5555
}
5656

5757
@Override
5858
public void selectByContainingValue(String value) {
5959
logElementAction(LOG_SELECTING_VALUE, value);
60-
selectOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()),
60+
applySelectFuncToOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()),
6161
Select::selectByValue,
6262
value);
6363
}
6464

65-
private void selectOptionThatContains(Function<WebElement, String> getValueFunc, BiConsumer<Select, String> selectFunc, String value){
65+
protected void applySelectFuncToOptionThatContains(Function<WebElement, String> getValueFunc, BiConsumer<Select, String> selectFunc, String value){
6666
doWithRetry(() -> {
6767
Select select = new Select(getElement());
6868
List<WebElement> elements = select.getOptions();

src/main/java/aquality/selenium/elements/ElementFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected Map<Class<? extends aquality.selenium.core.elements.interfaces.IElemen
3939
typesMap.put(IButton.class, Button.class);
4040
typesMap.put(ICheckBox.class, CheckBox.class);
4141
typesMap.put(IComboBox.class, ComboBox.class);
42+
typesMap.put(IMultiChoiceComboBox.class, MultiChoiceComboBox.class);
4243
typesMap.put(ILabel.class, Label.class);
4344
typesMap.put(ILink.class, Link.class);
4445
typesMap.put(IRadioButton.class, RadioButton.class);

src/main/java/aquality/selenium/elements/ElementType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public enum ElementType {
66
BUTTON(IButton.class),
77
CHECKBOX(ICheckBox.class),
88
COMBOBOX(IComboBox.class),
9+
MULTICHOICECOMBOBOX(IMultiChoiceComboBox.class),
910
LABEL(ILabel.class),
1011
LINK(ILink.class),
1112
RADIOBUTTON(IRadioButton.class),
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package aquality.selenium.elements;
2+
3+
import aquality.selenium.core.elements.ElementState;
4+
import aquality.selenium.elements.interfaces.IMultiChoiceComboBox;
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.support.ui.Select;
8+
9+
/**
10+
* Class describing the Multi-choice ComboBox (dropdown list), i.e. the one having attribute {@code multiple} set to {@code true}
11+
*/
12+
public class MultiChoiceComboBox extends ComboBox implements IMultiChoiceComboBox {
13+
14+
private static final String LOG_DESELECTING_VALUE = "loc.deselecting.value";
15+
16+
protected MultiChoiceComboBox(By locator, String name, ElementState state) {
17+
super(locator, name, state);
18+
}
19+
20+
protected String getElementType() {
21+
return getLocalizationManager().getLocalizedMessage("loc.multichoicecombobox");
22+
}
23+
24+
@Override
25+
public void deselectAll() {
26+
logElementAction("loc.multichoicecombobox.deselect.all");
27+
doWithRetry(() -> new Select(getElement()).deselectAll());
28+
}
29+
30+
@Override
31+
public void deselectByIndex(int index) {
32+
logElementAction(LOG_DESELECTING_VALUE, String.format("#%s", index));
33+
doWithRetry(() -> new Select(getElement()).deselectByIndex(index));
34+
}
35+
36+
@Override
37+
public void deselectByValue(String value) {
38+
logElementAction(LOG_DESELECTING_VALUE, value);
39+
doWithRetry(() -> new Select(getElement()).deselectByValue(value));
40+
}
41+
42+
@Override
43+
public void deselectByContainingValue(String value) {
44+
logElementAction(LOG_DESELECTING_VALUE, value);
45+
applySelectFuncToOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()),
46+
Select::deselectByValue,
47+
value);
48+
}
49+
50+
@Override
51+
public void deselectByText(String text) {
52+
logElementAction("loc.multichoicecombobox.deselect.by.text", text);
53+
doWithRetry(() -> new Select(getElement()).deselectByVisibleText(text));
54+
}
55+
56+
@Override
57+
public void deselectByContainingText(String text) {
58+
logElementAction("loc.multichoicecombobox.deselect.by.text", text);
59+
applySelectFuncToOptionThatContains(WebElement::getText,
60+
Select::deselectByVisibleText,
61+
text);
62+
}
63+
}

src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ default IComboBox getComboBox(By locator, String name, ElementState state) {
8080
return get(ElementType.COMBOBOX, locator, name, state);
8181
}
8282

83+
default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name) {
84+
return getMultiChoiceComboBox(locator, name, ElementState.DISPLAYED);
85+
}
86+
87+
default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name, ElementState state) {
88+
return get(ElementType.MULTICHOICECOMBOBOX, locator, name, state);
89+
}
90+
8391
/**
8492
* Creates element that implements ILabel interface.
8593
*
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package aquality.selenium.elements.interfaces;
2+
3+
import java.util.List;
4+
5+
public interface IMultiChoiceComboBox extends IComboBox {
6+
7+
/**
8+
* Deselect all selected options
9+
*/
10+
void deselectAll();
11+
12+
/**
13+
* Deselect selected option by index
14+
*
15+
* @param index number of selected option
16+
*/
17+
void deselectByIndex(int index);
18+
19+
/**
20+
* Deselect selected option by value
21+
*
22+
* @param value argument value
23+
*/
24+
void deselectByValue(String value);
25+
26+
/**
27+
* Deselect selected option by containing value
28+
*
29+
* @param value partial option's value
30+
*/
31+
void deselectByContainingValue(String value);
32+
33+
/**
34+
* Deselect selected option by visible text
35+
*
36+
* @param text text to be deselected
37+
*/
38+
void deselectByText(String text);
39+
40+
/**
41+
* Deselect selected option by containing visible text
42+
*
43+
* @param text visible text
44+
*/
45+
void deselectByContainingText(String text);
46+
}

src/main/resources/localization/be.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"loc.combobox.texts": "Спіс тэкстаў опцыяў: [%s]",
4444
"loc.combobox.values": "Спіс значэнняў: [%s]",
4545
"loc.combobox.impossible.to.select.contain.value.or.text" : "Немагчыма выбраць опцыю, якая змяшчае значэнне/тэкст '%1$s' у камбабоксе '%2$s'",
46+
"loc.multichoicecombobox": "Камбабокс з мульцівыбарам",
47+
"loc.multichoicecombobox.deselect.all": "Адмяняем выбар усіх значэнняў",
48+
"loc.multichoicecombobox.deselect.by.text": "Адмяняем выбар значэння з тэкстам '%s'",
4649
"loc.el.getattr" : "Атрымліваем атрыбут '%1$s'",
4750
"loc.el.attr.value": "Значэнне атрыбута '%1$s': [%2$s]",
4851
"loc.el.cssvalue" : "Атрымліваем значэнне css '%1$s'",
@@ -64,6 +67,7 @@
6467
"loc.scrolling.center.js" : "Пракручваем старонку да цэнтра элемента праз JavaScript",
6568
"loc.scrolling.js" : "Пракручваем старонку праз JavaScript",
6669
"loc.selecting.value" : "Выбіраем значэнне - '%s'",
70+
"loc.deselecting.value": "Адмяняем выбар значэння - '%s'",
6771
"loc.send.text" : "Задаем тэкст - '%s'",
6872
"loc.setting.value" : "Задаем значэнне - '%s'",
6973
"loc.text.clearing" : "Ачышчаем",

src/main/resources/localization/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"loc.combobox.texts": "Option texts: [%s]",
4444
"loc.combobox.values": "Option values: [%s]",
4545
"loc.combobox.impossible.to.select.contain.value.or.text" : "It is impossible to select option that contains value/text '%1$s' from combobox '%2$s'",
46+
"loc.multichoicecombobox": "Multi-choice ComboBox",
47+
"loc.multichoicecombobox.deselect.all": "Deselect all",
48+
"loc.multichoicecombobox.deselect.by.text": "Deselecting value by text '%s'",
4649
"loc.el.getattr" : "Getting attribute '%1$s'",
4750
"loc.el.attr.value": "Value of attribute '%1$s': [%2$s]",
4851
"loc.el.cssvalue" : "Getting css value '%1$s'",
@@ -64,6 +67,7 @@
6467
"loc.scrolling.center.js" : "Scrolling to the center via JavaScript",
6568
"loc.scrolling.js" : "Scrolling via JavaScript",
6669
"loc.selecting.value" : "Selecting value - '%s'",
70+
"loc.deselecting.value": "Deselecting value - '%s'",
6771
"loc.send.text" : "Setting text - '%s'",
6872
"loc.setting.value" : "Setting value - '%s'",
6973
"loc.text.clearing" : "Clearing",

src/main/resources/localization/ru.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"loc.combobox.texts": "Список текстов опций: [%s]",
4444
"loc.combobox.values": "Список значений: [%s]",
4545
"loc.combobox.impossible.to.select.contain.value.or.text" : "Не удаётся выбрать значение которое содержит значение/текст '%1$s' в выпадающем списке '%2$s'",
46+
"loc.multichoicecombobox": "Комбобокс с мультивыбором",
47+
"loc.multichoicecombobox.deselect.all": "Отмена выбора всех значений",
48+
"loc.multichoicecombobox.deselect.by.text": "Отмена выбора значения с текстом '%s'",
4649
"loc.el.getattr" : "Получение аттрибута '%1$s'",
4750
"loc.el.attr.value": "Значение аттрибута '%1$s'': [%2$s]",
4851
"loc.el.cssvalue" : "Получение значения css '%1$s'",
@@ -64,6 +67,7 @@
6467
"loc.scrolling.center.js" : "Скроллинг в центр (посредством JavaScript)",
6568
"loc.scrolling.js" : "Скроллинг посредством JavaScript",
6669
"loc.selecting.value" : "Выбор значения - '%s'",
70+
"loc.deselecting.value": "Отмена выбора значения - '%s'",
6771
"loc.send.text" : "Ввод текста - '%s'",
6872
"loc.setting.value" : "Установка значения - '%s'",
6973
"loc.text.clearing" : "Очистка",

0 commit comments

Comments
 (0)