Skip to content

Commit

Permalink
Fixes #94 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ham1 authored and eroshenkoam committed Mar 12, 2018
1 parent 4de5a1f commit b05fe3f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends TypifiedElement> T decorateTypifiedElement(ClassLoader loader, Field field) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 [email protected]
* 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)));
}
}
Original file line number Diff line number Diff line change
@@ -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 [email protected]
* Date: 24.10.2015
*/
public class NonElementFieldsPage {

// public for ease of assertion in test
public List<List<WebElement>> rowsCache;
public List<List<String>> rowsAsStringCache;
public List<String> otherCache = new ArrayList<>();

public NonElementFieldsPage() {
this(mockDriver());
}

public NonElementFieldsPage(WebDriver driver) {
HtmlElementLoader.populatePageObject(this, driver);
}

public static WebDriver mockDriver() {
return mock(WebDriver.class);
}
}

0 comments on commit b05fe3f

Please sign in to comment.