From 10d280301b4e6f0c9937fd2b288bcd4f1a03665c Mon Sep 17 00:00:00 2001 From: rimamdi Date: Mon, 22 Jun 2015 13:58:10 +0200 Subject: [PATCH] added AdfMenu component class with initial unit tests --- .../redheap/selenium/components/MenuTest.java | 59 +++++++++++++++++++ .../redheap/selenium/pages/MenuDemoPage.java | 40 +++++++++++++ .../redheap/selenium/component/AdfMenu.java | 11 ++++ 3 files changed, 110 insertions(+) create mode 100644 RichClientDemoTest/src/com/redheap/selenium/components/MenuTest.java create mode 100644 RichClientDemoTest/src/com/redheap/selenium/pages/MenuDemoPage.java create mode 100644 SeleniumTools/src/com/redheap/selenium/component/AdfMenu.java diff --git a/RichClientDemoTest/src/com/redheap/selenium/components/MenuTest.java b/RichClientDemoTest/src/com/redheap/selenium/components/MenuTest.java new file mode 100644 index 0000000..abb60d5 --- /dev/null +++ b/RichClientDemoTest/src/com/redheap/selenium/components/MenuTest.java @@ -0,0 +1,59 @@ +package com.redheap.selenium.components; + +import com.redheap.selenium.component.AdfCommandMenuItem; +import com.redheap.selenium.component.AdfMenu; +import com.redheap.selenium.junit.PageProvider; +import com.redheap.selenium.junit.SavePageSourceOnFailure; +import com.redheap.selenium.junit.ScreenshotOnFailure; +import com.redheap.selenium.junit.WebDriverResource; + +import com.redheap.selenium.pages.MenuDemoPage; + +import java.io.File; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.rules.TestWatcher; + +public class MenuTest { + + @ClassRule + public static WebDriverResource driver = new WebDriverResource(); + @Rule + public PageProvider pages = new PageProvider(MenuDemoPage.class, HOME_PAGE, driver.getDriver()); + @Rule + public TestWatcher screenshotOnFailure = new ScreenshotOnFailure(driver.getDriver(), new File("errors")); + @Rule + public TestWatcher saveSourceOnFailure = new SavePageSourceOnFailure(driver.getDriver(), new File("errors")); + + private static final String HOME_PAGE = "http://localhost:7101/adf-richclient-demo/faces/components/menu.jspx"; + + @Test + public void testDisabledMenu() { + AdfMenu menu = pages.goHome().findDisabledMenu(); + assertTrue(menu.isDisabled()); + } + + @Test + public void testFileMenu() { + MenuDemoPage page = pages.goHome(); + AdfMenu menu = page.findFileMenu(); + assertTrue(!menu.isDisabled()); + assertEquals("File", menu.getElement().getText()); + menu.click(); + AdfCommandMenuItem closeItem = page.findCloseItem(); + assertEquals("Close Ctrl+W", closeItem.getElement().getText()); + } + + @Test + public void testSubMenuNew() { + MenuDemoPage page = pages.goHome(); + AdfMenu menu = page.findFileMenu(); + menu.click(); + AdfMenu newMenu = page.findNewSubMenu(); + assertEquals("New", newMenu.getElement().getText()); + } +} diff --git a/RichClientDemoTest/src/com/redheap/selenium/pages/MenuDemoPage.java b/RichClientDemoTest/src/com/redheap/selenium/pages/MenuDemoPage.java new file mode 100644 index 0000000..56d6acd --- /dev/null +++ b/RichClientDemoTest/src/com/redheap/selenium/pages/MenuDemoPage.java @@ -0,0 +1,40 @@ +package com.redheap.selenium.pages; + +import com.redheap.selenium.component.AdfCommandMenuItem; +import com.redheap.selenium.component.AdfMenu; +import com.redheap.selenium.page.Page; + +import org.openqa.selenium.WebDriver; + +public class MenuDemoPage extends Page { + + private final String fileMenu = "dmoTpl:menu1"; + private final String newSubmenu = "dmoTpl:menu2"; + private final String disabledMenu = "dmoTpl:menu8"; + private final String closeMenuItem = "dmoTpl:cmi9"; + + public MenuDemoPage(WebDriver webDriver) { + super(webDriver); + } + + @Override + protected String getExpectedTitle() { + return "menu Demo"; + } + + public AdfMenu findFileMenu() { + return findAdfComponent(fileMenu); + } + + public AdfCommandMenuItem findCloseItem(){ + return findAdfComponent(closeMenuItem); + } + + public AdfMenu findNewSubMenu() { + return findAdfComponent(newSubmenu); + } + + public AdfMenu findDisabledMenu() { + return findAdfComponent(disabledMenu); + } +} diff --git a/SeleniumTools/src/com/redheap/selenium/component/AdfMenu.java b/SeleniumTools/src/com/redheap/selenium/component/AdfMenu.java new file mode 100644 index 0000000..abd6db2 --- /dev/null +++ b/SeleniumTools/src/com/redheap/selenium/component/AdfMenu.java @@ -0,0 +1,11 @@ +package com.redheap.selenium.component; + +import org.openqa.selenium.WebDriver; + +public class AdfMenu extends AdfComponent { + + public AdfMenu(WebDriver webDriver, String clientId) { + super(webDriver, clientId); + } + +}