Skip to content

Commit

Permalink
Fix TestBench API imports (#8112)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tsuoanttila authored and pleku committed Jan 13, 2017
1 parent fd8696d commit 253a61c
Show file tree
Hide file tree
Showing 289 changed files with 483 additions and 918 deletions.
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -55,11 +63,11 @@ public void selectByText(String text) throws ReadOnlyException {
}

/**
* 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) {
Expand All @@ -75,13 +83,35 @@ public List<String> getSelection() {
}

/**
* 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);
}

/**
Expand Down
Expand Up @@ -226,12 +226,49 @@ public String getValue() {
* @return the input field element
*/
public WebElement getInputField() {
return findElement(By.xpath("input"));
return findElement(By.vaadin("#textbox"));
}

private void ensurePopupOpen() {
if (!isElementPresent(bySuggestionPopup)) {
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) {
}
}
}
}
Expand Up @@ -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
Expand Down
Expand Up @@ -147,4 +147,32 @@ public ContextMenuElement getContextMenu() {
}
}

/**
* 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"));
}

}
Expand Up @@ -17,6 +17,7 @@

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.testbench.elementsbase.ServerClass;

Expand Down Expand Up @@ -91,4 +92,22 @@ public String getCaption() {
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();
}
}

This file was deleted.

This file was deleted.

0 comments on commit 253a61c

Please sign in to comment.