Skip to content

Commit

Permalink
Refactor MenuBar handling methods to AbstractTB3Test
Browse files Browse the repository at this point in the history
This patch uses the new menubar handling in AccordionClipsContentTest

Change-Id: Ib54b8b7c51b04fb98785af214aebdd33126aa61d
  • Loading branch information
Teemu Suo-Anttila committed Jun 2, 2015
1 parent 90e75a2 commit 0349e00
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 110 deletions.
Expand Up @@ -15,9 +15,10 @@
*/
package com.vaadin.tests.components.accordion;

import org.junit.Test;

import com.vaadin.testbench.elements.NativeButtonElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import org.junit.Test;

public class AccordionClipsContentTest extends MultiBrowserTest {
@Override
Expand All @@ -29,21 +30,8 @@ protected Class<?> getUIClass() {
public void testAccordionClipsContent() throws Exception {
openTestURL();

/*
* MenuBarElement doesn't have any API, so this part is ugly until
* #13364 is fixed
*/

// Component
vaadinElement("PID_Smenu#item0").click();
// Component container features
clickAt("Root/VOverlay[0]/VMenuBar[0]#item3", 136, 8);
// Add component
clickAt("Root/VOverlay[1]/VMenuBar[0]#item0", 65, 4);
// NativeButton
clickAt("Root/VOverlay[2]/VMenuBar[0]#item1", 86, 2);
// autoxauto
vaadinElement("Root/VOverlay[3]/VMenuBar[0]#item0").click();
selectMenuPath("Component", "Component container features",
"Add component", "NativeButton", "auto x auto");

$(NativeButtonElement.class).first().click();

Expand All @@ -54,8 +42,4 @@ public void testAccordionClipsContent() throws Exception {

compareScreen("button-clicked");
}

private void clickAt(String vaadinLocator, int x, int y) {
testBenchElement(vaadinElement(vaadinLocator)).click(x, y);
}
}
Expand Up @@ -22,10 +22,8 @@
import java.util.List;

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

import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.parallel.TestCategory;
Expand Down Expand Up @@ -204,29 +202,16 @@ private TestBenchElement getRow(String sectionTag, int row) {
return null;
}

@Override
protected void selectMenu(String menuCaption) {
TestBenchElement menuElement = getMenuElement(menuCaption);
Dimension size = menuElement.getSize();
new Actions(getDriver()).moveToElement(menuElement, size.width - 10,
size.height / 2).perform();
}

private TestBenchElement getMenuElement(String menuCaption) {
return (TestBenchElement) findElement(By.xpath("//td[text() = '"
+ menuCaption + "']"));
// GWT menu does not need to be clicked.
selectMenu(menuCaption, false);
}

protected void selectMenuPath(String... menuCaptions) {
new Actions(getDriver()).moveToElement(getMenuElement(menuCaptions[0]))
.click().perform();
for (int i = 1; i < menuCaptions.length - 1; ++i) {
selectMenu(menuCaptions[i]);
new Actions(getDriver()).moveByOffset(20, 0).perform();
}
new Actions(getDriver())
.moveToElement(
getMenuElement(menuCaptions[menuCaptions.length - 1]))
.click().perform();
@Override
protected WebElement getMenuElement(String menuCaption) {
return getDriver().findElement(
By.xpath("//td[text() = '" + menuCaption + "']"));
}

protected void assertLogContains(String substring) {
Expand Down
Expand Up @@ -22,7 +22,6 @@
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -51,34 +50,6 @@ protected Class<?> getUIClass() {
return GridBasicFeatures.class;
}

protected void selectMenu(String menuCaption) {
selectMenu(menuCaption, true);
}

protected void selectMenu(String menuCaption, boolean click) {
WebElement menuElement = getMenuElement(menuCaption);
Dimension size = menuElement.getSize();
new Actions(getDriver()).moveToElement(menuElement, size.width - 10,
size.height / 2).perform();
if (click) {
new Actions(getDriver()).click().perform();
}
}

protected WebElement getMenuElement(String menuCaption) {
return getDriver().findElement(
By.xpath("//span[text() = '" + menuCaption + "']"));
}

protected void selectMenuPath(String... menuCaptions) {
selectMenu(menuCaptions[0], true);
for (int i = 1; i < menuCaptions.length - 1; i++) {
selectMenu(menuCaptions[i]);
new Actions(getDriver()).moveByOffset(40, 0).build().perform();
}
selectMenu(menuCaptions[menuCaptions.length - 1], true);
}

protected CustomGridElement getGridElement() {
return ((TestBenchElement) findElement(By.id("testComponent")))
.wrap(CustomGridElement.class);
Expand Down
Expand Up @@ -21,11 +21,9 @@
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
Expand Down Expand Up @@ -152,29 +150,16 @@ private WebElement findVerticalScrollbar() {
+ "\"v-grid-scroller-vertical\")]"));
}

private void selectMenu(String menuCaption) {
WebElement menuElement = getMenuElement(menuCaption);
Dimension size = menuElement.getSize();
new Actions(getDriver()).moveToElement(menuElement, size.width - 10,
size.height / 2).perform();
@Override
protected void selectMenu(String menuCaption) {
// GWT menu does not need to be clicked.
selectMenu(menuCaption, false);
}

private WebElement getMenuElement(String menuCaption) {
@Override
protected WebElement getMenuElement(String menuCaption) {
return getDriver().findElement(
By.xpath("//td[text() = '" + menuCaption + "']"));
}

private void selectMenuPath(String... menuCaptions) {
new Actions(getDriver()).moveToElement(getMenuElement(menuCaptions[0]))
.click().perform();
for (int i = 1; i < menuCaptions.length - 1; ++i) {
selectMenu(menuCaptions[i]);
new Actions(getDriver()).moveByOffset(20, 0).perform();
}
new Actions(getDriver())
.moveToElement(
getMenuElement(menuCaptions[menuCaptions.length - 1]))
.click().perform();
}

}
Expand Up @@ -102,21 +102,4 @@ private void dragAndAssertStyleName(String styleName) {

new Actions(getDriver()).release().perform();
}

protected void selectSubMenu(String menuCaption) {
selectMenu(menuCaption);
new Actions(getDriver()).moveByOffset(100, 0).build().perform();
}

protected void selectMenu(String menuCaption) {
getDriver().findElement(
By.xpath("//span[text() = '" + menuCaption + "']")).click();
}

protected void selectMenuPath(String... menuCaptions) {
selectMenu(menuCaptions[0]);
for (int i = 1; i < menuCaptions.length; i++) {
selectSubMenu(menuCaptions[i]);
}
}
}
64 changes: 63 additions & 1 deletion uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
Expand Up @@ -26,7 +26,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Level;

Expand All @@ -40,9 +39,12 @@
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.HasInputDevices;
import org.openqa.selenium.interactions.Keyboard;
import org.openqa.selenium.interactions.Mouse;
Expand Down Expand Up @@ -976,4 +978,64 @@ public Boolean apply(WebDriver input) {
}
});
}

