aboutsummaryrefslogtreecommitdiffstats
path: root/testbench-api/src/main/java
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-01-13 09:32:41 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-01-13 09:32:41 +0200
commit253a61c1957941759deff87518989a71c30fc301 (patch)
tree90f26a96533daade29e536137efe5433144ac2cd /testbench-api/src/main/java
parentfd8696de945b8a3f3fa954ed56b4a48e3060d50a (diff)
downloadvaadin-framework-253a61c1957941759deff87518989a71c30fc301.tar.gz
vaadin-framework-253a61c1957941759deff87518989a71c30fc301.zip
Fix TestBench API imports (#8112)
* Fix TestBench API imports, move functionality from custom elements * Fixes to TestBench APIs and JavaDocs * Merge remote-tracking branch 'origin/master' into 578_tbapi_cleanup * Fix method name in CheckBoxGroupTest * Remove unused custom element classes * Implement getOptions using getOptionElements * Replace setValue with setSelection in CheckBoxGroupElement * Rename CheckBoxGroupElement getSelection to getValue * Fix one last method
Diffstat (limited to 'testbench-api/src/main/java')
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java56
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java39
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/MenuBarElement.java2
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/TableElement.java28
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/WindowElement.java19
5 files changed, 129 insertions, 15 deletions
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 ae6e65a62d..b24f5f69f8 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
@@ -16,7 +16,9 @@
package com.vaadin.testbench.elements;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
import org.openqa.selenium.WebElement;
@@ -33,12 +35,18 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
private static org.openqa.selenium.By byRadioInput = By.tagName("input");
public List<String> getOptions() {
- List<String> optionTexts = new ArrayList<String>();
- List<WebElement> options = findElements(bySelectOption);
- for (WebElement option : options) {
- optionTexts.add(option.findElement(byLabel).getText());
- }
- return optionTexts;
+ return getOptionElements().stream()
+ .map(option -> option.findElement(byLabel).getText())
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Gets the list of option elements for this check box group.
+ *
+ * @return list of option elements
+ */
+ public List<WebElement> getOptionElements() {
+ return findElements(bySelectOption);
}
public void selectByText(String text) throws ReadOnlyException {
@@ -55,11 +63,11 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
}
/**
- * Return list of the selected options in the checkbox group
+ * Return list of the selected options in the checkbox group.
*
* @return list of the selected options in the checkbox group
*/
- public List<String> getSelection() {
+ public List<String> getValue() {
List<String> values = new ArrayList<>();
List<WebElement> options = findElements(bySelectOption);
for (WebElement option : options) {
@@ -75,13 +83,35 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
}
/**
- * Select option in the option group with the specified value.
+ * Sets the selected options for this checkbox group.
+ *
+ * @param options
+ * the options to select
+ *
+ * @see #getValue()
+ * @see #setValue(List)
+ */
+ public void setValue(String... options) {
+ setValue(Arrays.asList(options));
+ }
+
+ /**
+ * Sets the selected options for this checkbox group.
+ *
+ * @param options
+ * the list of options to select
*
- * @param chars
- * value of the option in the option group which will be selected
+ * @see #getValue()
+ * @see #setValue(String...)
*/
- public void setValue(CharSequence chars) throws ReadOnlyException {
- selectByText((String) chars);
+ public void setValue(List<String> options) {
+ // Deselect everything that is not going to be selected again.
+ getValue().stream().filter(option -> !options.contains(option))
+ .forEach(this::selectByText);
+ // Select everything that still needs selecting.
+ List<String> selection = getValue();
+ options.stream().filter(option -> !selection.contains(option))
+ .forEach(this::selectByText);
}
/**
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 dcd6725363..dd538cecc1 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
@@ -226,7 +226,7 @@ public class ComboBoxElement extends AbstractSelectElement {
* @return the input field element
*/
public WebElement getInputField() {
- return findElement(By.xpath("input"));
+ return findElement(By.vaadin("#textbox"));
}
private void ensurePopupOpen() {
@@ -234,4 +234,41 @@ public class ComboBoxElement extends AbstractSelectElement {
openPopup();
}
}
+
+ @Override
+ public String getText() {
+ return getInputField().getAttribute("value");
+ }
+
+ @Override
+ public void clear() {
+ getInputField().clear();
+ }
+
+ @Override
+ public void sendKeys(CharSequence... keysToSend) {
+ sendKeys(50, keysToSend);
+ }
+
+ /**
+ * Use this method to simulate typing into an element, which may set its
+ * value.
+ *
+ * @param delay
+ * delay after sending each individual key (mainly needed for
+ * PhantomJS)
+ * @param keysToSend
+ * keys to type into the element
+ */
+ public void sendKeys(int delay, CharSequence... keysToSend) {
+ WebElement input = getInputField();
+
+ for (CharSequence key : keysToSend) {
+ input.sendKeys(key);
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
}
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/MenuBarElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/MenuBarElement.java
index 18b4240578..8c54b0584c 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/MenuBarElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/MenuBarElement.java
@@ -37,7 +37,7 @@ public class MenuBarElement extends AbstractComponentElement {
* If the item is another submenu, that submenu is opened.<br>
* If the item is not a submenu, it will be clicked and trigger any actions
* associated to it.
- *
+ *
* @param item
* name of the item to click
* @throws NullPointerException
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/TableElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/TableElement.java
index 68a42533b1..da167805e8 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/TableElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/TableElement.java
@@ -147,4 +147,32 @@ public class TableElement extends AbstractSelectElement {
}
}
+ /**
+ * Opens the collapse menu of this table and returns the element for it.
+ *
+ * @return collapse menu element
+ */
+ public CollapseMenuElement openCollapseMenu() {
+ getCollapseMenuToggle().click();
+ WebElement cm = getDriver()
+ .findElement(By.xpath("//*[@id='PID_VAADIN_CM']"));
+ return wrapElement(cm, getCommandExecutor())
+ .wrap(CollapseMenuElement.class);
+ }
+
+ /**
+ * Element representing a collapse menu of a Table.
+ */
+ public static class CollapseMenuElement extends ContextMenuElement {
+ }
+
+ /**
+ * Gets the button that shows or hides the collapse menu.
+ *
+ * @return button for opening collapse menu
+ */
+ public WebElement getCollapseMenuToggle() {
+ return findElement(By.className("v-table-column-selector"));
+ }
+
}
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/WindowElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/WindowElement.java
index 08c1a2f28d..39b5bfa830 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/WindowElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/WindowElement.java
@@ -17,6 +17,7 @@ package com.vaadin.testbench.elements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
import com.vaadin.testbench.elementsbase.ServerClass;
@@ -91,4 +92,22 @@ public class WindowElement extends PanelElement {
return findElement(By.className(HEADER_CLASS)).getText();
}
+ /**
+ * Moves the window by given offset.
+ *
+ * @param xOffset
+ * x offset
+ * @param yOffset
+ * y offset
+ */
+ public void move(int xOffset, int yOffset) {
+ Actions action = new Actions(getDriver());
+ action.moveToElement(
+ findElement(org.openqa.selenium.By.className("v-window-wrap")),
+ 5, 5);
+ action.clickAndHold();
+ action.moveByOffset(xOffset, yOffset);
+ action.release();
+ action.build().perform();
+ }
}