aboutsummaryrefslogtreecommitdiffstats
path: root/testbench-api
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-01-11 13:45:51 +0200
committerHenri Sara <henri.sara@gmail.com>2017-01-11 13:45:51 +0200
commitf7e33df4fcf07a73a06a372955b793bd77fe103a (patch)
tree2983cb6a2d0f0a1c77d67283220e3c546c6711e7 /testbench-api
parentaae36190f7647dc773c7410f68f41b731c937d97 (diff)
downloadvaadin-framework-f7e33df4fcf07a73a06a372955b793bd77fe103a.tar.gz
vaadin-framework-f7e33df4fcf07a73a06a372955b793bd77fe103a.zip
Import element tests from TestBench (#8117)
Contains some additional tests and element changes based on review.
Diffstat (limited to 'testbench-api')
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java3
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java13
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java8
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java9
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java23
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java25
6 files changed, 51 insertions, 30 deletions
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java
index 6263ce5b0f..788d4a917d 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java
@@ -67,6 +67,9 @@ public class CheckBoxElement extends AbstractFieldElement {
@Override
public void click() {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
WebElement input = getInputElement();
if (isFirefox()) {
// When using Valo, the input element is covered by a
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java
index ed657c085d..ae6e65a62d 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java
@@ -55,11 +55,12 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
}
/**
- * Return value of the selected option in the option group
+ * Return list of the selected options in the checkbox group
*
- * @return value of the selected option in the option group
+ * @return list of the selected options in the checkbox group
*/
- public String getValue() {
+ public List<String> getSelection() {
+ List<String> values = new ArrayList<>();
List<WebElement> options = findElements(bySelectOption);
for (WebElement option : options) {
WebElement checkedItem;
@@ -67,14 +68,14 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
String checked = checkedItem.getAttribute("checked");
if (checked != null
&& checkedItem.getAttribute("checked").equals("true")) {
- return option.findElement(By.tagName("label")).getText();
+ values.add(option.findElement(By.tagName("label")).getText());
}
}
- return null;
+ return values;
}
/**
- * Select option in the option group with the specified value
+ * Select option in the option group with the specified value.
*
* @param chars
* value of the option in the option group which will be selected
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java
index 980c4a1e7f..dcd6725363 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java
@@ -44,6 +44,10 @@ public class ComboBoxElement extends AbstractSelectElement {
* the text of the option to select
*/
public void selectByText(String text) {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
+
if (!isTextInputAllowed()) {
selectByTextFromPopup(text);
return;
@@ -57,7 +61,7 @@ public class ComboBoxElement extends AbstractSelectElement {
/**
* Selects, without filtering, the first option in the ComboBox which
* matches the given text.
- *
+ *
* @param text
* the text of the option to select
*/
@@ -96,7 +100,7 @@ public class ComboBoxElement extends AbstractSelectElement {
/**
* Checks if text input is allowed for the combo box.
- *
+ *
* @return <code>true</code> if text input is allowed, <code>false</code>
* otherwise
*/
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java
index 4ce4c9008f..77660904f3 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java
@@ -40,7 +40,7 @@ public class ListSelectElement extends AbstractSelectElement {
}
/**
- * Selects the option(s) with the given text.
+ * Selects the option with the given text.
* <p>
* For a ListSelect in multi select mode, adds the given option(s) to the
* current selection.
@@ -49,6 +49,10 @@ public class ListSelectElement extends AbstractSelectElement {
* the text of the option
*/
public void selectByText(String text) {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
+
select.selectByVisibleText(text);
if (isPhantomJS() && select.isMultiple()) {
// Phantom JS does not fire a change event when
@@ -64,6 +68,9 @@ public class ListSelectElement extends AbstractSelectElement {
* the text of the option
*/
public void deselectByText(String text) {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
select.deselectByVisibleText(text);
if (isPhantomJS() && select.isMultiple()) {
// Phantom JS does not fire a change event when
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java
index 396a2435b3..5f20c0b9d2 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java
@@ -15,10 +15,7 @@
*/
package com.vaadin.testbench.elements;
-import java.util.List;
-
import org.openqa.selenium.WebElement;
-import org.openqa.selenium.remote.BrowserType;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elementsbase.ServerClass;
@@ -27,27 +24,13 @@ import com.vaadin.testbench.elementsbase.ServerClass;
public class SliderElement extends AbstractFieldElement {
/**
* Get value of the slider
- *
+ *
* Warning! This method cause slider popup to appear on the screen. To hide
* this popup just focus any other element on the page.
*/
public String getValue() {
- List<WebElement> popupElems = findElements(By.vaadin("#popup"));
- // SubPartAware was implemented after 7.2.6, not sure in which release
- // it will be included
- if (popupElems.isEmpty()) {
- throw new UnsupportedOperationException(
- "Current version of vaadin doesn't support geting values from sliderElement");
-
- }
- WebElement popupElem = popupElems.get(0);
-
- if (BrowserType.IE.equals(getCapabilities().getBrowserName())
- && "8".equals(getCapabilities().getVersion())) {
- return popupElem.getAttribute("innerText");
- } else {
- return popupElem.getAttribute("textContent");
- }
+ WebElement popupElem = findElement(By.vaadin("#popup"));
+ return popupElem.getAttribute("textContent");
}
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java
index c68ade8ff4..7f3859c146 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java
@@ -62,7 +62,17 @@ public class TwinColSelectElement extends AbstractSelectElement {
}
}
+ /**
+ * Deselects the option with the given option text, i.e. removes it from the
+ * right side column.
+ *
+ * @param text
+ * the text of the option to deselect
+ */
public void deselectByText(String text) {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
selectedOptions.deselectAll();
selectedOptions.selectByVisibleText(text);
deselButton.click();
@@ -98,7 +108,18 @@ public class TwinColSelectElement extends AbstractSelectElement {
return getOptionsFromSelect(options);
}
+ /**
+ * Selects the option with the given option text, i.e. adds it to the right
+ * side column.
+ *
+ * @param text
+ * the text of the option to select
+ */
public void selectByText(String text) {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
+
options.deselectAll();
options.selectByVisibleText(text);
selButton.click();
@@ -113,7 +134,9 @@ public class TwinColSelectElement extends AbstractSelectElement {
}
/**
- * Return first selected item (item in the right part of component)
+ * Return first selected item (item in the right part of component).
+ *
+ * @return the option text for the item
*/
public String getValue() {
String value = "";