-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for PageScoped.java and web component field decoration.
- Loading branch information
1 parent
9fd19e6
commit 24925c8
Showing
21 changed files
with
164 additions
and
17 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
2 changes: 1 addition & 1 deletion
2
...t/java/integration/test/pojo/Content.java → src/test/java/integration/pojo/Content.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
2 changes: 1 addition & 1 deletion
2
...java/integration/test/pojo/EmptyTest.java → ...test/java/integration/pojo/EmptyTest.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
2 changes: 1 addition & 1 deletion
2
...test/java/integration/test/pojo/Home.java → src/test/java/integration/pojo/Home.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
2 changes: 1 addition & 1 deletion
2
.../java/integration/test/pojo/HomePage.java → src/test/java/integration/pojo/HomePage.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
2 changes: 1 addition & 1 deletion
2
...test/java/integration/test/pojo/Page.java → src/test/java/integration/pojo/Page.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
2 changes: 1 addition & 1 deletion
2
src/test/java/integration/test/pojo/Row.java → src/test/java/integration/pojo/Row.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
2 changes: 1 addition & 1 deletion
2
...gration/test/springstructure/Browser.java → .../integration/springstructure/Browser.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
2 changes: 1 addition & 1 deletion
2
...gration/test/springstructure/Content.java → .../integration/springstructure/Content.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
2 changes: 1 addition & 1 deletion
2
...tructure/CucumberSpringConfiguration.java → ...tructure/CucumberSpringConfiguration.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
2 changes: 1 addition & 1 deletion
2
...ntegration/test/springstructure/Home.java → ...ava/integration/springstructure/Home.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
2 changes: 1 addition & 1 deletion
2
...ration/test/springstructure/HomePage.java → ...integration/springstructure/HomePage.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
2 changes: 1 addition & 1 deletion
2
...ntegration/test/springstructure/Page.java → ...ava/integration/springstructure/Page.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
2 changes: 1 addition & 1 deletion
2
...ngstructure/PortDestinationContainer.java → ...ngstructure/PortDestinationContainer.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
2 changes: 1 addition & 1 deletion
2
.../springstructure/PortOriginContainer.java → .../springstructure/PortOriginContainer.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
2 changes: 1 addition & 1 deletion
2
...integration/test/springstructure/Row.java → ...java/integration/springstructure/Row.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
2 changes: 1 addition & 1 deletion
2
...ture/SeleniumWebComponentApplication.java → ...ture/SeleniumWebComponentApplication.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
2 changes: 1 addition & 1 deletion
2
...test/springstructure/StepDefinitions.java → ...tion/springstructure/StepDefinitions.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
69 changes: 69 additions & 0 deletions
69
src/test/java/unit/SpringWebComponentFieldDecoratorTest.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,69 @@ | ||
package unit; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import io.github.orcunbalcilar.selenium.support.pagefactory.SpringWebComponentFieldDecorator; | ||
import io.github.orcunbalcilar.selenium.support.pagefactory.WebComponentLocatorFactory; | ||
import java.lang.reflect.Field; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.PageFactory; | ||
|
||
public class SpringWebComponentFieldDecoratorTest { | ||
|
||
@Test | ||
public void testDecorate_WebComponentField() throws Exception { | ||
WebDriver driver = mock(WebDriver.class); | ||
|
||
WebElement mockParentElement = mock(WebElement.class); | ||
when(driver.findElement(By.cssSelector(".test-web-component"))).thenReturn(mockParentElement); | ||
|
||
WebElement mockTestElement = mock(WebElement.class); | ||
when(mockParentElement.findElement(By.id("test"))).thenReturn(mockTestElement); | ||
|
||
SpringWebComponentFieldDecorator decorator = | ||
new SpringWebComponentFieldDecorator(driver, new WebComponentLocatorFactory(driver, 5)); | ||
TestPage testPage = new TestPage(); | ||
PageFactory.initElements(decorator, testPage); | ||
|
||
// Reaching testElement from TestWebComponent | ||
Field webComponent = testPage.getClass().getDeclaredField("webComponent"); | ||
webComponent.setAccessible(true); | ||
TestWebComponent component = (TestWebComponent) webComponent.get(testPage); | ||
Field testElementField = component.getClass().getDeclaredField("testElement"); | ||
testElementField.setAccessible(true); | ||
WebElement testElementFromComponent = (WebElement) testElementField.get(component); | ||
|
||
assertNotNull(component); | ||
assertEquals(mockParentElement.toString(), component.getSearchContext().toString()); | ||
assertEquals(mockTestElement.toString(), testElementFromComponent.toString()); | ||
} | ||
|
||
@Test | ||
public void testDecorate_PageScopedField() throws Exception { | ||
WebDriver driver = mock(WebDriver.class); | ||
|
||
WebElement mockPageScopedElement = mock(WebElement.class); | ||
when(driver.findElement(By.id("pageScopedElement"))).thenReturn(mockPageScopedElement); | ||
|
||
SpringWebComponentFieldDecorator decorator = | ||
new SpringWebComponentFieldDecorator(driver, new WebComponentLocatorFactory(driver, 5)); | ||
TestPage testPage = new TestPage(); | ||
PageFactory.initElements(decorator, testPage); | ||
|
||
// Reaching pageScopedElement from TestWebComponent | ||
Field webComponentField = testPage.getClass().getDeclaredField("webComponent"); | ||
webComponentField.setAccessible(true); | ||
TestWebComponent webComponent = (TestWebComponent) webComponentField.get(testPage); | ||
Field pageScopedElementField = webComponent.getClass().getDeclaredField("pageScopedElement"); | ||
pageScopedElementField.setAccessible(true); | ||
|
||
WebElement pageScopedElement = (WebElement) pageScopedElementField.get(webComponent); | ||
|
||
assertNotNull(pageScopedElement); | ||
assertEquals(mockPageScopedElement.toString(), pageScopedElement.toString()); | ||
} | ||
} |
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,11 @@ | ||
package unit; | ||
|
||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
|
||
public class TestPage { | ||
private WebElement webElement; | ||
|
||
@FindBy(css = ".test-web-component") | ||
private TestWebComponent webComponent; | ||
} |
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,19 @@ | ||
package unit; | ||
|
||
import io.github.orcunbalcilar.selenium.support.pagefactory.PageScoped; | ||
import io.github.orcunbalcilar.selenium.support.pagefactory.WebComponent; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
|
||
public class TestWebComponent extends WebComponent { | ||
@FindBy(id = "test") | ||
private WebElement testElement; | ||
|
||
@PageScoped | ||
@FindBy(id = "pageScopedElement") | ||
private WebElement pageScopedElement; | ||
|
||
public TestWebComponent() { | ||
super(); | ||
} | ||
} |