From c5e0b61ec01f0d61d03894154e101695e06fa181 Mon Sep 17 00:00:00 2001 From: Eugene Nekh Date: Wed, 18 Nov 2020 01:38:29 +0300 Subject: [PATCH 1/9] Add new element: MultiChoiceCombobox This element can be used to work with Comboboxes that allow several elements to be selected --- .../aquality/selenium/elements/ComboBox.java | 6 +- .../selenium/elements/ElementFactory.java | 1 + .../selenium/elements/ElementType.java | 1 + .../elements/MultiChoiceComboBox.java | 63 +++++++++++++++++++ .../elements/interfaces/IElementFactory.java | 8 +++ .../interfaces/IMultiChoiceComboBox.java | 46 ++++++++++++++ src/main/resources/localization/be.json | 4 ++ src/main/resources/localization/en.json | 4 ++ src/main/resources/localization/ru.json | 4 ++ 9 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/main/java/aquality/selenium/elements/MultiChoiceComboBox.java create mode 100644 src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java diff --git a/src/main/java/aquality/selenium/elements/ComboBox.java b/src/main/java/aquality/selenium/elements/ComboBox.java index 39459ec..328a5ce 100644 --- a/src/main/java/aquality/selenium/elements/ComboBox.java +++ b/src/main/java/aquality/selenium/elements/ComboBox.java @@ -49,7 +49,7 @@ public void clickAndSelectByText(String value) { @Override public void selectByContainingText(String text) { logElementAction("loc.combobox.select.by.text", text); - selectOptionThatContains(WebElement::getText, + applySelectFuncToOptionThatContains(WebElement::getText, Select::selectByVisibleText, text); } @@ -57,12 +57,12 @@ public void selectByContainingText(String text) { @Override public void selectByContainingValue(String value) { logElementAction(LOG_SELECTING_VALUE, value); - selectOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()), + applySelectFuncToOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()), Select::selectByValue, value); } - private void selectOptionThatContains(Function getValueFunc, BiConsumer selectFunc, String value){ + protected void applySelectFuncToOptionThatContains(Function getValueFunc, BiConsumer selectFunc, String value){ doWithRetry(() -> { Select select = new Select(getElement()); List elements = select.getOptions(); diff --git a/src/main/java/aquality/selenium/elements/ElementFactory.java b/src/main/java/aquality/selenium/elements/ElementFactory.java index e22cf52..e17098c 100644 --- a/src/main/java/aquality/selenium/elements/ElementFactory.java +++ b/src/main/java/aquality/selenium/elements/ElementFactory.java @@ -39,6 +39,7 @@ protected Map 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); + applySelectFuncToOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()), + Select::deselectByValue, + value); + } + + @Override + public void deselectByText(String text) { + logElementAction("loc.multichoicecombobox.deselect.by.text", text); + doWithRetry(() -> new Select(getElement()).deselectByVisibleText(text)); + } + + @Override + public void deselectByContainingText(String text) { + logElementAction("loc.multichoicecombobox.deselect.by.text", text); + applySelectFuncToOptionThatContains(WebElement::getText, + Select::deselectByVisibleText, + text); + } +} diff --git a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java index 13cd99a..15e3ee6 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java @@ -80,6 +80,14 @@ default IComboBox getComboBox(By locator, String name, ElementState state) { return get(ElementType.COMBOBOX, locator, name, state); } + default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name) { + return getMultiChoiceComboBox(locator, name, ElementState.DISPLAYED); + } + + default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name, ElementState state) { + return get(ElementType.MULTICHOICECOMBOBOX, locator, name, state); + } + /** * Creates element that implements ILabel interface. * diff --git a/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java b/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java new file mode 100644 index 0000000..4631f25 --- /dev/null +++ b/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java @@ -0,0 +1,46 @@ +package aquality.selenium.elements.interfaces; + +import java.util.List; + +public interface IMultiChoiceComboBox extends IComboBox { + + /** + * 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); +} diff --git a/src/main/resources/localization/be.json b/src/main/resources/localization/be.json index e9a20dd..1f20793 100644 --- a/src/main/resources/localization/be.json +++ b/src/main/resources/localization/be.json @@ -43,6 +43,9 @@ "loc.combobox.texts": "Спіс тэкстаў опцыяў: [%s]", "loc.combobox.values": "Спіс значэнняў: [%s]", "loc.combobox.impossible.to.select.contain.value.or.text" : "Немагчыма выбраць опцыю, якая змяшчае значэнне/тэкст '%1$s' у камбабоксе '%2$s'", + "loc.multichoicecombobox": "Камбабокс з мульцівыбарам", + "loc.multichoicecombobox.deselect.all": "Адмяняем выбар усіх значэнняў", + "loc.multichoicecombobox.deselect.by.text": "Адмяняем выбар значэння з тэкстам '%s'", "loc.el.getattr" : "Атрымліваем атрыбут '%1$s'", "loc.el.attr.value": "Значэнне атрыбута '%1$s': [%2$s]", "loc.el.cssvalue" : "Атрымліваем значэнне css '%1$s'", @@ -64,6 +67,7 @@ "loc.scrolling.center.js" : "Пракручваем старонку да цэнтра элемента праз JavaScript", "loc.scrolling.js" : "Пракручваем старонку праз JavaScript", "loc.selecting.value" : "Выбіраем значэнне - '%s'", + "loc.deselecting.value": "Адмяняем выбар значэння - '%s'", "loc.send.text" : "Задаем тэкст - '%s'", "loc.setting.value" : "Задаем значэнне - '%s'", "loc.text.clearing" : "Ачышчаем", diff --git a/src/main/resources/localization/en.json b/src/main/resources/localization/en.json index 36c9e8c..c290790 100644 --- a/src/main/resources/localization/en.json +++ b/src/main/resources/localization/en.json @@ -43,6 +43,9 @@ "loc.combobox.texts": "Option texts: [%s]", "loc.combobox.values": "Option values: [%s]", "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'", + "loc.multichoicecombobox": "Multi-choice ComboBox", + "loc.multichoicecombobox.deselect.all": "Deselect all", + "loc.multichoicecombobox.deselect.by.text": "Deselecting value by text '%s'", "loc.el.getattr" : "Getting attribute '%1$s'", "loc.el.attr.value": "Value of attribute '%1$s': [%2$s]", "loc.el.cssvalue" : "Getting css value '%1$s'", @@ -64,6 +67,7 @@ "loc.scrolling.center.js" : "Scrolling to the center via JavaScript", "loc.scrolling.js" : "Scrolling via JavaScript", "loc.selecting.value" : "Selecting value - '%s'", + "loc.deselecting.value": "Deselecting value - '%s'", "loc.send.text" : "Setting text - '%s'", "loc.setting.value" : "Setting value - '%s'", "loc.text.clearing" : "Clearing", diff --git a/src/main/resources/localization/ru.json b/src/main/resources/localization/ru.json index 1c1bfa7..31ab5ac 100644 --- a/src/main/resources/localization/ru.json +++ b/src/main/resources/localization/ru.json @@ -43,6 +43,9 @@ "loc.combobox.texts": "Список текстов опций: [%s]", "loc.combobox.values": "Список значений: [%s]", "loc.combobox.impossible.to.select.contain.value.or.text" : "Не удаётся выбрать значение которое содержит значение/текст '%1$s' в выпадающем списке '%2$s'", + "loc.multichoicecombobox": "Комбобокс с мультивыбором", + "loc.multichoicecombobox.deselect.all": "Отмена выбора всех значений", + "loc.multichoicecombobox.deselect.by.text": "Отмена выбора значения с текстом '%s'", "loc.el.getattr" : "Получение аттрибута '%1$s'", "loc.el.attr.value": "Значение аттрибута '%1$s'': [%2$s]", "loc.el.cssvalue" : "Получение значения css '%1$s'", @@ -64,6 +67,7 @@ "loc.scrolling.center.js" : "Скроллинг в центр (посредством JavaScript)", "loc.scrolling.js" : "Скроллинг посредством JavaScript", "loc.selecting.value" : "Выбор значения - '%s'", + "loc.deselecting.value": "Отмена выбора значения - '%s'", "loc.send.text" : "Ввод текста - '%s'", "loc.setting.value" : "Установка значения - '%s'", "loc.text.clearing" : "Очистка", From dcd760f8ac6ac4cc3ab618d7dd865e746f6bb5a4 Mon Sep 17 00:00:00 2001 From: Eugene Nekh Date: Wed, 18 Nov 2020 01:46:05 +0300 Subject: [PATCH 2/9] Add tests for MultiChoiceCombobox --- .../{ => elements}/ElementTests.java | 2 +- .../{ => elements}/HiddenElementsTests.java | 2 +- .../elements/MultiChoiceComboBoxTests.java | 97 +++++++++++++++++++ src/test/java/w3schools/W3SchoolsPage.java | 17 ++++ .../w3schools/forms/SelectMultipleForm.java | 93 ++++++++++++++++++ src/test/resources/TestSuite.xml | 4 +- 6 files changed, 211 insertions(+), 4 deletions(-) rename src/test/java/tests/integration/{ => elements}/ElementTests.java (99%) rename src/test/java/tests/integration/{ => elements}/HiddenElementsTests.java (98%) create mode 100644 src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java create mode 100644 src/test/java/w3schools/W3SchoolsPage.java create mode 100644 src/test/java/w3schools/forms/SelectMultipleForm.java diff --git a/src/test/java/tests/integration/ElementTests.java b/src/test/java/tests/integration/elements/ElementTests.java similarity index 99% rename from src/test/java/tests/integration/ElementTests.java rename to src/test/java/tests/integration/elements/ElementTests.java index f9afade..c7bce44 100644 --- a/src/test/java/tests/integration/ElementTests.java +++ b/src/test/java/tests/integration/elements/ElementTests.java @@ -1,4 +1,4 @@ -package tests.integration; +package tests.integration.elements; import aquality.selenium.browser.AqualityServices; import aquality.selenium.core.elements.ElementState; diff --git a/src/test/java/tests/integration/HiddenElementsTests.java b/src/test/java/tests/integration/elements/HiddenElementsTests.java similarity index 98% rename from src/test/java/tests/integration/HiddenElementsTests.java rename to src/test/java/tests/integration/elements/HiddenElementsTests.java index 7ef47c6..c0d445c 100644 --- a/src/test/java/tests/integration/HiddenElementsTests.java +++ b/src/test/java/tests/integration/elements/HiddenElementsTests.java @@ -1,4 +1,4 @@ -package tests.integration; +package tests.integration.elements; import aquality.selenium.browser.AqualityServices; import aquality.selenium.core.elements.ElementState; diff --git a/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java b/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java new file mode 100644 index 0000000..3c220d4 --- /dev/null +++ b/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java @@ -0,0 +1,97 @@ +package tests.integration.elements; + +import aquality.selenium.browser.AqualityServices; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import tests.BaseTest; +import w3schools.W3SchoolsPage; +import w3schools.forms.SelectMultipleForm; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class MultiChoiceComboBoxTests extends BaseTest { + + private final SelectMultipleForm selectMultipleForm = new SelectMultipleForm(); + + @BeforeMethod + @Override + public void beforeMethod() { + getBrowser().goTo(W3SchoolsPage.SELECT_MULTIPLE.getAddress()); + getBrowser().setWindowSize(defaultSize.width, defaultSize.height); + } + + @Test + public void testDeselectByValue() { + List valuesToRemove = Stream.of("volvo", "saab").collect(Collectors.toList()); + + selectMultipleForm.switchToResultFrame(); + selectMultipleForm.selectAll(); + List remaining = selectMultipleForm.deselectByValue(valuesToRemove); + selectMultipleForm.submit(); + + Assert.assertEquals(selectMultipleForm.getValuesFromResult(), remaining); + } + + @Test + public void testDeselectByContainingValue() { + List valuesToRemove = Stream.of("saa", "ope").collect(Collectors.toList()); + + selectMultipleForm.switchToResultFrame(); + selectMultipleForm.selectAll(); + List remaining = selectMultipleForm.deselectByContainingValue(valuesToRemove); + selectMultipleForm.submit(); + + Assert.assertEquals(selectMultipleForm.getValuesFromResult(), remaining); + } + + @Test + public void testDeselectByText() { + List valuesToRemove = Stream.of("Opel").collect(Collectors.toList()); + + selectMultipleForm.switchToResultFrame(); + selectMultipleForm.selectAll(); + List remaining = selectMultipleForm.deselectByText(valuesToRemove); + selectMultipleForm.submit(); + + Assert.assertEquals(selectMultipleForm.getValuesFromResult(), remaining); + } + + @Test + public void testDeselectByContainingText() { + List valuesToRemove = Stream.of("Au", "Vol").collect(Collectors.toList()); + + selectMultipleForm.switchToResultFrame(); + selectMultipleForm.selectAll(); + List remaining = selectMultipleForm.deselectByContainingText(valuesToRemove); + selectMultipleForm.submit(); + + Assert.assertEquals(selectMultipleForm.getValuesFromResult(), remaining); + } + + @Test + public void testDeselectByIndex() { + List valuesToRemove = Stream.of(2, 3).collect(Collectors.toList()); + + selectMultipleForm.switchToResultFrame(); + selectMultipleForm.selectAll(); + List remaining = selectMultipleForm.deselectByIndex(valuesToRemove); + selectMultipleForm.submit(); + + Assert.assertEquals(selectMultipleForm.getValuesFromResult(), remaining); + } + + @Test + public void testDeselectAll() { + selectMultipleForm.switchToResultFrame(); + selectMultipleForm.selectAll(); + selectMultipleForm.deselectAll(); + selectMultipleForm.submit(); + + Assert.assertTrue(selectMultipleForm.getValuesFromResult().isEmpty()); + } +} diff --git a/src/test/java/w3schools/W3SchoolsPage.java b/src/test/java/w3schools/W3SchoolsPage.java new file mode 100644 index 0000000..12dc989 --- /dev/null +++ b/src/test/java/w3schools/W3SchoolsPage.java @@ -0,0 +1,17 @@ +package w3schools; + +public enum W3SchoolsPage { + SELECT_MULTIPLE("tryhtml_select_multiple"); + + private static final String BASE_URL = "https://www.w3schools.com/tags/tryit.asp"; + + private final String postfix; + + W3SchoolsPage(String postfix) { + this.postfix = postfix; + } + + public String getAddress() { + return BASE_URL.concat(String.format("?filename=%s", postfix)); + } +} diff --git a/src/test/java/w3schools/forms/SelectMultipleForm.java b/src/test/java/w3schools/forms/SelectMultipleForm.java new file mode 100644 index 0000000..90fad31 --- /dev/null +++ b/src/test/java/w3schools/forms/SelectMultipleForm.java @@ -0,0 +1,93 @@ +package w3schools.forms; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import aquality.selenium.elements.interfaces.IMultiChoiceComboBox; +import aquality.selenium.elements.interfaces.ITextBox; +import aquality.selenium.forms.Form; +import org.openqa.selenium.By; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.IntSupplier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class SelectMultipleForm extends Form { + + private final IMultiChoiceComboBox cbxCars = getElementFactory().getMultiChoiceComboBox(By.id("cars"), "Cars"); + private final IButton btnSubmit = getElementFactory().getButton(By.cssSelector("input[type='submit']"), "Submit"); + private final ITextBox txbResult = getElementFactory().getTextBox(By.cssSelector(".w3-large"), "Result"); + + public SelectMultipleForm() { + super(By.id("iframe"), "Select Multiple"); + } + + public void switchToResultFrame() { + AqualityServices.getBrowser().getDriver().switchTo().frame("iframeResult"); + } + + public void submit() { + btnSubmit.clickAndWait(); + } + + public List getValuesFromResult() { + String result = txbResult.getText().trim(); + + List results = new ArrayList<>(); + Pattern pattern = Pattern.compile(".*?=(.*?)(&|$)"); + Matcher matcher = pattern.matcher(result); + while (matcher.find()) { + results.add(matcher.group(1)); + } + return results; + } + + public void selectAll() { + cbxCars.getValues().forEach(cbxCars::selectByValue); + } + + public List deselectByValue(List valuesToDeselect) { + return deselectBy(cbxCars::deselectByValue, valuesToDeselect); + } + + public List deselectByContainingValue(List valuesToDeselect) { + return deselectBy(cbxCars::deselectByContainingValue, valuesToDeselect); + } + + public List deselectByText(List textToDeselect) { + return deselectBy(cbxCars::deselectByText, textToDeselect); + } + + public List deselectByContainingText(List textToDeselect) { + return deselectBy(cbxCars::deselectByContainingText, textToDeselect); + } + + public List deselectByIndex(List indeciesToDeselect) { + List values = cbxCars.getValues(); + indeciesToDeselect.forEach(cbxCars::deselectByIndex); + return IntStream.range(0, values.size()) + .filter(i -> !indeciesToDeselect.contains(i)) + .mapToObj(values::get) + .collect(Collectors.toList()); + } + + public void deselectAll() { + cbxCars.deselectAll(); + } + + private List deselectBy(Consumer deselectFunc, List valuesToDeselect) { + valuesToDeselect.forEach(deselectFunc); + return collectRemaining(valuesToDeselect); + } + + private List collectRemaining(List valuesToDeselect) { + return cbxCars.getValues().stream() + .filter(v -> valuesToDeselect.stream() + .noneMatch(deselected -> v.contains(deselected.toLowerCase()))) + .collect(Collectors.toList()); + } +} diff --git a/src/test/resources/TestSuite.xml b/src/test/resources/TestSuite.xml index 5a5be1f..cd172d0 100644 --- a/src/test/resources/TestSuite.xml +++ b/src/test/resources/TestSuite.xml @@ -7,9 +7,9 @@ - + - + From bbf10ecea8c3017191739eb2c6859b674c94974e Mon Sep 17 00:00:00 2001 From: Eugene Nekh Date: Wed, 18 Nov 2020 11:58:06 +0300 Subject: [PATCH 3/9] Add javadoc to default IMultiChoiceComboBox creation methods --- .../elements/interfaces/IElementFactory.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java index 15e3ee6..78378e7 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java @@ -80,10 +80,25 @@ default IComboBox getComboBox(By locator, String name, ElementState state) { return get(ElementType.COMBOBOX, locator, name, state); } + /** + * Creates element that implements IMultiChoiceComboBox interface. + * + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements IMultiChoiceComboBox interface + */ default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name) { return getMultiChoiceComboBox(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements IMultiChoiceComboBox interface. + * + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements IMultiChoiceComboBox interface + */ default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name, ElementState state) { return get(ElementType.MULTICHOICECOMBOBOX, locator, name, state); } From 96d1c9741bd1a5f323a41ab13343e7d72041bff0 Mon Sep 17 00:00:00 2001 From: Eugene Nekh Date: Wed, 18 Nov 2020 12:00:00 +0300 Subject: [PATCH 4/9] Remove unused imports --- .../selenium/elements/interfaces/IMultiChoiceComboBox.java | 2 -- .../tests/integration/elements/MultiChoiceComboBoxTests.java | 3 --- src/test/java/w3schools/forms/SelectMultipleForm.java | 1 - 3 files changed, 6 deletions(-) diff --git a/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java b/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java index 4631f25..1848432 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java @@ -1,7 +1,5 @@ package aquality.selenium.elements.interfaces; -import java.util.List; - public interface IMultiChoiceComboBox extends IComboBox { /** diff --git a/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java b/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java index 3c220d4..d37f083 100644 --- a/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java +++ b/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java @@ -1,9 +1,6 @@ package tests.integration.elements; -import aquality.selenium.browser.AqualityServices; import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import tests.BaseTest; diff --git a/src/test/java/w3schools/forms/SelectMultipleForm.java b/src/test/java/w3schools/forms/SelectMultipleForm.java index 90fad31..8c44ef8 100644 --- a/src/test/java/w3schools/forms/SelectMultipleForm.java +++ b/src/test/java/w3schools/forms/SelectMultipleForm.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import java.util.function.IntSupplier; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; From e1e6e68d7bca1486584f65b2ed24c7d19a0d6292 Mon Sep 17 00:00:00 2001 From: Aleksey2 Meleshko Date: Thu, 13 Apr 2023 18:58:55 +0200 Subject: [PATCH 5/9] Add selectAll, getSelectedTexts, getSelectedValues methods Rename to MultiChoiceBox Add localization values Add test, add to TestSuite.xml Resolve GitHub comments --- .../aquality/selenium/elements/ComboBox.java | 8 +- .../selenium/elements/ElementFactory.java | 2 +- .../selenium/elements/ElementType.java | 2 +- .../selenium/elements/MultiChoiceBox.java | 99 +++++++++++++++++++ .../elements/MultiChoiceComboBox.java | 63 ------------ .../elements/interfaces/IElementFactory.java | 4 +- ...oiceComboBox.java => IMultiChoiceBox.java} | 23 ++++- src/main/resources/localization/be.json | 9 +- src/main/resources/localization/en.json | 9 +- src/main/resources/localization/pl.json | 7 +- src/main/resources/localization/ru.json | 9 +- src/main/resources/localization/uk.json | 7 +- ...BoxTests.java => MultiChoiceBoxTests.java} | 24 +++-- .../w3schools/forms/SelectMultipleForm.java | 32 ++++-- 14 files changed, 199 insertions(+), 99 deletions(-) create mode 100644 src/main/java/aquality/selenium/elements/MultiChoiceBox.java delete mode 100644 src/main/java/aquality/selenium/elements/MultiChoiceComboBox.java rename src/main/java/aquality/selenium/elements/interfaces/{IMultiChoiceComboBox.java => IMultiChoiceBox.java} (68%) rename src/test/java/tests/integration/elements/{MultiChoiceComboBoxTests.java => MultiChoiceBoxTests.java} (83%) diff --git a/src/main/java/aquality/selenium/elements/ComboBox.java b/src/main/java/aquality/selenium/elements/ComboBox.java index 328a5ce..3b8e900 100644 --- a/src/main/java/aquality/selenium/elements/ComboBox.java +++ b/src/main/java/aquality/selenium/elements/ComboBox.java @@ -49,7 +49,7 @@ public void clickAndSelectByText(String value) { @Override public void selectByContainingText(String text) { logElementAction("loc.combobox.select.by.text", text); - applySelectFuncToOptionThatContains(WebElement::getText, + applyFunctionToOptionsThatContain(WebElement::getText, Select::selectByVisibleText, text); } @@ -57,12 +57,12 @@ public void selectByContainingText(String text) { @Override public void selectByContainingValue(String value) { logElementAction(LOG_SELECTING_VALUE, value); - applySelectFuncToOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()), + applyFunctionToOptionsThatContain(element -> element.getAttribute(Attributes.VALUE.toString()), Select::selectByValue, value); } - protected void applySelectFuncToOptionThatContains(Function getValueFunc, BiConsumer selectFunc, String value){ + protected void applyFunctionToOptionsThatContain(Function getValueFunc, BiConsumer selectFunc, String value){ doWithRetry(() -> { Select select = new Select(getElement()); List elements = select.getOptions(); @@ -77,7 +77,7 @@ protected void applySelectFuncToOptionThatContains(Function } if (!isSelected){ throw new InvalidElementStateException(String.format(getLocalizationManager().getLocalizedMessage( - "loc.combobox.impossible.to.select.contain.value.or.text"), value, getName())); + "loc.combobox.impossible.to.find.option.contain.value.or.text"), value, getName())); } }); } diff --git a/src/main/java/aquality/selenium/elements/ElementFactory.java b/src/main/java/aquality/selenium/elements/ElementFactory.java index ac252c3..3fe48c7 100644 --- a/src/main/java/aquality/selenium/elements/ElementFactory.java +++ b/src/main/java/aquality/selenium/elements/ElementFactory.java @@ -43,7 +43,7 @@ protected Map getSelectedValues() { + logElementAction("loc.combobox.getting.selected.value"); + return collectSelectedOptions(option -> option.getAttribute(Attributes.VALUE.toString()), "value"); + } + + @Override + public List getSelectedTexts() { + logElementAction("loc.combobox.getting.selected.text"); + return collectSelectedOptions(WebElement::getText, "text"); + } + + private List collectSelectedOptions(Function valueGetter, String valueType) { + List 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); + } +} diff --git a/src/main/java/aquality/selenium/elements/MultiChoiceComboBox.java b/src/main/java/aquality/selenium/elements/MultiChoiceComboBox.java deleted file mode 100644 index e54fc18..0000000 --- a/src/main/java/aquality/selenium/elements/MultiChoiceComboBox.java +++ /dev/null @@ -1,63 +0,0 @@ -package aquality.selenium.elements; - -import aquality.selenium.core.elements.ElementState; -import aquality.selenium.elements.interfaces.IMultiChoiceComboBox; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; - -/** - * Class describing the Multi-choice ComboBox (dropdown list), i.e. the one having attribute {@code multiple} set to {@code true} - */ -public class MultiChoiceComboBox extends ComboBox implements IMultiChoiceComboBox { - - private static final String LOG_DESELECTING_VALUE = "loc.deselecting.value"; - - protected MultiChoiceComboBox(By locator, String name, ElementState state) { - super(locator, name, state); - } - - protected String getElementType() { - return getLocalizationManager().getLocalizedMessage("loc.multichoicecombobox"); - } - - @Override - public void deselectAll() { - logElementAction("loc.multichoicecombobox.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); - applySelectFuncToOptionThatContains(element -> element.getAttribute(Attributes.VALUE.toString()), - Select::deselectByValue, - value); - } - - @Override - public void deselectByText(String text) { - logElementAction("loc.multichoicecombobox.deselect.by.text", text); - doWithRetry(() -> new Select(getElement()).deselectByVisibleText(text)); - } - - @Override - public void deselectByContainingText(String text) { - logElementAction("loc.multichoicecombobox.deselect.by.text", text); - applySelectFuncToOptionThatContains(WebElement::getText, - Select::deselectByVisibleText, - text); - } -} diff --git a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java index 78378e7..a568eec 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java @@ -87,7 +87,7 @@ default IComboBox getComboBox(By locator, String name, ElementState state) { * @param name Element name * @return Instance of element that implements IMultiChoiceComboBox interface */ - default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name) { + default IMultiChoiceBox getMultiChoiceComboBox(By locator, String name) { return getMultiChoiceComboBox(locator, name, ElementState.DISPLAYED); } @@ -99,7 +99,7 @@ default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name) { * @param state Element state * @return Instance of element that implements IMultiChoiceComboBox interface */ - default IMultiChoiceComboBox getMultiChoiceComboBox(By locator, String name, ElementState state) { + default IMultiChoiceBox getMultiChoiceComboBox(By locator, String name, ElementState state) { return get(ElementType.MULTICHOICECOMBOBOX, locator, name, state); } diff --git a/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java b/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceBox.java similarity index 68% rename from src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java rename to src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceBox.java index 1848432..f3ee29a 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceComboBox.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IMultiChoiceBox.java @@ -1,6 +1,27 @@ package aquality.selenium.elements.interfaces; -public interface IMultiChoiceComboBox extends IComboBox { +import java.util.List; + +public interface IMultiChoiceBox extends IComboBox { + + /** + * Gets value of all selected options + * + * @return selected values + */ + List getSelectedValues(); + + /** + * Gets text of all selected options + * + * @return selected text + */ + List getSelectedTexts(); + + /** + * Select all options + */ + void selectAll(); /** * Deselect all selected options diff --git a/src/main/resources/localization/be.json b/src/main/resources/localization/be.json index 5411c08..2840c4e 100644 --- a/src/main/resources/localization/be.json +++ b/src/main/resources/localization/be.json @@ -43,10 +43,11 @@ "loc.combobox.get.text.js": "Атрымліваем выбраны тэкст праз JavaScript", "loc.combobox.texts": "Спіс тэкстаў опцыяў: [%s]", "loc.combobox.values": "Спіс значэнняў: [%s]", - "loc.combobox.impossible.to.select.contain.value.or.text": "Немагчыма выбраць опцыю, якая змяшчае значэнне/тэкст '%1$s' у камбабоксе '%2$s'", - "loc.multichoicecombobox": "Камбабокс з мульцівыбарам", - "loc.multichoicecombobox.deselect.all": "Адмяняем выбар усіх значэнняў", - "loc.multichoicecombobox.deselect.by.text": "Адмяняем выбар значэння з тэкстам '%s'", + "loc.combobox.impossible.to.find.option.contain.value.or.text": "Немагчыма знайсці опцыю, якая змяшчае значэнне/тэкст '%1$s' у камбабоксе '%2$s'", + "loc.multichoicebox": "Камбабокс з мульцівыбарам", + "loc.multichoicebox.select.all": "Выбіраем усе значэнні", + "loc.multichoicebox.deselect.all": "Адмяняем выбар усіх значэнняў", + "loc.multichoicebox.deselect.by.text": "Адмяняем выбар значэння з тэкстам '%s'", "loc.el.getattr": "Атрымліваем атрыбут '%1$s'", "loc.el.attr.value": "Значэнне атрыбута '%1$s': [%2$s]", "loc.el.attr.set": "Задаем значэнне атрыбута '%1$s': [%2$s]", diff --git a/src/main/resources/localization/en.json b/src/main/resources/localization/en.json index 4af9899..fde73ae 100644 --- a/src/main/resources/localization/en.json +++ b/src/main/resources/localization/en.json @@ -43,10 +43,11 @@ "loc.combobox.get.text.js": "Getting selected text via JavaScript", "loc.combobox.texts": "Option texts: [%s]", "loc.combobox.values": "Option values: [%s]", - "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'", - "loc.multichoicecombobox": "Multi-choice ComboBox", - "loc.multichoicecombobox.deselect.all": "Deselect all", - "loc.multichoicecombobox.deselect.by.text": "Deselecting value by text '%s'", + "loc.combobox.impossible.to.find.option.contain.value.or.text": "It is impossible to find an option that contains value/text '%1$s' from combobox '%2$s'", + "loc.multichoicebox": "Multi-choice ComboBox", + "loc.multichoicebox.select.all": "Select all", + "loc.multichoicebox.deselect.all": "Deselect all", + "loc.multichoicebox.deselect.by.text": "Deselecting value by text '%s'", "loc.el.getattr": "Getting attribute '%1$s'", "loc.el.attr.value": "Value of attribute '%1$s': [%2$s]", "loc.el.attr.set": "Setting value of attribute '%1$s': [%2$s]", diff --git a/src/main/resources/localization/pl.json b/src/main/resources/localization/pl.json index 5d95097..20df9ba 100644 --- a/src/main/resources/localization/pl.json +++ b/src/main/resources/localization/pl.json @@ -43,7 +43,11 @@ "loc.combobox.get.text.js": "Pobieranie wybranego tekstu przez JavaScript", "loc.combobox.texts": "Lista tekstów opcji: [%s]", "loc.combobox.values": "Lista wartości: [%s]", - "loc.combobox.impossible.to.select.contain.value.or.text": "Wybieranie wartości ze znaczeniem/tekstem '%1$s' w polu kombi '%2$s' nie jest możliwe", + "loc.combobox.impossible.to.find.option.contain.value.or.text": "Znalezienie wartości ze znaczeniem/tekstem '%1$s' w polu kombi '%2$s' nie jest możliwe", + "loc.multichoicebox": "Pole kombi z multiwyborem", + "loc.multichoicebox.select.all": "Wybieranie wszystkich wartości", + "loc.multichoicebox.deselect.all": "Anulowanie wybierania wszystkich wartości", + "loc.multichoicebox.deselect.by.text": "Anulowanie wybierania wartości z tekstem '%s'", "loc.el.getattr": "Pobieranie atrybutu '%1$s'", "loc.el.attr.value": "Wartość atrybutu '%1$s': [%2$s]", "loc.el.attr.set": "Ustawianie wartości atrybutu '%1$s': [%2$s]", @@ -68,6 +72,7 @@ "loc.scrolling.center.js": "Przewijanie do centrum przez JavaScript", "loc.scrolling.js": "Przewijanie przez JavaScript", "loc.selecting.value": "Wybieranie wartości - '%s'", + "loc.deselecting.value": "Anulowanie wybierania wartości - '%s'", "loc.send.text": "Ustawianie tekstu - '%s'", "loc.setting.value": "Ustawienie wartości - '%s'", "loc.text.clearing": "Oczyszczenie", diff --git a/src/main/resources/localization/ru.json b/src/main/resources/localization/ru.json index 9f2a783..647ecff 100644 --- a/src/main/resources/localization/ru.json +++ b/src/main/resources/localization/ru.json @@ -43,10 +43,11 @@ "loc.combobox.get.text.js": "Получение текста выбранного значения посредством JavaScript", "loc.combobox.texts": "Список текстов опций: [%s]", "loc.combobox.values": "Список значений: [%s]", - "loc.combobox.impossible.to.select.contain.value.or.text": "Не удаётся выбрать значение которое содержит значение/текст '%1$s' в выпадающем списке '%2$s'", - "loc.multichoicecombobox": "Комбобокс с мультивыбором", - "loc.multichoicecombobox.deselect.all": "Отмена выбора всех значений", - "loc.multichoicecombobox.deselect.by.text": "Отмена выбора значения с текстом '%s'", + "loc.combobox.impossible.to.find.option.contain.value.or.text": "Не удаётся найти опцию, которая содержит значение/текст '%1$s' в выпадающем списке '%2$s'", + "loc.multichoicebox": "Комбобокс с мультивыбором", + "loc.multichoicebox.select.all": "Выбор всех значений", + "loc.multichoicebox.deselect.all": "Отмена выбора всех значений", + "loc.multichoicebox.deselect.by.text": "Отмена выбора значения с текстом '%s'", "loc.el.getattr": "Получение аттрибута '%1$s'", "loc.el.attr.value": "Значение аттрибута '%1$s'': [%2$s]", "loc.el.attr.set": "Установка значения атрибута '%1$s': [%2$s]", diff --git a/src/main/resources/localization/uk.json b/src/main/resources/localization/uk.json index a2c18ae..436d08b 100644 --- a/src/main/resources/localization/uk.json +++ b/src/main/resources/localization/uk.json @@ -43,7 +43,11 @@ "loc.combobox.get.text.js": "Отримання вибраного тексту за допомогою JavaScript", "loc.combobox.texts": "Тексти опцій: [%s]", "loc.combobox.values": "Значення опцій: [%s]", - "loc.combobox.impossible.to.select.contain.value.or.text": "Неможливо вибрати опцію, що зміщує значення/текст '%1$s' у комбобоксі '%2$s'", + "loc.combobox.impossible.to.find.option.contain.value.or.text": "Неможливо знайти опцію, що містіть значення/текст '%1$s' у комбобоксі '%2$s'", + "loc.multichoicebox": "Комбобокс з мультівибором", + "loc.multichoicebox.select.all": "Вибір всіх значень", + "loc.multichoicebox.deselect.all": "Скасування вибору всіх значень", + "loc.multichoicebox.deselect.by.text": "Скасування вибору значення за текстом '%s'", "loc.el.getattr": "Отримання атрибута '%1$s'", "loc.el.attr.value": "Значення атрибута '%1$s': [%2$s]", "loc.el.attr.set": "Встановлення значення атрибута '%1$s': [%2$s]", @@ -68,6 +72,7 @@ "loc.scrolling.center.js": "Прокрутка до центру за допомогою JavaScript", "loc.scrolling.js": "Прокрутка за допомогою JavaScript", "loc.selecting.value": "Вибір значення - '%s'", + "loc.deselecting.value": "Скасування выбору значення - '%s'", "loc.send.text": "Встановлення тексту - '%s'", "loc.setting.value": "Встановлення значення - '%s'", "loc.text.clearing": "Очищення", diff --git a/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java b/src/test/java/tests/integration/elements/MultiChoiceBoxTests.java similarity index 83% rename from src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java rename to src/test/java/tests/integration/elements/MultiChoiceBoxTests.java index d37f083..4eaaa1b 100644 --- a/src/test/java/tests/integration/elements/MultiChoiceComboBoxTests.java +++ b/src/test/java/tests/integration/elements/MultiChoiceBoxTests.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class MultiChoiceComboBoxTests extends BaseTest { +public class MultiChoiceBoxTests extends BaseTest { private final SelectMultipleForm selectMultipleForm = new SelectMultipleForm(); @@ -20,13 +20,28 @@ public class MultiChoiceComboBoxTests extends BaseTest { public void beforeMethod() { getBrowser().goTo(W3SchoolsPage.SELECT_MULTIPLE.getAddress()); getBrowser().setWindowSize(defaultSize.width, defaultSize.height); + selectMultipleForm.acceptCookies(); + selectMultipleForm.switchToResultFrame(); + } + + @Test + public void testSelectAll() { + List allTexts = selectMultipleForm.getAllTexts(); + + selectMultipleForm.selectAll(); + List selected = selectMultipleForm.getSelectedTexts(); + Assert.assertEquals(allTexts, selected, "Not all texts were selected"); + + selected = selectMultipleForm.getSelectedValues(); + selectMultipleForm.submit(); + + Assert.assertEquals(selectMultipleForm.getValuesFromResult(), selected); } @Test public void testDeselectByValue() { List valuesToRemove = Stream.of("volvo", "saab").collect(Collectors.toList()); - selectMultipleForm.switchToResultFrame(); selectMultipleForm.selectAll(); List remaining = selectMultipleForm.deselectByValue(valuesToRemove); selectMultipleForm.submit(); @@ -38,7 +53,6 @@ public void testDeselectByValue() { public void testDeselectByContainingValue() { List valuesToRemove = Stream.of("saa", "ope").collect(Collectors.toList()); - selectMultipleForm.switchToResultFrame(); selectMultipleForm.selectAll(); List remaining = selectMultipleForm.deselectByContainingValue(valuesToRemove); selectMultipleForm.submit(); @@ -50,7 +64,6 @@ public void testDeselectByContainingValue() { public void testDeselectByText() { List valuesToRemove = Stream.of("Opel").collect(Collectors.toList()); - selectMultipleForm.switchToResultFrame(); selectMultipleForm.selectAll(); List remaining = selectMultipleForm.deselectByText(valuesToRemove); selectMultipleForm.submit(); @@ -62,7 +75,6 @@ public void testDeselectByText() { public void testDeselectByContainingText() { List valuesToRemove = Stream.of("Au", "Vol").collect(Collectors.toList()); - selectMultipleForm.switchToResultFrame(); selectMultipleForm.selectAll(); List remaining = selectMultipleForm.deselectByContainingText(valuesToRemove); selectMultipleForm.submit(); @@ -74,7 +86,6 @@ public void testDeselectByContainingText() { public void testDeselectByIndex() { List valuesToRemove = Stream.of(2, 3).collect(Collectors.toList()); - selectMultipleForm.switchToResultFrame(); selectMultipleForm.selectAll(); List remaining = selectMultipleForm.deselectByIndex(valuesToRemove); selectMultipleForm.submit(); @@ -84,7 +95,6 @@ public void testDeselectByIndex() { @Test public void testDeselectAll() { - selectMultipleForm.switchToResultFrame(); selectMultipleForm.selectAll(); selectMultipleForm.deselectAll(); selectMultipleForm.submit(); diff --git a/src/test/java/w3schools/forms/SelectMultipleForm.java b/src/test/java/w3schools/forms/SelectMultipleForm.java index 8c44ef8..fac5e36 100644 --- a/src/test/java/w3schools/forms/SelectMultipleForm.java +++ b/src/test/java/w3schools/forms/SelectMultipleForm.java @@ -2,7 +2,7 @@ import aquality.selenium.browser.AqualityServices; import aquality.selenium.elements.interfaces.IButton; -import aquality.selenium.elements.interfaces.IMultiChoiceComboBox; +import aquality.selenium.elements.interfaces.IMultiChoiceBox; import aquality.selenium.elements.interfaces.ITextBox; import aquality.selenium.forms.Form; import org.openqa.selenium.By; @@ -17,14 +17,22 @@ public class SelectMultipleForm extends Form { - private final IMultiChoiceComboBox cbxCars = getElementFactory().getMultiChoiceComboBox(By.id("cars"), "Cars"); + private final IMultiChoiceBox cbxCars = getElementFactory().getMultiChoiceComboBox(By.id("cars"), "Cars"); private final IButton btnSubmit = getElementFactory().getButton(By.cssSelector("input[type='submit']"), "Submit"); private final ITextBox txbResult = getElementFactory().getTextBox(By.cssSelector(".w3-large"), "Result"); + private final IButton btnAcceptCookies = getElementFactory().getButton(By.id("accept-choices"), "Accept cookies"); public SelectMultipleForm() { super(By.id("iframe"), "Select Multiple"); } + public void acceptCookies() { + if (btnAcceptCookies.state().isDisplayed()) { + btnAcceptCookies.click(); + btnAcceptCookies.state().waitForNotDisplayed(); + } + } + public void switchToResultFrame() { AqualityServices.getBrowser().getDriver().switchTo().frame("iframeResult"); } @@ -46,7 +54,19 @@ public List getValuesFromResult() { } public void selectAll() { - cbxCars.getValues().forEach(cbxCars::selectByValue); + cbxCars.selectAll(); + } + + public List getAllTexts() { + return cbxCars.getTexts(); + } + + public List getSelectedTexts() { + return cbxCars.getSelectedTexts(); + } + + public List getSelectedValues() { + return cbxCars.getSelectedValues(); } public List deselectByValue(List valuesToDeselect) { @@ -65,11 +85,11 @@ public List deselectByContainingText(List textToDesele return deselectBy(cbxCars::deselectByContainingText, textToDeselect); } - public List deselectByIndex(List indeciesToDeselect) { + public List deselectByIndex(List indicesToDeselect) { List values = cbxCars.getValues(); - indeciesToDeselect.forEach(cbxCars::deselectByIndex); + indicesToDeselect.forEach(cbxCars::deselectByIndex); return IntStream.range(0, values.size()) - .filter(i -> !indeciesToDeselect.contains(i)) + .filter(i -> !indicesToDeselect.contains(i)) .mapToObj(values::get) .collect(Collectors.toList()); } From 46922966631a135e301d082452fbd11afbb4b902 Mon Sep 17 00:00:00 2001 From: Aleksey2 Meleshko Date: Thu, 13 Apr 2023 19:04:30 +0200 Subject: [PATCH 6/9] add to TestSuite.xml --- src/test/resources/TestSuite.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/resources/TestSuite.xml b/src/test/resources/TestSuite.xml index 33dc102..21ca6cb 100644 --- a/src/test/resources/TestSuite.xml +++ b/src/test/resources/TestSuite.xml @@ -8,6 +8,7 @@ + From 34063914e7a66aa8a65cf033d78062167a9739e0 Mon Sep 17 00:00:00 2001 From: Aleksey2 Meleshko Date: Thu, 20 Apr 2023 17:33:26 +0200 Subject: [PATCH 7/9] Rename all occurrences to MultiChoiceBox --- .../aquality/selenium/elements/ElementType.java | 2 +- .../elements/interfaces/IElementFactory.java | 16 ++++++++-------- .../java/w3schools/forms/SelectMultipleForm.java | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/aquality/selenium/elements/ElementType.java b/src/main/java/aquality/selenium/elements/ElementType.java index c8d5b2a..62559ff 100644 --- a/src/main/java/aquality/selenium/elements/ElementType.java +++ b/src/main/java/aquality/selenium/elements/ElementType.java @@ -6,7 +6,7 @@ public enum ElementType { BUTTON(IButton.class), CHECKBOX(ICheckBox.class), COMBOBOX(IComboBox.class), - MULTICHOICECOMBOBOX(IMultiChoiceBox.class), + MULTICHOICEBOX(IMultiChoiceBox.class), LABEL(ILabel.class), LINK(ILink.class), RADIOBUTTON(IRadioButton.class), diff --git a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java index a568eec..d743786 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java @@ -81,26 +81,26 @@ default IComboBox getComboBox(By locator, String name, ElementState state) { } /** - * Creates element that implements IMultiChoiceComboBox interface. + * Creates element that implements IMultiChoiceBox interface. * * @param locator Element locator * @param name Element name - * @return Instance of element that implements IMultiChoiceComboBox interface + * @return Instance of element that implements IMultiChoiceBox interface */ - default IMultiChoiceBox getMultiChoiceComboBox(By locator, String name) { - return getMultiChoiceComboBox(locator, name, ElementState.DISPLAYED); + default IMultiChoiceBox getMultiChoiceBox(By locator, String name) { + return getMultiChoiceBox(locator, name, ElementState.DISPLAYED); } /** - * Creates element that implements IMultiChoiceComboBox interface. + * Creates element that implements IMultiChoiceBox interface. * * @param locator Element locator * @param name Element name * @param state Element state - * @return Instance of element that implements IMultiChoiceComboBox interface + * @return Instance of element that implements IMultiChoiceBox interface */ - default IMultiChoiceBox getMultiChoiceComboBox(By locator, String name, ElementState state) { - return get(ElementType.MULTICHOICECOMBOBOX, locator, name, state); + default IMultiChoiceBox getMultiChoiceBox(By locator, String name, ElementState state) { + return get(ElementType.MULTICHOICEBOX, locator, name, state); } /** diff --git a/src/test/java/w3schools/forms/SelectMultipleForm.java b/src/test/java/w3schools/forms/SelectMultipleForm.java index fac5e36..3ff2d66 100644 --- a/src/test/java/w3schools/forms/SelectMultipleForm.java +++ b/src/test/java/w3schools/forms/SelectMultipleForm.java @@ -17,7 +17,7 @@ public class SelectMultipleForm extends Form { - private final IMultiChoiceBox cbxCars = getElementFactory().getMultiChoiceComboBox(By.id("cars"), "Cars"); + private final IMultiChoiceBox cbxCars = getElementFactory().getMultiChoiceBox(By.id("cars"), "Cars"); private final IButton btnSubmit = getElementFactory().getButton(By.cssSelector("input[type='submit']"), "Submit"); private final ITextBox txbResult = getElementFactory().getTextBox(By.cssSelector(".w3-large"), "Result"); private final IButton btnAcceptCookies = getElementFactory().getButton(By.id("accept-choices"), "Accept cookies"); From 4c1aa456e34d97675f2991bdf859b68bbbba5963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Fri, 21 Apr 2023 19:08:23 +0200 Subject: [PATCH 8/9] Rename all occurrences to MultiChoiceBox * Rename all occurrences to MultiChoiceBox * unparallelize MultiChoiceBox tests --- src/test/resources/TestSuite.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/TestSuite.xml b/src/test/resources/TestSuite.xml index 21ca6cb..018b7be 100644 --- a/src/test/resources/TestSuite.xml +++ b/src/test/resources/TestSuite.xml @@ -8,7 +8,6 @@ - @@ -43,6 +42,7 @@ + From 40f603194f1ca8193ca41d08cbbc284509c1926f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Fri, 21 Apr 2023 19:25:49 +0200 Subject: [PATCH 9/9] remove waiting after the click * Rename all occurrences to MultiChoiceBox * unparallelize MultiChoiceBox tests * remove waiting after the click --- src/test/java/w3schools/forms/SelectMultipleForm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/w3schools/forms/SelectMultipleForm.java b/src/test/java/w3schools/forms/SelectMultipleForm.java index 3ff2d66..7277e83 100644 --- a/src/test/java/w3schools/forms/SelectMultipleForm.java +++ b/src/test/java/w3schools/forms/SelectMultipleForm.java @@ -38,7 +38,7 @@ public void switchToResultFrame() { } public void submit() { - btnSubmit.clickAndWait(); + btnSubmit.click(); } public List getValuesFromResult() {