aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2013-10-31 11:56:04 +0200
committerHenri Sara <hesara@vaadin.com>2013-10-31 11:56:04 +0200
commit29ec642eb1321f58bbcfbde79c1f1362cf1e3f9b (patch)
tree3a52babe53ff073cd89a06c654f76f28aa17d71f
parenta247c5ae3172881e3639d5e0ed3588b2cf5c000e (diff)
downloadvaadin-framework-29ec642eb1321f58bbcfbde79c1f1362cf1e3f9b.tar.gz
vaadin-framework-29ec642eb1321f58bbcfbde79c1f1362cf1e3f9b.zip
Produce TB4 style selectors in debug window (#12694)
Change-Id: Ie2e5cc48c493d065221a30fa6d2058f7a61f0274
-rw-r--r--client/src/com/vaadin/client/debug/internal/SelectorPath.java69
-rw-r--r--client/src/com/vaadin/client/debug/internal/TestBenchSection.java6
-rw-r--r--client/src/com/vaadin/client/metadata/TypeDataStore.java16
3 files changed, 81 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/debug/internal/SelectorPath.java b/client/src/com/vaadin/client/debug/internal/SelectorPath.java
index d4502daeda..2ad77a246b 100644
--- a/client/src/com/vaadin/client/debug/internal/SelectorPath.java
+++ b/client/src/com/vaadin/client/debug/internal/SelectorPath.java
@@ -16,18 +16,21 @@
package com.vaadin.client.debug.internal;
+import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.FastStringSet;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.Util;
import com.vaadin.client.componentlocator.ComponentLocator;
import com.vaadin.client.componentlocator.VaadinFinderLocatorStrategy;
import com.vaadin.client.metadata.NoDataException;
import com.vaadin.client.metadata.Property;
+import com.vaadin.client.metadata.TypeDataStore;
import com.vaadin.client.ui.AbstractConnector;
import com.vaadin.client.ui.SubPartAware;
@@ -108,7 +111,8 @@ public abstract class SelectorPath {
* in a test.
*
* @param context
- * the context to use (usually "getDriver()" or a variable name)
+ * the context to use (usually a variable name) or null for
+ * default
* @return string to add in a JUnit test
*/
public abstract String getJUnitSelector(String context);
@@ -551,7 +555,10 @@ public abstract class SelectorPath {
@Override
public String getJUnitSelector(String context) {
- return context + ".findElement(By.xpath(\"" + getPath() + "\"))";
+ // use driver by default
+ String contextString = null != context ? context : "getDriver()";
+ return contextString + ".findElement(By.xpath(\"" + getPath()
+ + "\"))";
}
@Override
@@ -604,7 +611,8 @@ public abstract class SelectorPath {
@Override
public String getJUnitSelector(String context) {
- return context + ".findElement(By.id(\"" + getId() + "\"))";
+ String contextPart = null != context ? ", " + context : "";
+ return "getElementById(\"" + getId() + "\"" + contextPart + ")";
}
@Override
@@ -634,11 +642,6 @@ public abstract class SelectorPath {
protected abstract String getPath();
@Override
- public String getJUnitSelector(String context) {
- return context + ".findElement(By.vaadin(\"" + getPath() + "\"))";
- }
-
- @Override
public Element findElement() {
if (null != getParent()) {
Element parentElement = getParent().findElement();
@@ -746,6 +749,50 @@ public abstract class SelectorPath {
}
@Override
+ public String getJUnitSelector(String context) {
+ String componentClass = getComponentClass();
+ String contextPart = null != context ? ", " + context : "";
+ // TODO update after subpart API finished
+ if (null != getSubPart() || null == componentClass) {
+ return "getElementByPath(\"" + getPath() + "\"" + contextPart
+ + ")";
+ } else if (null != getWidgetCaption()) {
+ return "getElementByCaption(" + componentClass + ".class, \""
+ + getWidgetCaption() + "\"" + contextPart + ")";
+ } else if (getWidgetIndex() >= 0) {
+ return "getElementByIndex(" + componentClass + ".class, "
+ + getWidgetIndex() + contextPart + ")";
+ } else {
+ return "getElement(" + componentClass + ".class" + contextPart
+ + ")";
+ }
+ }
+
+ /**
+ * Returns the Vaadin server side component class to use for a widget
+ * class.
+ *
+ * @return fully qualified server side class name, null if unable to
+ * determine it
+ */
+ private String getComponentClass() {
+ ComponentConnector connector = Util.findPaintable(getLocator()
+ .getClient(), findElement());
+ Class<? extends ServerConnector> connectorClass = connector
+ .getClass();
+ FastStringSet identifiers = TypeDataStore.get().findIdentifiersFor(
+ connectorClass);
+ JsArrayString ids = identifiers.dump();
+ if (ids.length() == 1) {
+ return ids.get(0);
+ } else {
+ return null;
+ }
+ }
+
+ // these are used only to locate components on the client side by path
+
+ @Override
protected String getPath() {
return "/" + getWidgetClass() + getIndexString(false)
+ getSubPartPostfix();
@@ -800,6 +847,12 @@ public abstract class SelectorPath {
this.path = path;
}
+ @Override
+ public String getJUnitSelector(String context) {
+ String contextPart = null != context ? ", " + context : "";
+ return "getElementByPath(\"" + getPath() + "\"" + contextPart + ")";
+ }
+
/**
* Returns the By.vaadin(...) path relative to the parent element.
*
diff --git a/client/src/com/vaadin/client/debug/internal/TestBenchSection.java b/client/src/com/vaadin/client/debug/internal/TestBenchSection.java
index efab5ac11f..462309768f 100644
--- a/client/src/com/vaadin/client/debug/internal/TestBenchSection.java
+++ b/client/src/com/vaadin/client/debug/internal/TestBenchSection.java
@@ -67,7 +67,7 @@ public class TestBenchSection implements Section {
this.parent = parent;
String parentString = (parent != null) ? ("element" + parent.selectorIndex)
- : "getDriver()";
+ : null;
String html = "<div class=\""
+ VDebugWindow.STYLENAME
+ "-selector\"><span class=\"tb-selector\">"
@@ -215,7 +215,9 @@ public class TestBenchSection implements Section {
SelectorPath path = SelectorPath.findTestBenchSelector(connector,
element);
- addSelectorWidgets(path);
+ if (null != path) {
+ addSelectorWidgets(path);
+ }
}
private SelectorWidget addSelectorWidgets(SelectorPath path) {
diff --git a/client/src/com/vaadin/client/metadata/TypeDataStore.java b/client/src/com/vaadin/client/metadata/TypeDataStore.java
index aa37d75dc8..649f018f95 100644
--- a/client/src/com/vaadin/client/metadata/TypeDataStore.java
+++ b/client/src/com/vaadin/client/metadata/TypeDataStore.java
@@ -69,6 +69,22 @@ public class TypeDataStore {
return class1;
}
+ // this is a very inefficient implementation for getting all the identifiers
+ // for a class
+ public FastStringSet findIdentifiersFor(Class<?> type) {
+ FastStringSet result = FastStringSet.create();
+
+ JsArrayString keys = identifiers.getKeys();
+ for (int i = 0; i < keys.length(); i++) {
+ String key = keys.get(i);
+ if (identifiers.get(key) == type) {
+ result.add(key);
+ }
+ }
+
+ return result;
+ }
+
public static Type getType(Class<?> clazz) {
return new Type(clazz);
}