diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-06-01 15:46:19 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-06-02 16:14:34 +0300 |
commit | 0349e002b8904e6d91e7d7938cbe085b3501ce0f (patch) | |
tree | fb6e46876cf9688529982498bec9ed309d33e294 /uitest/src/com/vaadin/tests/tb3 | |
parent | 90e75a20bda563f90297840f4feb5668cd524633 (diff) | |
download | vaadin-framework-0349e002b8904e6d91e7d7938cbe085b3501ce0f.tar.gz vaadin-framework-0349e002b8904e6d91e7d7938cbe085b3501ce0f.zip |
Refactor MenuBar handling methods to AbstractTB3Test
This patch uses the new menubar handling in AccordionClipsContentTest
Change-Id: Ib54b8b7c51b04fb98785af214aebdd33126aa61d
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3')
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index ddf90b080b..7b77aaf817 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -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); + } } |