diff --git a/RichClientDemoTest/src/com/redheap/selenium/LocatorTest.java b/RichClientDemoTest/src/com/redheap/selenium/LocatorTest.java index 5764546..0af2ec7 100644 --- a/RichClientDemoTest/src/com/redheap/selenium/LocatorTest.java +++ b/RichClientDemoTest/src/com/redheap/selenium/LocatorTest.java @@ -1,14 +1,11 @@ package com.redheap.selenium; -import com.redheap.selenium.component.AdfDynamicDeclarativeComponent; import com.redheap.selenium.component.AdfInputText; -import com.redheap.selenium.component.AdfOutputText; import com.redheap.selenium.component.AdfTable; 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.DeclarativeComponentPage; import com.redheap.selenium.pages.EditableTablePage; import java.io.File; @@ -30,8 +27,8 @@ public class LocatorTest { public static WebDriverResource driver = new WebDriverResource(); @Rule public PageProvider tablePage = new PageProvider(EditableTablePage.class, TABLE_PAGE, driver.getDriver()); - @Rule - public PageProvider declCompPage = new PageProvider(DeclarativeComponentPage.class, DECL_COMP_PAGE, driver.getDriver()); +// @Rule +// public PageProvider declCompPage = new PageProvider(DeclarativeComponentPage.class, DECL_COMP_PAGE, driver.getDriver()); @Rule public TestWatcher screenshotOnFailure = new ScreenshotOnFailure(driver.getDriver(), new File("errors")); @Rule @@ -63,15 +60,15 @@ public void testRelativeLocatorFromNonNamingContainer() { assertEquals("dmoTpl:table1:0:it3", target.getClientId()); } - @Test - public void testRelativeLocatorFromNamingContainer() { - EditableTablePage page = tablePage.goHome(); - AdfTable table = page.findTable(); - AdfDynamicDeclarativeComponent namingContainer = table.findAdfComponentByLocator(":dmoTpl:gTools:glryFind"); - AdfInputText target = namingContainer.findAdfComponentByLocator("findIt"); - assertEquals("dmoTpl:gTools:glryFind:findIt", target.getAbsoluteLocator()); - assertEquals("dmoTpl:gTools:glryFind:findIt", target.getClientId()); - } +// @Test +// public void testRelativeLocatorFromNamingContainer() { +// EditableTablePage page = tablePage.goHome(); +// AdfTable table = page.findTable(); +// AdfDynamicDeclarativeComponent namingContainer = table.findAdfComponentByLocator(":dmoTpl:gTools:glryFind"); +// AdfInputText target = namingContainer.findAdfComponentByLocator("findIt"); +// assertEquals("dmoTpl:gTools:glryFind:findIt", target.getAbsoluteLocator()); +// assertEquals("dmoTpl:gTools:glryFind:findIt", target.getClientId()); +// } @Test public void testRelativeDifferentIndexLocator() { @@ -99,25 +96,25 @@ public void testNonExistingChild() { assertNull(table.findAdfComponent("foo")); } - @Test - public void testDeclarativeComponentLocator() { - DeclarativeComponentPage page = declCompPage.goHome(); - AdfDynamicDeclarativeComponent declComp = page.findDeclarativeComponent(); - AdfOutputText target = declComp.findAdfComponentByLocator("dcot1"); - assertEquals("dmoTpl:lwdc:dcot1", target.getAbsoluteLocator()); - assertEquals("dmoTpl:lwdc:dcot1", target.getClientId()); - // af:ierator does not exist at client, so simple iter:0:item and not iter[0]:item - AdfInputText it0 = declComp.findAdfComponentByLocator("dci1:0:itemsText"); - assertEquals("dmoTpl:lwdc:dci1:0:itemsText", it0.getAbsoluteLocator()); - assertEquals("dmoTpl:lwdc:dci1:0:itemsText", it0.getClientId()); - AdfInputText it2 = declComp.findAdfComponentByLocator("dci1:2:itemsText"); - assertEquals("dmoTpl:lwdc:dci1:2:itemsText", it2.getAbsoluteLocator()); - assertEquals("dmoTpl:lwdc:dci1:2:itemsText", it2.getClientId()); - // facet content - AdfInputText fit = declComp.findAdfComponentByLocator("facetInputText"); - assertEquals("dmoTpl:lwdc:facetInputText", fit.getAbsoluteLocator()); - assertEquals("dmoTpl:lwdc:facetInputText", fit.getClientId()); - } +// @Test +// public void testDeclarativeComponentLocator() { +// DeclarativeComponentPage page = declCompPage.goHome(); +// AdfDynamicDeclarativeComponent declComp = page.findDeclarativeComponent(); +// AdfOutputText target = declComp.findAdfComponentByLocator("dcot1"); +// assertEquals("dmoTpl:lwdc:dcot1", target.getAbsoluteLocator()); +// assertEquals("dmoTpl:lwdc:dcot1", target.getClientId()); +// // af:ierator does not exist at client, so simple iter:0:item and not iter[0]:item +// AdfInputText it0 = declComp.findAdfComponentByLocator("dci1:0:itemsText"); +// assertEquals("dmoTpl:lwdc:dci1:0:itemsText", it0.getAbsoluteLocator()); +// assertEquals("dmoTpl:lwdc:dci1:0:itemsText", it0.getClientId()); +// AdfInputText it2 = declComp.findAdfComponentByLocator("dci1:2:itemsText"); +// assertEquals("dmoTpl:lwdc:dci1:2:itemsText", it2.getAbsoluteLocator()); +// assertEquals("dmoTpl:lwdc:dci1:2:itemsText", it2.getClientId()); +// // facet content +// AdfInputText fit = declComp.findAdfComponentByLocator("facetInputText"); +// assertEquals("dmoTpl:lwdc:facetInputText", fit.getAbsoluteLocator()); +// assertEquals("dmoTpl:lwdc:facetInputText", fit.getClientId()); +// } public static void main(String[] args) { String[] args2 = { LocatorTest.class.getName() }; 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/components/SelectManyChoiceTest.java b/RichClientDemoTest/src/com/redheap/selenium/components/SelectManyChoiceTest.java index d60ddf8..7aaa540 100644 --- a/RichClientDemoTest/src/com/redheap/selenium/components/SelectManyChoiceTest.java +++ b/RichClientDemoTest/src/com/redheap/selenium/components/SelectManyChoiceTest.java @@ -9,7 +9,7 @@ import java.io.File; -import java.util.ArrayList; +import java.util.List; import static org.junit.Assert.*; import org.junit.ClassRule; @@ -33,26 +33,54 @@ public class SelectManyChoiceTest { "http://localhost:7101/adf-richclient-demo/faces/components/selectManyChoice.jspx"; @Test - public void testItemLabels() { + public void testItems() { AdfSelectManyChoice choice = pages.goHome().findDrinksSelectManyChoice(); assertEquals("coffee", choice.getItemLabel(0)); + assertEquals("0", choice.getItemValue(0)); + assertEquals(0, choice.getItemIndexByLabel("coffee")); assertEquals("tea", choice.getItemLabel(1)); - // item 2 is rendered=false - assertEquals("fizz", choice.getItemLabel(3)); - // item 4 is rendered=false - assertEquals("beer", choice.getItemLabel(5)); - assertEquals("lemonade", choice.getItemLabel(6)); + assertEquals("1", choice.getItemValue(1)); + assertEquals(1, choice.getItemIndexByLabel("tea")); + // milk (value "2") is rendered=false + assertEquals("fizz", choice.getItemLabel(2)); + assertEquals("3", choice.getItemValue(2)); + assertEquals(2, choice.getItemIndexByLabel("fizz")); + // item "4" is rendered=false + assertEquals("beer", choice.getItemLabel(3)); + assertEquals("5", choice.getItemValue(3)); + assertEquals(3, choice.getItemIndexByLabel("beer")); + assertEquals("lemonade", choice.getItemLabel(4)); + assertEquals("6", choice.getItemValue(4)); + assertEquals(4, choice.getItemIndexByLabel("lemonade")); } @Test public void testSetValue() { AdfSelectManyChoice choice = pages.goHome().findDrinksSelectManyChoice(); - choice.clickItemsByIndices(new int[] { 1, 3 }); - choice.click(); - ArrayList clickedItems = (ArrayList) choice.getValue(); - assertEquals(2, clickedItems.size()); - assertEquals("1", clickedItems.get(0)); - assertEquals("3", clickedItems.get(1)); + choice.clickItemsByIndices(1, 3, 4); // idx=3 is disabled so should not work + assertEquals( "tea; lemonade", choice.getContent()); + // selected values + List selectedValues = choice.getValue(); + assertEquals(2, selectedValues.size()); + assertEquals("1", selectedValues.get(0)); + assertEquals("6", selectedValues.get(1)); + // selected indices + long[] selectedIndices = choice.getValueIndices(); + assertEquals(2, selectedIndices.length); + assertEquals(1, selectedIndices[0]); + assertEquals(4, selectedIndices[1]); + List selectedLabels = choice.getValueLabels(); + assertEquals(2, selectedLabels.size()); + assertEquals("tea", selectedLabels.get(0)); + assertEquals("lemonade", selectedLabels.get(1)); + choice.clickItemsByLabels("fizz", "item6"); + assertEquals("tea; fizz; lemonade; item6", choice.getContent()); + selectedLabels = choice.getValueLabels(); + assertEquals(4, selectedLabels.size()); + assertEquals("tea", selectedLabels.get(0)); + assertEquals("fizz", selectedLabels.get(1)); + assertEquals("lemonade", selectedLabels.get(2)); + assertEquals("item6", selectedLabels.get(3)); } public static void main(String[] args) { 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); + } + +} diff --git a/SeleniumTools/src/com/redheap/selenium/component/AdfSelectManyChoice.java b/SeleniumTools/src/com/redheap/selenium/component/AdfSelectManyChoice.java index 0bf8b3a..2603a5c 100644 --- a/SeleniumTools/src/com/redheap/selenium/component/AdfSelectManyChoice.java +++ b/SeleniumTools/src/com/redheap/selenium/component/AdfSelectManyChoice.java @@ -2,68 +2,101 @@ import com.redheap.selenium.component.uix.UixValue; -import org.openqa.selenium.Keys; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; public class AdfSelectManyChoice extends UixValue { // see http://jdevadf.oracle.com/adf-richclient-demo/docs/js-subids.html - private static final String SUBID_content = "content"; // element + private static final String SUBID_drop = "drop"; // element to expand + private static final String SUBID_item = "item"; // item[99] element private static final String SUBID_label = "label"; //