Browse Source

Refactor MenuBar handling methods to AbstractTB3Test

This patch uses the new menubar handling in AccordionClipsContentTest

Change-Id: Ib54b8b7c51b04fb98785af214aebdd33126aa61d
tags/7.6.0.alpha1
Teemu Suo-Anttila 9 years ago
parent
commit
0349e002b8

+ 4
- 20
uitest/src/com/vaadin/tests/components/accordion/AccordionClipsContentTest.java View File

@@ -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
@@ -29,21 +30,8 @@ public class AccordionClipsContentTest extends MultiBrowserTest {
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();

@@ -54,8 +42,4 @@ public class AccordionClipsContentTest extends MultiBrowserTest {

compareScreen("button-clicked");
}

private void clickAt(String vaadinLocator, int x, int y) {
testBenchElement(vaadinElement(vaadinLocator)).click(x, y);
}
}

+ 7
- 22
uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java View File

@@ -22,10 +22,8 @@ import static org.junit.Assert.fail;
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;
@@ -204,29 +202,16 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest
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) {

+ 0
- 29
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java View File

@@ -22,7 +22,6 @@ import java.util.ArrayList;
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;
@@ -51,34 +50,6 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest {
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);

+ 6
- 21
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java View File

@@ -21,11 +21,9 @@ import static org.junit.Assert.assertNull;
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;
@@ -152,29 +150,16 @@ public class GridClientDataSourcesTest extends MultiBrowserTest {
+ "\"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();
}

}

+ 0
- 17
uitest/src/com/vaadin/tests/components/table/TableDragColumnTest.java View File

@@ -102,21 +102,4 @@ public class TableDragColumnTest extends MultiBrowserTest {

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]);
}
}
}

+ 63
- 1
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java View File

@@ -26,7 +26,6 @@ import java.util.Arrays;
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;

@@ -40,9 +39,12 @@ import org.junit.Assert;
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;
@@ -976,4 +978,64 @@ public abstract class AbstractTB3Test extends ParallelTest {
}
});
}

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

Loading…
Cancel
Save