/**
* Selects a menu item. By default, this will click on the menu item.
*
* @param menuCaption
* caption of the menu item
*/
protected void selectMenu(String menuCaption) {
selectMenu(menuCaption, true);
}

/**
* Selects a menu item.
*
* @param menuCaption
* caption of the menu item
* @param click
* <code>true</code> if should click the menu item;
* <code>false</code> if not
*/
protected void selectMenu(String menuCaption, boolean click) {
WebElement menuElement = getMenuElement(menuCaption);
Dimension size = menuElement.getSize();
new Actions(getDriver()).moveToElement(menuElement, size.width - 10,
size.height / 2).perform();
if (click) {
new Actions(getDriver()).click().perform();
}
}

/**
* Finds the menu item from the DOM based on menu item caption.
*
* @param menuCaption
* caption of the menu item
* @return the found menu item
* @throws NoSuchElementException
* if menu item is not found
*/
protected WebElement getMenuElement(String menuCaption)
throws NoSuchElementException {
return getDriver().findElement(
By.xpath("//span[text() = '" + menuCaption + "']"));
}

/**
* Selects a submenu described by a path of menus from the first MenuBar in
* the UI.
*
* @param menuCaptions
* array of menu captions
*/
protected void selectMenuPath(String... menuCaptions) {
selectMenu(menuCaptions[0], true);
for (int i = 1; i < menuCaptions.length - 1; i++) {
selectMenu(menuCaptions[i]);
new Actions(getDriver()).moveByOffset(40, 0).build().perform();
}
selectMenu(menuCaptions[menuCaptions.length - 1], true);
}
}

0 comments on commit 0349e00

Please sign in to comment.