-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from aquality-automation/Feature/Add-Multicho…
…ice-Combobox Feature/add multichoice combobox closes #65
- Loading branch information
Showing
17 changed files
with
461 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/aquality/selenium/elements/MultiChoiceBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package aquality.selenium.elements; | ||
|
||
import aquality.selenium.core.elements.ElementState; | ||
import aquality.selenium.elements.interfaces.IMultiChoiceBox; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.ui.Select; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Class describing the Multi-choice ComboBox (dropdown list), i.e. the one having attribute {@code multiple} set to {@code true} | ||
*/ | ||
public class MultiChoiceBox extends ComboBox implements IMultiChoiceBox { | ||
|
||
private static final String LOG_DESELECTING_VALUE = "loc.deselecting.value"; | ||
|
||
protected MultiChoiceBox(By locator, String name, ElementState state) { | ||
super(locator, name, state); | ||
} | ||
|
||
protected String getElementType() { | ||
return getLocalizationManager().getLocalizedMessage("loc.multichoicebox"); | ||
} | ||
|
||
@Override | ||
public List<String> getSelectedValues() { | ||
logElementAction("loc.combobox.getting.selected.value"); | ||
return collectSelectedOptions(option -> option.getAttribute(Attributes.VALUE.toString()), "value"); | ||
} | ||
|
||
@Override | ||
public List<String> getSelectedTexts() { | ||
logElementAction("loc.combobox.getting.selected.text"); | ||
return collectSelectedOptions(WebElement::getText, "text"); | ||
} | ||
|
||
private List<String> collectSelectedOptions(Function<WebElement, String> valueGetter, String valueType) { | ||
List<String> texts = doWithRetry(() -> | ||
new Select(getElement()).getAllSelectedOptions() | ||
.stream() | ||
.map(valueGetter) | ||
.collect(Collectors.toList())); | ||
String logValue = texts.stream().map(value -> String.format("'%s'", value)).collect(Collectors.joining(", ")); | ||
logElementAction(String.format("loc.combobox.selected.%s", valueType), logValue); | ||
return texts; | ||
} | ||
|
||
@Override | ||
public void selectAll() { | ||
logElementAction("loc.multichoicebox.select.all"); | ||
applyFunctionToOptionsThatContain(element -> element.getAttribute(Attributes.VALUE.toString()), | ||
Select::selectByValue, | ||
StringUtils.EMPTY); | ||
} | ||
|
||
@Override | ||
public void deselectAll() { | ||
logElementAction("loc.multichoicebox.deselect.all"); | ||
doWithRetry(() -> new Select(getElement()).deselectAll()); | ||
} | ||
|
||
@Override | ||
public void deselectByIndex(int index) { | ||
logElementAction(LOG_DESELECTING_VALUE, String.format("#%s", index)); | ||
doWithRetry(() -> new Select(getElement()).deselectByIndex(index)); | ||
} | ||
|
||
@Override | ||
public void deselectByValue(String value) { | ||
logElementAction(LOG_DESELECTING_VALUE, value); | ||
doWithRetry(() -> new Select(getElement()).deselectByValue(value)); | ||
} | ||
|
||
@Override | ||
public void deselectByContainingValue(String value) { | ||
logElementAction(LOG_DESELECTING_VALUE, value); | ||
applyFunctionToOptionsThatContain(element -> element.getAttribute(Attributes.VALUE.toString()), | ||
Select::deselectByValue, | ||
value); | ||
} | ||
|
||
@Override | ||
public void deselectByText(String text) { | ||
logElementAction("loc.multichoicebox.deselect.by.text", text); | ||
doWithRetry(() -> new Select(getElement()).deselectByVisibleText(text)); | ||
} | ||
|
||
@Override | ||
public void deselectByContainingText(String text) { | ||
logElementAction("loc.multichoicebox.deselect.by.text", text); | ||
applyFunctionToOptionsThatContain(WebElement::getText, | ||
Select::deselectByVisibleText, | ||
text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package aquality.selenium.elements.interfaces; | ||
|
||
import java.util.List; | ||
|
||
public interface IMultiChoiceBox extends IComboBox { | ||
|
||
/** | ||
* Gets value of all selected options | ||
* | ||
* @return selected values | ||
*/ | ||
List<String> getSelectedValues(); | ||
|
||
/** | ||
* Gets text of all selected options | ||
* | ||
* @return selected text | ||
*/ | ||
List<String> getSelectedTexts(); | ||
|
||
/** | ||
* Select all options | ||
*/ | ||
void selectAll(); | ||
|
||
/** | ||
* Deselect all selected options | ||
*/ | ||
void deselectAll(); | ||
|
||
/** | ||
* Deselect selected option by index | ||
* | ||
* @param index number of selected option | ||
*/ | ||
void deselectByIndex(int index); | ||
|
||
/** | ||
* Deselect selected option by value | ||
* | ||
* @param value argument value | ||
*/ | ||
void deselectByValue(String value); | ||
|
||
/** | ||
* Deselect selected option by containing value | ||
* | ||
* @param value partial option's value | ||
*/ | ||
void deselectByContainingValue(String value); | ||
|
||
/** | ||
* Deselect selected option by visible text | ||
* | ||
* @param text text to be deselected | ||
*/ | ||
void deselectByText(String text); | ||
|
||
/** | ||
* Deselect selected option by containing visible text | ||
* | ||
* @param text visible text | ||
*/ | ||
void deselectByContainingText(String text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../java/tests/integration/ElementTests.java → ...ts/integration/elements/ElementTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ests/integration/HiddenElementsTests.java → ...gration/elements/HiddenElementsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.