From 093bf34f9cef4c57c081de612949825b0c794d60 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 11 Jan 2013 18:11:28 +0800 Subject: [PATCH] IDEMPIERE-92 Implement Selenium testing framework. Added _zk_locator dom attribute to further ease the use of zk selector for the writing of selenium script. Fixed issue with id after a component have change parent. --- .../adempiere/webui/UiLifeCycleListener.java | 72 +++++++++++++++++++ .../adempiere/webui/adwindow/ADTabpanel.java | 3 +- org.adempiere.ui.zk/WEB-INF/zk-selenium.xml | 4 ++ .../src/fitlibrary/zk/ZkFixture.java | 5 ++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/UiLifeCycleListener.java diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/UiLifeCycleListener.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/UiLifeCycleListener.java new file mode 100644 index 0000000000..3fccc337d3 --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/UiLifeCycleListener.java @@ -0,0 +1,72 @@ +/****************************************************************************** + * Copyright (C) 2013 Heng Sin Low * + * Copyright (C) 2013 Trek Global * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.webui; + +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.Desktop; +import org.zkoss.zk.ui.Page; +import org.zkoss.zk.ui.util.UiLifeCycle; + +/** + * @author hengsin + * + */ +public class UiLifeCycleListener implements UiLifeCycle { + + /** + * + */ + public UiLifeCycleListener() { + } + + /* (non-Javadoc) + * @see org.zkoss.zk.ui.util.UiLifeCycle#afterComponentAttached(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Page) + */ + @Override + public void afterComponentAttached(Component comp, Page page) { + } + + /* (non-Javadoc) + * @see org.zkoss.zk.ui.util.UiLifeCycle#afterComponentDetached(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Page) + */ + @Override + public void afterComponentDetached(Component comp, Page prevpage) { + } + + /* (non-Javadoc) + * @see org.zkoss.zk.ui.util.UiLifeCycle#afterComponentMoved(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component) + */ + @Override + public void afterComponentMoved(Component parent, Component child, Component prevparent) { + String locator = child.getWidgetAttribute(AdempiereIdGenerator.ZK_LOCATOR_ATTRIBUTE); + if (locator != null) { + AdempiereIdGenerator.updateZkLocatorAttribute(child); + } + } + + /* (non-Javadoc) + * @see org.zkoss.zk.ui.util.UiLifeCycle#afterPageAttached(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Desktop) + */ + @Override + public void afterPageAttached(Page page, Desktop desktop) { + } + + /* (non-Javadoc) + * @see org.zkoss.zk.ui.util.UiLifeCycle#afterPageDetached(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Desktop) + */ + @Override + public void afterPageDetached(Page page, Desktop prevdesktop) { + } + +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java index 3a9155495a..7b2bcd9284 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java @@ -26,6 +26,7 @@ import java.util.Map.Entry; import java.util.logging.Level; import org.adempiere.base.Core; +import org.adempiere.webui.AdempiereIdGenerator; import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Borderlayout; @@ -247,7 +248,7 @@ DataStatusListener, IADTabpanel, IdSpace this.getChildren().clear(); - setId(gridTab.getName()); + setId(AdempiereIdGenerator.escapeId(gridTab.getName())); int AD_Tree_ID = 0; if (gridTab.isTreeTab()) diff --git a/org.adempiere.ui.zk/WEB-INF/zk-selenium.xml b/org.adempiere.ui.zk/WEB-INF/zk-selenium.xml index 06f7e9ea8f..c9df6be923 100644 --- a/org.adempiere.ui.zk/WEB-INF/zk-selenium.xml +++ b/org.adempiere.ui.zk/WEB-INF/zk-selenium.xml @@ -10,6 +10,10 @@ org.adempiere.webui.AdempiereIdGenerator + + org.adempiere.webui.UiLifeCycleListener + + org.zkoss.zk.ui.uuidRecycle.disabled 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 167074ed84..095f6b8eef 100644 --- a/org.idempiere.ui.zk.selenium/src/fitlibrary/zk/ZkFixture.java +++ b/org.idempiere.ui.zk.selenium/src/fitlibrary/zk/ZkFixture.java @@ -191,6 +191,11 @@ public class ZkFixture extends SpiderFixture { } } + public void focus(String locator) { + Widget widget = new Widget(locator); + widget.execute(webDriver, "focus()"); + } + protected String getEval(String script) { return String.valueOf(executeJavaScript("return ("+ script+");")); }