1
1
package io .appium .java_client .android ;
2
2
3
- import io .appium .java_client .functions .AppiumFunction ;
4
- import io .appium .java_client .functions .ExpectedCondition ;
5
3
import org .junit .jupiter .api .BeforeAll ;
6
4
import org .junit .jupiter .api .BeforeEach ;
7
5
import org .junit .jupiter .api .Test ;
8
6
import org .openqa .selenium .By ;
9
7
import org .openqa .selenium .TimeoutException ;
10
8
import org .openqa .selenium .WebDriver ;
11
9
import org .openqa .selenium .WebElement ;
10
+ import org .openqa .selenium .support .ui .ExpectedCondition ;
12
11
import org .openqa .selenium .support .ui .FluentWait ;
13
12
import org .openqa .selenium .support .ui .Wait ;
14
13
15
14
import java .util .ArrayList ;
16
15
import java .util .List ;
17
16
import java .util .Set ;
17
+ import java .util .function .Function ;
18
18
import java .util .regex .Matcher ;
19
19
import java .util .regex .Pattern ;
20
20
27
27
28
28
public class AndroidFunctionTest extends BaseAndroidTest {
29
29
30
- private final AppiumFunction <WebDriver , List <WebElement >> searchingFunction = input -> {
30
+ private final Function <WebDriver , List <WebElement >> searchingFunction = input -> {
31
31
List <WebElement > result = input .findElements (By .tagName ("a" ));
32
32
33
- if (result .size () > 0 ) {
34
- return result ;
35
- }
36
- return null ;
33
+ return result .isEmpty () ? null : result ;
37
34
};
38
35
39
- private final AppiumFunction <Pattern , WebDriver > contextFunction = input -> {
36
+ private final Function <Pattern , WebDriver > contextFunction = input -> {
40
37
Set <String > contexts = driver .getContextHandles ();
41
38
String current = driver .getContext ();
42
39
contexts .forEach (context -> {
@@ -51,18 +48,15 @@ public class AndroidFunctionTest extends BaseAndroidTest {
51
48
return null ;
52
49
};
53
50
54
- private final AppiumFunction <List <WebElement >, List <WebElement >> filteringFunction = input -> {
51
+ private final Function <List <WebElement >, List <WebElement >> filteringFunction = input -> {
55
52
final List <WebElement > result = new ArrayList <>();
56
53
input .forEach (element -> {
57
54
if (element .getText ().equals ("Hello World! - 1" )) {
58
55
result .add (element );
59
56
}
60
57
});
61
58
62
- if (result .size () > 0 ) {
63
- return result ;
64
- }
65
- return null ;
59
+ return result .isEmpty () ? null : result ;
66
60
};
67
61
68
62
@ BeforeAll
@@ -80,8 +74,7 @@ public void setUp() {
80
74
81
75
@ Test
82
76
public void complexWaitingTestWithPreCondition () {
83
- AppiumFunction <Pattern , List <WebElement >> compositeFunction =
84
- searchingFunction .compose (contextFunction );
77
+ Function <Pattern , List <WebElement >> compositeFunction = searchingFunction .compose (contextFunction );
85
78
86
79
Wait <Pattern > wait = new FluentWait <>(Pattern .compile ("WEBVIEW" ))
87
80
.withTimeout (ofSeconds (30 ));
@@ -94,23 +87,23 @@ public void complexWaitingTestWithPreCondition() {
94
87
@ Test public void complexWaitingTestWithPostConditions () {
95
88
final List <Boolean > calls = new ArrayList <>();
96
89
97
- AppiumFunction <Pattern , WebDriver > waitingForContext = input -> {
90
+ Function <Pattern , WebDriver > waitingForContext = input -> {
98
91
WebDriver result = contextFunction .apply (input );
99
92
if (result != null ) {
100
93
calls .add (true );
101
94
}
102
95
return result ;
103
96
};
104
97
105
- AppiumFunction <Pattern , List <WebElement >> compositeFunction = waitingForContext
98
+ Function <Pattern , List <WebElement >> compositeFunction = waitingForContext
106
99
.andThen ((ExpectedCondition <List <WebElement >>) input -> {
107
100
List <WebElement > result = searchingFunction .apply (input );
108
101
if (result != null ) {
109
102
calls .add (true );
110
103
}
111
104
return result ;
112
105
})
113
- .andThen (( AppiumFunction < List < WebElement >, List < WebElement >>) input -> {
106
+ .andThen (input -> {
114
107
List <WebElement > result = filteringFunction .apply (input );
115
108
if (result != null ) {
116
109
calls .add (true );
0 commit comments