-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8: nested classes (not static) are supported now
- Loading branch information
Artem Eroshenko
committed
Jan 23, 2013
1 parent
161e157
commit e9c57a5
Showing
4 changed files
with
119 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/utils/ReflectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ru.yandex.qatools.htmlelements.utils; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Modifier; | ||
|
||
import static org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor; | ||
|
||
/** | ||
* User: eroshenkoam | ||
* Date: 1/22/13, 5:53 PM | ||
*/ | ||
public class ReflectionUtils { | ||
|
||
public static <T> T newInstance(Class<T> clazz, Object... args) throws IllegalAccessException, | ||
InstantiationException, NoSuchMethodException, InvocationTargetException { | ||
if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) { | ||
Class outerClass = clazz.getDeclaringClass(); | ||
Object outerObject = outerClass.newInstance(); | ||
return invokeConstructor(clazz, Lists.asList(outerObject, args).toArray()); | ||
} else { | ||
return invokeConstructor(clazz, args); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/NestedClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ru.yandex.qatools.htmlelements; | ||
|
||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import ru.yandex.qatools.htmlelements.annotations.Block; | ||
import ru.yandex.qatools.htmlelements.element.HtmlElement; | ||
import ru.yandex.qatools.htmlelements.element.Link; | ||
import ru.yandex.qatools.htmlelements.element.TypifiedElement; | ||
import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader; | ||
|
||
import static org.hamcrest.core.IsNull.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* User: eroshenkoam | ||
* Date: 1/22/13, 2:16 PM | ||
*/ | ||
public class NestedClassTest { | ||
|
||
public WebDriver driver = mock(WebDriver.class); | ||
WebElement arrow = mock(WebElement.class); | ||
WebElement link = mock(WebElement.class); | ||
|
||
@Before | ||
public void before() { | ||
when(driver.findElement(By.className("arrow"))).thenReturn(arrow); | ||
when(arrow.findElement(By.className("link"))).thenReturn(link); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void test() { | ||
NestedPageObject pageObject = HtmlElementLoader.create(NestedPageObject.class, driver); | ||
assertThat(pageObject, notNullValue()); | ||
assertThat(pageObject.arrow.getName(), notNullValue()); | ||
assertThat(pageObject.arrow.link.getWrappedElement(), notNullValue()); | ||
} | ||
|
||
public class NestedPageObject { | ||
@FindBy(className = "arrow") | ||
public NestedHtmlElement arrow; | ||
} | ||
|
||
public class NestedHtmlElement extends HtmlElement { | ||
@FindBy(className = "link") | ||
public NestedTypifiedElement link; | ||
|
||
} | ||
|
||
|
||
public class NestedTypifiedElement extends TypifiedElement { | ||
|
||
public NestedTypifiedElement(WebElement wrappedElement) { | ||
super(wrappedElement); | ||
} | ||
|
||
} | ||
} |