From 095c72be6452aabfb27ccaa147c52b3faeac2216 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 11 Jan 2013 13:24:07 +0800 Subject: [PATCH] IDEMPIERE-92 Implement Selenium testing framework. Fixed combobox issue after the 6.5.1 upgrade. --- .../MissingFieldTranslationTab/content.txt | 2 +- .../src/fitlibrary/zk/ZkFixture.java | 35 ++++++++++++++----- .../org/idempiere/ui/zk/selenium/Widget.java | 6 ++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/fitnesse/FitNesseRoot/ZkSuite/MissingFieldTranslationTab/content.txt b/fitnesse/FitNesseRoot/ZkSuite/MissingFieldTranslationTab/content.txt index 2377a3126f..096238b2ab 100644 --- a/fitnesse/FitNesseRoot/ZkSuite/MissingFieldTranslationTab/content.txt +++ b/fitnesse/FitNesseRoot/ZkSuite/MissingFieldTranslationTab/content.txt @@ -4,7 +4,7 @@ Bugs: Field translation tab not show !include -c ZkSystemAdminLogin '''Open Window, Tab & Field''' -|''combobox''|$treeSearchCombo|''select item''|!-Window, Tab & Field-!| +|''open window''|!-Window, Tab & Field-!| |''wait response''| |''click''|$findWindow_1 $simpleSearch $btnOk| diff --git a/org.idempiere.ui.zk.selenium/src/fitlibrary/zk/ZkFixture.java b/org.idempiere.ui.zk.selenium/src/fitlibrary/zk/ZkFixture.java index 8a8d1bb139..167074ed84 100644 --- a/org.idempiere.ui.zk.selenium/src/fitlibrary/zk/ZkFixture.java +++ b/org.idempiere.ui.zk.selenium/src/fitlibrary/zk/ZkFixture.java @@ -49,18 +49,26 @@ public class ZkFixture extends SpiderFixture { // --------- ComboBox --------- public String comboboxSelectedValue(String locator) { Widget widget = new Widget(locator); - return widget.$n(webDriver, "real").getAttribute("Value"); + return (String) widget.eval(webDriver, "getValue()"); } @SimpleAction(wiki = "|''combobox''|xpath, id or other locator|''select item''|label of item|", tooltip = "Changes the selected item in the given comboBox.") public boolean comboboxSelectItem(String locator, String label) { Widget widget = new Widget(locator); - widget.execute(webDriver, "setValue('"+label+"')"); - widget.execute(webDriver, "fireOnChange()"); - WebElement element = widget.$n(webDriver, "real"); - element.click(); + widget.execute(webDriver, "open()"); waitResponse(); - return label.equals(element.getAttribute("value")); + List list = webDriver.findElements(Zk.jq(locator + " @comboitem")); + if (list != null && list.size() > 0) { + for(WebElement element : list) { + if (element.getText().equals(label) || element.getText().trim().equals(label)) { + element.click(); + waitResponse(); + String selected = comboboxSelectedValue(locator); + return label.equals(selected); + } + } + } + return false; } @SimpleAction(wiki = "|''combobox''|xpath, id or other locator|''select item at''|index|", tooltip = "Changes the selected item to the nth one, in the given comboBox.") @@ -77,7 +85,18 @@ public class ZkFixture extends SpiderFixture { } return false; } - + + public boolean comboboxSetText(String locator, String text) { + Widget widget = new Widget(locator); + widget.execute(webDriver, "setValue('"+text+"', true)"); + widget.execute(webDriver, "fireOnChange()"); + WebElement element = widget.$n(webDriver, "real"); + element.click(); + waitResponse(); + + return text.equals(comboboxSelectedValue(locator)); + } + // ---- Tabbox ---- @SimpleAction(wiki = "|''tabbox''|xpath, id or other locator|''select tab at''|index|", tooltip = "Changes the selected tab to the nth one, in the given tabbox.") public void tabboxSelectTabAt(String locator, int index) { @@ -111,7 +130,7 @@ public class ZkFixture extends SpiderFixture { // ---- window ( tab ) --- @SimpleAction(wiki = "|''open window''|menu label|", tooltip = "Open window with label.") public void openWindow(String label) { - comboboxSelectItem("$treeSearchCombo", label); + comboboxSetText("$treeSearchCombo", label); } @SimpleAction(wiki = "|''window''|xpath, id or other locator|''click process button''|button id|", tooltip = "Click a window's process button.") diff --git a/org.idempiere.ui.zk.selenium/src/org/idempiere/ui/zk/selenium/Widget.java b/org.idempiere.ui.zk.selenium/src/org/idempiere/ui/zk/selenium/Widget.java index a371013547..4e84d6cf22 100644 --- a/org.idempiere.ui.zk.selenium/src/org/idempiere/ui/zk/selenium/Widget.java +++ b/org.idempiere.ui.zk.selenium/src/org/idempiere/ui/zk/selenium/Widget.java @@ -54,4 +54,10 @@ public class Widget extends By { JavascriptExecutor executor = (JavascriptExecutor) driver; return executor.executeScript("return zk('"+locator+"').$()."+command+";"); } + + public static StringBuilder getWidgetLocatorScript(String locator) { + StringBuilder builder = new StringBuilder("zk('"); + builder.append(locator).append("').$()"); + return builder; + } }