-
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.
* Change to next version. Add develop branch to github actions (#8) * Add playwright 1.19.0 (#9) * Added ability to define custom field locators (#12) * Add ability to call a method automatically after creation of page object (#13) * Prepare v1.1 release * Update readme with new afterCreate functionality
- Loading branch information
Showing
9 changed files
with
95 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.uchagani.stagehand; | ||
|
||
public interface AfterCreate { | ||
void afterCreate(); | ||
} |
31 changes: 2 additions & 29 deletions
31
src/main/java/io/github/uchagani/stagehand/FieldDecorator.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 |
---|---|---|
@@ -1,34 +1,7 @@ | ||
package io.github.uchagani.stagehand; | ||
|
||
import com.microsoft.playwright.Locator; | ||
import com.microsoft.playwright.Page; | ||
import io.github.uchagani.stagehand.annotations.Find; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Proxy; | ||
|
||
public class FieldDecorator { | ||
Page page; | ||
LocatorFactory locatorFactory; | ||
|
||
public FieldDecorator(Page page) { | ||
this.page = page; | ||
this.locatorFactory = new LocatorFactory(page); | ||
} | ||
|
||
public Object decorate(Field field, Object pageObjectInstance) { | ||
Locator locator = locatorFactory.createLocator(field, pageObjectInstance); | ||
ClassLoader loader = pageObjectInstance.getClass().getClassLoader(); | ||
return proxyForLocator(loader, locator); | ||
} | ||
|
||
protected Locator proxyForLocator(ClassLoader loader, Locator locator) { | ||
InvocationHandler handler = new LocatorHandler(locator); | ||
|
||
Locator proxy; | ||
proxy = (Locator) Proxy.newProxyInstance( | ||
loader, new Class[]{Locator.class}, handler); | ||
return proxy; | ||
} | ||
public interface FieldDecorator { | ||
Object decorate(Field field, Object pageObjectInstance); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/io/github/uchagani/stagehand/LocatorFieldDecorator.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,34 @@ | ||
package io.github.uchagani.stagehand; | ||
|
||
import com.microsoft.playwright.Locator; | ||
import com.microsoft.playwright.Page; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Proxy; | ||
|
||
public class LocatorFieldDecorator implements FieldDecorator { | ||
Page page; | ||
LocatorFactory locatorFactory; | ||
|
||
public LocatorFieldDecorator(Page page) { | ||
this.page = page; | ||
this.locatorFactory = new LocatorFactory(page); | ||
} | ||
|
||
@Override | ||
public Object decorate(Field field, Object pageObjectInstance) { | ||
Locator locator = locatorFactory.createLocator(field, pageObjectInstance); | ||
ClassLoader loader = pageObjectInstance.getClass().getClassLoader(); | ||
return proxyForLocator(loader, locator); | ||
} | ||
|
||
protected Locator proxyForLocator(ClassLoader loader, Locator locator) { | ||
InvocationHandler handler = new LocatorHandler(locator); | ||
|
||
Locator proxy; | ||
proxy = (Locator) Proxy.newProxyInstance( | ||
loader, new Class[]{Locator.class}, handler); | ||
return proxy; | ||
} | ||
} |
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
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