diff --git a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/loader/decorator/HtmlElementDecorator.java b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/loader/decorator/HtmlElementDecorator.java
index 3d44bbc5..f51216bf 100644
--- a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/loader/decorator/HtmlElementDecorator.java
+++ b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/loader/decorator/HtmlElementDecorator.java
@@ -50,26 +50,29 @@ public HtmlElementDecorator(CustomElementLocatorFactory factory) {
}
public Object decorate(ClassLoader loader, Field field) {
- if (isTypifiedElement(field)) {
- return decorateTypifiedElement(loader, field);
+ try {
+ if (isTypifiedElement(field)) {
+ return decorateTypifiedElement(loader, field);
+ }
+ if (isHtmlElement(field)) {
+ return decorateHtmlElement(loader, field);
+ }
+ if (isWebElement(field) && !field.getName().equals("wrappedElement")) {
+ return decorateWebElement(loader, field);
+ }
+ if (isTypifiedElementList(field)) {
+ return decorateTypifiedElementList(loader, field);
+ }
+ if (isHtmlElementList(field)) {
+ return decorateHtmlElementList(loader, field);
+ }
+ if (isWebElementList(field)) {
+ return decorateWebElementList(loader, field);
+ }
+ return null;
+ } catch (ClassCastException ignore) {
+ return null; // See bug #94 and NonElementFieldsTest
}
- if (isHtmlElement(field)) {
- return decorateHtmlElement(loader, field);
- }
- if (isWebElement(field) && !field.getName().equals("wrappedElement")) {
- return decorateWebElement(loader, field);
- }
- if (isTypifiedElementList(field)) {
- return decorateTypifiedElementList(loader, field);
- }
- if (isHtmlElementList(field)) {
- return decorateHtmlElementList(loader, field);
- }
- if (isWebElementList(field)) {
- return decorateWebElementList(loader, field);
- }
-
- return null;
}
protected T decorateTypifiedElement(ClassLoader loader, Field field) {
diff --git a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/NonElementFieldsTest.java b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/NonElementFieldsTest.java
new file mode 100644
index 00000000..bec36d0c
--- /dev/null
+++ b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/NonElementFieldsTest.java
@@ -0,0 +1,29 @@
+package ru.yandex.qatools.htmlelements;
+
+import org.junit.Test;
+import ru.yandex.qatools.htmlelements.testpages.NonElementFieldsPage;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.emptyCollectionOf;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Graham Russell graham@ham1.co.uk
+ * Date: 24.10.2015
+ */
+public class NonElementFieldsTest {
+
+ @Test
+ public void nonElementPrivateFieldsShouldNotBeDecoratedAsElements() {
+
+ NonElementFieldsPage page = new NonElementFieldsPage();
+
+ assertThat("Non-WebElement/HtmlElement fields are not touched",
+ page.rowsCache, is(nullValue()));
+ assertThat("Non-WebElement/HtmlElement fields are not touched",
+ page.rowsAsStringCache, is(nullValue()));
+ assertThat("Non-WebElement/HtmlElement fields are not touched",
+ page.otherCache, is(emptyCollectionOf(String.class)));
+ }
+}
diff --git a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/NonElementFieldsPage.java b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/NonElementFieldsPage.java
new file mode 100644
index 00000000..ee7e1f24
--- /dev/null
+++ b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/NonElementFieldsPage.java
@@ -0,0 +1,34 @@
+package ru.yandex.qatools.htmlelements.testpages;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * @author Graham Russell graham@ham1.co.uk
+ * Date: 24.10.2015
+ */
+public class NonElementFieldsPage {
+
+ // public for ease of assertion in test
+ public List> rowsCache;
+ public List> rowsAsStringCache;
+ public List otherCache = new ArrayList<>();
+
+ public NonElementFieldsPage() {
+ this(mockDriver());
+ }
+
+ public NonElementFieldsPage(WebDriver driver) {
+ HtmlElementLoader.populatePageObject(this, driver);
+ }
+
+ public static WebDriver mockDriver() {
+ return mock(WebDriver.class);
+ }
+}