|
42 | 42 | @AllArgsConstructor(access = AccessLevel.PRIVATE)
|
43 | 43 | public class PageFragmentProxyHandler implements InvocationHandler {
|
44 | 44 |
|
45 |
| - public static PageFragmentProxyHandler fromModel(PageFragmentModel model) { |
46 |
| - |
47 |
| - Browser browser = model.getBrowser(); |
48 |
| - Class<? extends PageFragment> pageFragmentClass = model.getType(); |
49 |
| - MappingValidator validator = new MappingValidatorImpl(pageFragmentClass); |
50 |
| - Supplier<WebElement> webElementSupplier = () -> { |
51 |
| - SearchContext searchContext = model.getSearchContextSupplier().get(); |
52 |
| - By by = model.getBy(); |
53 |
| - return searchContext.findElement(by); |
54 |
| - }; |
55 |
| - EventProducingImplementationDecorator eventDecorator = |
56 |
| - new EventProducingImplementationDecorator(browser, webElementSupplier); |
57 |
| - |
58 |
| - return PageFragmentProxyHandler.builder() |
59 |
| - .browser(browser) |
60 |
| - .pageFragmentClass(pageFragmentClass) |
61 |
| - .validator(validator) |
62 |
| - .webElementSupplier(webElementSupplier) |
63 |
| - .searchContextSupplier(webElementSupplier::get) |
64 |
| - .name(Optional.ofNullable(model.getName())) |
65 |
| - .eventDecorator(eventDecorator) |
66 |
| - .build() |
67 |
| - .addBeforeOperations() |
68 |
| - .addImplementations(); |
69 |
| - |
70 |
| - } |
71 |
| - |
72 |
| - public static PageFragmentProxyHandler forWebElement(Browser browser, WebElement webElement, |
73 |
| - Class<? extends PageFragment> pageFragmentClass) { |
74 |
| - |
75 |
| - MappingValidator validator = new MappingValidatorImpl(pageFragmentClass); |
76 |
| - Supplier<WebElement> webElementSupplier = () -> webElement; |
77 |
| - EventProducingImplementationDecorator eventDecorator = |
78 |
| - new EventProducingImplementationDecorator(browser, webElementSupplier); |
79 |
| - |
80 |
| - return PageFragmentProxyHandler.builder() |
81 |
| - .browser(browser) |
82 |
| - .pageFragmentClass(pageFragmentClass) |
83 |
| - .validator(validator) |
84 |
| - .webElementSupplier(webElementSupplier) |
85 |
| - .searchContextSupplier(webElementSupplier::get) |
86 |
| - .name(Optional.empty()) |
87 |
| - .eventDecorator(eventDecorator) |
88 |
| - .build() |
89 |
| - .addBeforeOperations() |
90 |
| - .addImplementations(); |
91 |
| - |
92 |
| - } |
93 |
| - |
94 | 45 | private final Browser browser;
|
95 | 46 | private final Class<? extends PageFragment> pageFragmentClass;
|
96 | 47 | private final MappingValidator validator;
|
@@ -148,4 +99,53 @@ private Implementation findImplementation(Method method) {
|
148 | 99 | .orElseThrow(() -> new IllegalStateException("No implementation found for: " + method));
|
149 | 100 | }
|
150 | 101 |
|
| 102 | + public static PageFragmentProxyHandler fromModel(PageFragmentModel model) { |
| 103 | + |
| 104 | + Browser browser = model.getBrowser(); |
| 105 | + Class<? extends PageFragment> pageFragmentClass = model.getType(); |
| 106 | + MappingValidator validator = new MappingValidatorImpl(pageFragmentClass); |
| 107 | + Supplier<WebElement> webElementSupplier = () -> { |
| 108 | + SearchContext searchContext = model.getSearchContextSupplier().get(); |
| 109 | + By by = model.getBy(); |
| 110 | + return searchContext.findElement(by); |
| 111 | + }; |
| 112 | + EventProducingImplementationDecorator eventDecorator = |
| 113 | + new EventProducingImplementationDecorator(browser, webElementSupplier); |
| 114 | + |
| 115 | + return PageFragmentProxyHandler.builder() |
| 116 | + .browser(browser) |
| 117 | + .pageFragmentClass(pageFragmentClass) |
| 118 | + .validator(validator) |
| 119 | + .webElementSupplier(webElementSupplier) |
| 120 | + .searchContextSupplier(webElementSupplier::get) |
| 121 | + .name(Optional.ofNullable(model.getName())) |
| 122 | + .eventDecorator(eventDecorator) |
| 123 | + .build() |
| 124 | + .addBeforeOperations() |
| 125 | + .addImplementations(); |
| 126 | + |
| 127 | + } |
| 128 | + |
| 129 | + public static PageFragmentProxyHandler forWebElement(Browser browser, WebElement webElement, |
| 130 | + Class<? extends PageFragment> pageFragmentClass) { |
| 131 | + |
| 132 | + MappingValidator validator = new MappingValidatorImpl(pageFragmentClass); |
| 133 | + Supplier<WebElement> webElementSupplier = () -> webElement; |
| 134 | + EventProducingImplementationDecorator eventDecorator = |
| 135 | + new EventProducingImplementationDecorator(browser, webElementSupplier); |
| 136 | + |
| 137 | + return PageFragmentProxyHandler.builder() |
| 138 | + .browser(browser) |
| 139 | + .pageFragmentClass(pageFragmentClass) |
| 140 | + .validator(validator) |
| 141 | + .webElementSupplier(webElementSupplier) |
| 142 | + .searchContextSupplier(webElementSupplier::get) |
| 143 | + .name(Optional.empty()) |
| 144 | + .eventDecorator(eventDecorator) |
| 145 | + .build() |
| 146 | + .addBeforeOperations() |
| 147 | + .addImplementations(); |
| 148 | + |
| 149 | + } |
| 150 | + |
151 | 151 | }
|
0 commit comments