6
6
import io .appium .java_client .pagefactory_tests .widget .tests .AbstractStubWebDriver ;
7
7
import io .appium .java_client .pagefactory_tests .widget .tests .DefaultStubWidget ;
8
8
import io .appium .java_client .pagefactory_tests .widget .tests .android .DefaultAndroidWidget ;
9
+ import io .appium .java_client .proxy .Helpers ;
10
+ import org .junit .jupiter .api .RepeatedTest ;
9
11
import org .junit .jupiter .params .ParameterizedTest ;
10
12
import org .junit .jupiter .params .provider .Arguments ;
11
13
import org .junit .jupiter .params .provider .MethodSource ;
20
22
import static org .hamcrest .MatcherAssert .assertThat ;
21
23
import static org .hamcrest .Matchers .contains ;
22
24
import static org .hamcrest .Matchers .equalTo ;
25
+ import static org .hamcrest .Matchers .lessThan ;
23
26
import static org .openqa .selenium .support .PageFactory .initElements ;
24
27
25
28
@@ -33,30 +36,31 @@ public class CombinedWidgetTest {
33
36
*/
34
37
public static Stream <Arguments > data () {
35
38
return Stream .of (
36
- Arguments .of (new AppWithCombinedWidgets (),
37
- new AbstractStubWebDriver .StubAndroidDriver (), DefaultAndroidWidget .class ),
38
- Arguments .of (new AppWithCombinedWidgets (),
39
- new AbstractStubWebDriver .StubIOSXCUITDriver (), DefaultIosXCUITWidget .class ),
40
- Arguments .of (new AppWithCombinedWidgets (),
41
- new AbstractStubWebDriver .StubBrowserDriver (), DefaultFindByWidget .class ),
42
- Arguments .of (new AppWithCombinedWidgets (),
43
- new AbstractStubWebDriver .StubAndroidBrowserOrWebViewDriver (), DefaultFindByWidget .class ),
44
- Arguments .of (new AppWithPartiallyCombinedWidgets (),
45
- new AbstractStubWebDriver .StubAndroidDriver (), DefaultAndroidWidget .class ),
46
- Arguments .of (new AppWithPartiallyCombinedWidgets (),
47
- new AbstractStubWebDriver .StubIOSXCUITDriver (), DefaultStubWidget .class ),
48
- Arguments .of (new AppWithPartiallyCombinedWidgets (),
49
- new AbstractStubWebDriver .StubWindowsDriver (), DefaultStubWidget .class ),
50
- Arguments .of (new AppWithPartiallyCombinedWidgets (),
51
- new AbstractStubWebDriver .StubBrowserDriver (), DefaultFindByWidget .class ),
52
- Arguments .of (new AppWithPartiallyCombinedWidgets (),
53
- new AbstractStubWebDriver .StubAndroidBrowserOrWebViewDriver (), DefaultFindByWidget .class )
39
+ Arguments .of (new AppWithCombinedWidgets (),
40
+ new AbstractStubWebDriver .StubAndroidDriver (), DefaultAndroidWidget .class ),
41
+ Arguments .of (new AppWithCombinedWidgets (),
42
+ new AbstractStubWebDriver .StubIOSXCUITDriver (), DefaultIosXCUITWidget .class ),
43
+ Arguments .of (new AppWithCombinedWidgets (),
44
+ new AbstractStubWebDriver .StubBrowserDriver (), DefaultFindByWidget .class ),
45
+ Arguments .of (new AppWithCombinedWidgets (),
46
+ new AbstractStubWebDriver .StubAndroidBrowserOrWebViewDriver (), DefaultFindByWidget .class ),
47
+ Arguments .of (new AppWithPartiallyCombinedWidgets (),
48
+ new AbstractStubWebDriver .StubAndroidDriver (), DefaultAndroidWidget .class ),
49
+ Arguments .of (new AppWithPartiallyCombinedWidgets (),
50
+ new AbstractStubWebDriver .StubIOSXCUITDriver (), DefaultStubWidget .class ),
51
+ Arguments .of (new AppWithPartiallyCombinedWidgets (),
52
+ new AbstractStubWebDriver .StubWindowsDriver (), DefaultStubWidget .class ),
53
+ Arguments .of (new AppWithPartiallyCombinedWidgets (),
54
+ new AbstractStubWebDriver .StubBrowserDriver (), DefaultFindByWidget .class ),
55
+ Arguments .of (new AppWithPartiallyCombinedWidgets (),
56
+ new AbstractStubWebDriver .StubAndroidBrowserOrWebViewDriver (), DefaultFindByWidget .class )
54
57
);
55
58
}
56
59
57
60
@ ParameterizedTest
58
61
@ MethodSource ("data" )
59
62
void checkThatWidgetsAreCreatedCorrectly (AbstractApp app , WebDriver driver , Class <?> widgetClass ) {
63
+ assertProxyClassCacheGrowth ();
60
64
initElements (new AppiumFieldDecorator (driver ), app );
61
65
assertThat ("Expected widget class was " + widgetClass .getName (),
62
66
app .getWidget ().getSubWidget ().getSelfReference ().getClass (),
@@ -161,4 +165,22 @@ public List<PartiallyCombinedWidget> getWidgets() {
161
165
return multipleWidgets ;
162
166
}
163
167
}
168
+
169
+
170
+ /**
171
+ * Assert proxy class cache growth for this test class.
172
+ * The (@link io.appium.java_client.proxy.Helpers#CACHED_PROXY_CLASSES) should be populated during these tests.
173
+ * Prior to the Caching issue being resolved
174
+ * - the CACHED_PROXY_CLASSES would grow indefinitely, resulting in an Out Of Memory exception.
175
+ * - this ParameterizedTest would have the CACHED_PROXY_CLASSES grow to 266 entries.
176
+ */
177
+ private void assertProxyClassCacheGrowth () {
178
+ System .gc (); //Trying to force a collection for more accurate check numbers
179
+ int thresholdSize = 50 ;
180
+ assertThat (
181
+ "Proxy Class Cache threshold is " + thresholdSize ,
182
+ Helpers .getCachedProxyClassesSize (),
183
+ lessThan (thresholdSize )
184
+ );
185
+ }
164
186
}
0 commit comments