2
2
3
3
import io .appium .java_client .AppiumBy ;
4
4
import io .appium .java_client .android .options .UiAutomator2Options ;
5
+ import io .appium .java_client .flutter .FlutterDriverOptions ;
6
+ import io .appium .java_client .flutter .FlutterIntegrationTestDriver ;
5
7
import io .appium .java_client .flutter .android .FlutterAndroidDriver ;
6
8
import io .appium .java_client .flutter .commands .ScrollParameter ;
7
- import io .appium .java_client .remote .AutomationName ;
9
+ import io .appium .java_client .flutter .ios .FlutterIOSDriver ;
10
+ import io .appium .java_client .ios .options .XCUITestOptions ;
8
11
import io .appium .java_client .service .local .AppiumDriverLocalService ;
9
12
import io .appium .java_client .service .local .AppiumServiceBuilder ;
10
13
import org .junit .jupiter .api .AfterAll ;
11
14
import org .junit .jupiter .api .AfterEach ;
12
15
import org .junit .jupiter .api .BeforeAll ;
13
16
import org .junit .jupiter .api .BeforeEach ;
14
17
import org .openqa .selenium .By ;
15
- import org .openqa .selenium .InvalidArgumentException ;
16
18
import org .openqa .selenium .WebElement ;
17
19
18
20
import java .net .MalformedURLException ;
21
+ import java .time .Duration ;
19
22
import java .util .Optional ;
20
23
21
24
class BaseFlutterTest {
@@ -29,7 +32,7 @@ class BaseFlutterTest {
29
32
protected static final int PORT = 4723 ;
30
33
31
34
private static AppiumDriverLocalService service ;
32
- protected static FlutterAndroidDriver driver ;
35
+ protected static FlutterIntegrationTestDriver driver ;
33
36
protected static final By LOGIN_BUTTON = AppiumBy .flutterText ("Login" );
34
37
35
38
/**
@@ -45,35 +48,52 @@ public static void beforeClass() {
45
48
}
46
49
47
50
@ BeforeEach
48
- public void startSession () throws MalformedURLException {
51
+ void startSession () throws MalformedURLException {
52
+ FlutterDriverOptions flutterOptions = new FlutterDriverOptions ()
53
+ .setFlutterServerLaunchTimeout (Duration .ofMinutes (2 ))
54
+ .setFlutterSystemPort (9999 )
55
+ .setFlutterElementWaitTimeout (Duration .ofSeconds (10 ));
49
56
if (IS_ANDROID ) {
50
- // TODO: update it with FlutterDriverOptions once implemented
51
- UiAutomator2Options options = new UiAutomator2Options ()
52
- .setAutomationName (AutomationName .FLUTTER_INTEGRATION )
53
- .setApp (System .getProperty ("flutterApp" ))
54
- .eventTimings ();
55
- driver = new FlutterAndroidDriver (service .getUrl (), options );
57
+ driver = new FlutterAndroidDriver (service .getUrl (), flutterOptions
58
+ .setUiAutomator2Options (new UiAutomator2Options ()
59
+ .setApp (System .getProperty ("flutterApp" ))
60
+ .eventTimings ())
61
+ );
56
62
} else {
57
- throw new InvalidArgumentException (
58
- "Currently flutter driver implementation only supports android platform" );
63
+ String deviceName = System .getenv ("IOS_DEVICE_NAME" ) != null
64
+ ? System .getenv ("IOS_DEVICE_NAME" )
65
+ : "iPhone 12" ;
66
+ String platformVersion = System .getenv ("IOS_PLATFORM_VERSION" ) != null
67
+ ? System .getenv ("IOS_PLATFORM_VERSION" )
68
+ : "14.5" ;
69
+ driver = new FlutterIOSDriver (service .getUrl (), flutterOptions
70
+ .setXCUITestOptions (new XCUITestOptions ()
71
+ .setApp (System .getProperty ("flutterApp" ))
72
+ .setDeviceName (deviceName )
73
+ .setPlatformVersion (platformVersion )
74
+ .setWdaLaunchTimeout (Duration .ofMinutes (4 ))
75
+ .setSimulatorStartupTimeout (Duration .ofMinutes (5 ))
76
+ .eventTimings ()
77
+ )
78
+ );
59
79
}
60
80
}
61
81
62
82
@ AfterEach
63
- public void stopSession () {
83
+ void stopSession () {
64
84
if (driver != null ) {
65
85
driver .quit ();
66
86
}
67
87
}
68
88
69
89
@ AfterAll
70
- public static void afterClass () {
90
+ static void afterClass () {
71
91
if (service .isRunning ()) {
72
92
service .stop ();
73
93
}
74
94
}
75
95
76
- public void openScreen (String screenTitle ) {
96
+ void openScreen (String screenTitle ) {
77
97
ScrollParameter scrollOptions = new ScrollParameter (
78
98
AppiumBy .flutterText (screenTitle ), ScrollParameter .ScrollDirection .DOWN );
79
99
WebElement element = driver .scrollTillVisible (scrollOptions );
0 commit comments