|
| 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 | +} |
0 commit comments