changeset 94:527f9a799850

JemmyFX: WebWiew wrap
author Oleg Barbashov <oleg.barbashov@oracle.com>
date Tue, 23 Oct 2012 16:18:05 +0400
parents 49816bcead4f
children 12daa64a9797
files tools/Jemmy/JemmyFX/samples/org/jemmy/samples/webview/WebViewSample.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeWrap.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebViewWrap.java tools/Jemmy/JemmyFX/test/org/jemmy/fx/control/WebViewTest.java
diffstat 4 files changed, 60 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/webview/WebViewSample.java	Tue Oct 23 14:26:08 2012 +0400
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/webview/WebViewSample.java	Tue Oct 23 16:18:05 2012 +0400
@@ -29,6 +29,8 @@
 import org.jemmy.fx.SceneDock;
 import org.jemmy.fx.control.WebNodeDock;
 import org.jemmy.fx.control.WebViewDock;
+import org.jemmy.fx.control.WebViewWrap.ByAttribute;
+import org.jemmy.fx.control.WebViewWrap.ByName;
 import org.jemmy.lookup.LookupCriteria;
 import org.jemmy.samples.SampleBase;
 import org.junit.Before;
@@ -60,26 +62,12 @@
         });
 
         // WebViewWrap as parent for org.w3c.dom.Node
-        WebNodeDock body = new WebNodeDock(web_view.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
-            public boolean check(org.w3c.dom.Node cntrl) {
-                // looking for HTML's body
-                if (cntrl.getNodeName().equals("BODY")) {
-                    return true;
-                }
-                return false;
-            }
-        });
+        // ByName() lookup criteria
+        WebNodeDock body = new WebNodeDock(web_view.asWebNodeParent(), new ByName("BODY"));
 
         // WebNodeWrap as parent for org.w3c.dom.Node
-        WebNodeDock button = new WebNodeDock(body.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
-            public boolean check(org.w3c.dom.Node cntrl) {
-                // looking for button
-                if (cntrl.getNodeName().equals("BUTTON")) {
-                    return true;
-                }
-                return false;
-            }
-        });
+        // ByAttribute() lookup criteria
+        WebNodeDock button = new WebNodeDock(body.asWebNodeParent(), new ByAttribute("type", "button"));
 
         button.wrap().mouse().click();
     }
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeWrap.java	Tue Oct 23 14:26:08 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeWrap.java	Tue Oct 23 16:18:05 2012 +0400
@@ -31,6 +31,7 @@
 import org.jemmy.control.As;
 import org.jemmy.control.ControlInterfaces;
 import org.jemmy.control.ControlType;
+import org.jemmy.control.Property;
 import org.jemmy.control.Wrap;
 import org.jemmy.dock.DockInfo;
 import org.jemmy.fx.Root;
@@ -45,6 +46,8 @@
 public class WebNodeWrap<CONTROL extends org.w3c.dom.Node> extends Wrap<CONTROL>
                                                            implements Showable, Show {
 
+    public static final String WEB_NODE_PATH_PROP_NAME = "webnode.path";
+
     protected WebViewWrap<? extends WebView> view;
     protected String path = new String();
     protected JSObject bounds;
@@ -93,6 +96,14 @@
         }.dispatch(Root.ROOT.getEnvironment());
     }
 
+    @Property(WEB_NODE_PATH_PROP_NAME)
+    public String getPath() {
+        if (path.isEmpty()) {
+            getPath(getControl());
+        }
+        return path;
+    }
+
     protected void getPath(org.w3c.dom.Node node) {
         final org.w3c.dom.Node parentNode = node.getParentNode();
         if (parentNode == null) {
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebViewWrap.java	Tue Oct 23 14:26:08 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebViewWrap.java	Tue Oct 23 16:18:05 2012 +0400
@@ -33,6 +33,9 @@
 import org.jemmy.env.Timeout;
 import org.jemmy.interfaces.Parent;
 import org.jemmy.lookup.AbstractParent;
+import org.jemmy.lookup.LookupCriteria;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
 
 @ControlType({WebView.class})
 @ControlInterfaces( value = {Parent.class}, 
@@ -61,4 +64,40 @@
     public <T extends org.w3c.dom.Node> AbstractParent<T> asWebNodeParent(Class<T> type) {
         return new WebNodeParent(this, type);
     }
+
+    public static class ByName implements LookupCriteria<org.w3c.dom.Node> {
+        protected String name;
+        public ByName(String name) {
+            this.name = name;
+        }
+        public boolean check(org.w3c.dom.Node cntrl) {
+            if (cntrl.getNodeName().equals(name)) {
+                return true;
+            }
+            return false;
+        }
+    }
+
+    public static class ByAttribute implements LookupCriteria<org.w3c.dom.Node> {
+        protected String name;
+        protected String value;
+        public ByAttribute(String name, String value) {
+            this.name = name;
+            this.value = value;
+        }
+        public boolean check(org.w3c.dom.Node cntrl) {
+            final NamedNodeMap attributes = cntrl.getAttributes();
+            if (attributes == null) {
+                return false;
+            }
+            Node item = attributes.getNamedItem(name);
+            if (item == null) {
+                return false;
+            }
+            if (item.getNodeValue().equals(value)) {
+                return true;
+            }
+            return false;
+        }
+    }
 }
\ No newline at end of file
--- a/tools/Jemmy/JemmyFX/test/org/jemmy/fx/control/WebViewTest.java	Tue Oct 23 14:26:08 2012 +0400
+++ b/tools/Jemmy/JemmyFX/test/org/jemmy/fx/control/WebViewTest.java	Tue Oct 23 16:18:05 2012 +0400
@@ -27,6 +27,8 @@
 
 import javafx.scene.web.WebView;
 import org.jemmy.fx.SceneDock;
+import org.jemmy.fx.control.WebViewWrap.ByAttribute;
+import org.jemmy.fx.control.WebViewWrap.ByName;
 import org.jemmy.lookup.LookupCriteria;
 import org.jemmy.samples.SampleBase;
 import org.junit.Before;
@@ -54,23 +56,9 @@
             }
         });
 
-        WebNodeDock body = new WebNodeDock(web_view.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
-            public boolean check(org.w3c.dom.Node cntrl) {
-                if (cntrl.getNodeName().equals("BODY")) {
-                    return true;
-                }
-                return false;
-            }
-        });
+        WebNodeDock body = new WebNodeDock(web_view.asWebNodeParent(), new ByName("BODY"));
         
-        WebNodeDock button = new WebNodeDock(body.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
-            public boolean check(org.w3c.dom.Node cntrl) {
-                if (cntrl.getNodeName().equals("BUTTON")) {
-                    return true;
-                }
-                return false;
-            }
-        });
+        WebNodeDock button = new WebNodeDock(body.asWebNodeParent(), new ByAttribute("type", "button"));
 
         button.wrap().mouse().click();
     }