Skip to content

Commit

Permalink
Add testbench-api for board, fixes DASH-104 (#65)
Browse files Browse the repository at this point in the history
* Add testbench-api for board, fixes DASH-104

Add plugin repository to precompiled module
  • Loading branch information
rogozinds authored Jun 12, 2017
1 parent d4e77fc commit b8ec87d
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 27 deletions.
5 changes: 5 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
<artifactId>vaadin-spreadsheet</artifactId>
<version>${vaadin-spreadsheet.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin.board</groupId>
<artifactId>vaadin-board-testbench-api</artifactId>
<version>${project.version}</version>
</dependency>


</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.vaadin.addon.board.testbenchtests;

import static com.vaadin.addon.board.testUI.UIFunctions.readTestbenchProperties;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetAddress;
Expand All @@ -13,7 +12,6 @@

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.BasicUI;
import com.vaadin.testbench.By;
import com.vaadin.board.elements.BoardElement;
import com.vaadin.testbench.elements.ButtonElement;

public class BasicIT extends AbstractParallelTest {
Expand All @@ -17,7 +16,7 @@ protected Class<?> getUIClass() {

@Test
public void basicLayout_boardTabletSize_twoRowsAndTwoItemsInRow() {
WebElement board = getDriver().findElement(By.tagName("vaadin-board"));
BoardElement board = $(BoardElement.class).get(0);
ButtonElement btn1 = $(ButtonElement.class).caption("Button 1").first();
ButtonElement btn2 = $(ButtonElement.class).caption("Button 2").first();
ButtonElement btn3 = $(ButtonElement.class).caption("Button 3").first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.BoardDynamicResizeUI;
import com.vaadin.testbench.By;
import com.vaadin.board.elements.BoardElement;
import com.vaadin.board.elements.RowElement;
import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elements.ButtonElement;

public class BoardDynamicResizeIT extends AbstractParallelTest {
Expand All @@ -19,8 +20,9 @@ protected Class<?> getUIClass() {

@Test
public void basicLayout_boardTabletSize_twoRowsAndTwoItemsInRow() {
WebElement board = getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rowChildren = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/*"));
BoardElement board = $(BoardElement.class).get(0);
RowElement row = board.getRow(0);
List<AbstractComponentElement> rowChildren = row.$(AbstractComponentElement.class).all();
ButtonElement resizeButton = $(ButtonElement.class).caption("resize").first();
resizeButton.click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.ColsUI;
import com.vaadin.testbench.By;
import com.vaadin.board.elements.BoardElement;
import com.vaadin.board.elements.RowElement;
import com.vaadin.testbench.elements.ButtonElement;

/**
Expand All @@ -23,8 +23,8 @@ protected Class<?> getUIClass() {
@Test
public void removeColsTest()
throws Exception {
WebElement board = getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rows = board.findElements(By.xpath("//vaadin-board/vaadin-board-row"));
BoardElement board = $(BoardElement.class).get(0);
List<RowElement> rows = board.getRows();
Assert.assertEquals(1, rows.size());

ButtonElement btn = $(ButtonElement.class).caption("remove").first();
Expand All @@ -38,8 +38,8 @@ public void removeColsTest()
@Test
public void exceptionColsTest()
throws Exception {
WebElement board = getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rows = board.findElements(By.xpath("//vaadin-board/vaadin-board-row"));
BoardElement board = $(BoardElement.class).get(0);
List<RowElement> rows = board.getRows();
Assert.assertEquals(1, rows.size());

ButtonElement btn = $(ButtonElement.class).caption("exception").first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.InnerRowUI;
import com.vaadin.board.elements.BoardElement;
import com.vaadin.board.elements.RowElement;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;

Expand All @@ -23,8 +25,8 @@ public void oneRowBoard_addInnerRow_hasOneInnerRow() {
ButtonElement addButton = $(ButtonElement.class).id(InnerRowUI.BUTTON_ADD_ID);
addButton.click();

WebElement board =getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rows = board.findElements(By.xpath("//vaadin-board/vaadin-board-row"));
BoardElement board = $(BoardElement.class).get(0);
List<RowElement> rows = board.getRows();
List<WebElement> innerRow = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/vaadin-board-row"));
List<WebElement> innerRowChildren = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/vaadin-board-row/*"));

Expand All @@ -41,8 +43,8 @@ public void oneRowBoard_addThenRemoveInnerRow_hasNoInnerRow() {
addButton.click();
rmvButton.click();

WebElement board =getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rows = board.findElements(By.xpath("//vaadin-board/vaadin-board-row"));
BoardElement board = $(BoardElement.class).get(0);
List<RowElement> rows = board.getRows();
List<WebElement> innerRow = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/vaadin-board-row"));

Assert.assertEquals("Board has only one row" , 1, rows.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.RemoveComponentUI;
import com.vaadin.testbench.By;
import com.vaadin.board.elements.BoardElement;
import com.vaadin.testbench.elements.AbstractComponentElement;

public class RemoveComponentIT extends AbstractParallelTest {

Expand All @@ -18,9 +18,9 @@ protected Class<?> getUIClass() {

@Test
public void basicLayout_removeComponentFromRow_removedComponentsNotShown() {
WebElement board =getDriver().findElement(By.tagName("vaadin-board"));
BoardElement board =$(BoardElement.class).first();

List<WebElement> children = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/*"));
List<AbstractComponentElement> children = board.getRow(0).$(AbstractComponentElement.class).all();
Assert.assertEquals("Board should have 2 children", 2, children.size());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.RowRemoveUI;
import com.vaadin.board.elements.BoardElement;
import com.vaadin.board.elements.RowElement;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;

Expand All @@ -19,16 +21,16 @@ protected Class<?> getUIClass() {

@Test
public void twoRowsBoard_removeRow_hasOneRow() {
WebElement board =getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rows = board.findElements(By.xpath("//vaadin-board/vaadin-board-row"));
BoardElement board =$(BoardElement.class).first();
List<RowElement> rows = board.getRows();
List<WebElement> children = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/*"));
Assert.assertEquals("Before removing board has 2 rows" , 2, rows.size());
Assert.assertEquals("Board removing board has 4 elements", 4, children.size());

ButtonElement rmvButton =$(ButtonElement.class).id(RowRemoveUI.RMV_BUTTON_ID);
rmvButton.click();

rows = board.findElements(By.xpath("//vaadin-board/vaadin-board-row"));
rows = board.getRows();
children = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/*"));
Assert.assertEquals("Board has only one row" , 1, rows.size());
Assert.assertEquals("Board has two buttons", 2, children.size());
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<module>addon</module>
<module>precompiled</module>
<module>integration-tests</module>
<module>testbench-api</module>
</modules>

</project>
7 changes: 6 additions & 1 deletion precompiled/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
Expand Down
65 changes: 65 additions & 0 deletions testbench-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>vaadin-board-root</artifactId>
<groupId>com.vaadin.board</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>vaadin-board-testbench-api</artifactId>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-testbench-api</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<configuration>
<licenseName>cval3</licenseName>
<licenseResolver>file://${basedir}/src/license</licenseResolver>
<includes>
<include>**/main/**/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.vaadin.board.elements;

/*
* #%L
* Vaadin Spreadsheet Testbench API
* %%
* Copyright (C) 2013 - 2016 Vaadin Ltd
* %%
* This program is available under Commercial Vaadin Add-On License 3.0
* (CVALv3).
*
* See the file license.html distributed with this software for more
* information about licensing.
*
* You should have received a copy of the CVALv3 along with this program.
* If not, see <http://vaadin.com/license/cval-3>.
* #L%
*/

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elementsbase.ServerClass;

/**
* This is the base element class for accessing a Vaadin Board component
* for TestBench testing.
*
* @author Vaadin Ltd.
*/
@ServerClass("com.vaadin.board.Board")
public class BoardElement extends AbstractComponentElement {

/**
* Gets the row header element at the given index.
*
* @param rowIndex
* Index of target row, 0-based
* @return Row at the given index
*/
public RowElement getRow(int rowIndex) {
List<RowElement> rows = getRows();
if (rows != null && rows.size() > rowIndex) {
return rows.get(rowIndex);
}
throw new NoSuchElementException(
String.format("There is no row with the index %d in the current board", rowIndex));
}

/**
* Gets all rows from the board. Inner rows are not included.
*
* @return Row elements
*/
public List<RowElement> getRows() {
List<WebElement> elements = findElements(By.xpath("./vaadin-board-row"));
List<RowElement> rElements = new ArrayList<RowElement>();
for (TestBenchElement elem : wrapElements(elements, getCommandExecutor())) {
rElements.add(elem.wrap(RowElement.class));
}
return rElements;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.vaadin.board.elements;

/*
* #%L
* Vaadin Spreadsheet Testbench API
* %%
* Copyright (C) 2013 - 2016 Vaadin Ltd
* %%
* This program is available under Commercial Vaadin Add-On License 3.0
* (CVALv3).
*
* See the file license.html distributed with this software for more
* information about licensing.
*
* You should have received a copy of the CVALv3 along with this program.
* If not, see <http://vaadin.com/license/cval-3>.
* #L%
*/

import com.vaadin.testbench.elements.AbstractComponentContainerElement;
import com.vaadin.testbench.elementsbase.ServerClass;

/**
* This class represents one row inside the Vaadin Board.
*
* @author Vaadin Ltd.
*/
@ServerClass("com.vaadin.board.Row")
public class RowElement extends AbstractComponentContainerElement {
}

0 comments on commit b8ec87d

Please sign in to comment.