Skip to content

Commit 1e1b66a

Browse files
authored
Merge pull request #2225 from leancodepl/fix-ios-simulator-build
Fix ios simulator build
2 parents 3047159 + 41b8596 commit 1e1b66a

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
import 'dart:io' as io;
2+
13
import 'common.dart';
24

35
void main() {
46
patrol('change volume', ($) async {
57
await createApp($);
68

7-
await $.pumpAndSettle();
8-
await $.native.pressVolumeUp();
9-
await $.pumpAndSettle();
10-
await $.native.pressVolumeDown();
11-
await $.pumpAndSettle();
12-
await $.native.pressVolumeUp();
13-
await $.pumpAndSettle();
9+
if (io.Platform.isAndroid) {
10+
await $.pumpAndSettle();
11+
await $.native.pressVolumeUp();
12+
await $.pumpAndSettle();
13+
await $.native.pressVolumeDown();
14+
await $.pumpAndSettle();
15+
await $.native.pressVolumeUp();
16+
await $.pumpAndSettle();
17+
}
1418
});
1519
}

dev/e2e_app/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import FlutterMacOS
66
import Foundation
7+
78
import app_links
89
import flutter_local_notifications
910
import flutter_timezone
@@ -12,8 +13,7 @@ import patrol
1213

1314
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
1415
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
15-
FlutterLocalNotificationsPlugin.register(
16-
with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
16+
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
1717
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
1818
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
1919
PatrolPlugin.register(with: registry.registrar(forPlugin: "PatrolPlugin"))

packages/patrol/darwin/Classes/AutomatorServer/Automator/IOSAutomator.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,19 @@
362362

363363
// MARK: Volume settings
364364
func pressVolumeUp() throws {
365-
try runVolumeAction("pressing volume up") {
365+
#if targetEnvironment(simulator)
366+
throw PatrolError.methodNotAvailable("pressVolumeUp", "simulator")
367+
#else
366368
self.device.press(XCUIDevice.Button.volumeUp)
367-
}
369+
#endif
368370
}
369371

370372
func pressVolumeDown() throws {
371-
try runVolumeAction("pressing volume down") {
373+
#if targetEnvironment(simulator)
374+
throw PatrolError.methodNotAvailable("pressVolumeDown", "simulator")
375+
#else
372376
self.device.press(XCUIDevice.Button.volumeDown)
373-
}
377+
#endif
374378
}
375379

376380
// MARK: Services
@@ -999,16 +1003,6 @@
9991003
}
10001004
}
10011005

1002-
private func runVolumeAction(_ log: String, block: @escaping () -> Void) throws {
1003-
#if targetEnvironment(simulator)
1004-
throw PatrolError.internal("Volume buttons are not available on Simulator")
1005-
#endif
1006-
1007-
runAction(log) {
1008-
block()
1009-
}
1010-
}
1011-
10121006
private func runAction<T>(_ log: String, block: @escaping () throws -> T) rethrows -> T {
10131007
return try DispatchQueue.main.sync {
10141008
Logger.shared.i("\(log)...")

packages/patrol/darwin/Classes/AutomatorServer/Errors.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ enum PatrolError: Error {
22
case viewNotExists(_ elementDescription: String)
33
case appNotInstalled(_ bundleId: String)
44
case methodNotImplemented(_ methodName: String)
5+
case methodNotAvailable(_ methodName: String, _ deviceType: String)
56
case `internal`(_ message: String)
67
case unknown(_ error: Error)
78
}
@@ -15,6 +16,8 @@ extension PatrolError: CustomStringConvertible {
1516
return "app \(format: bundleId) is not installed"
1617
case .methodNotImplemented(let methodName):
1718
return "method \(methodName)() is not implemented on iOS"
19+
case .methodNotAvailable(let methodName, let deviceType):
20+
return "method \(methodName)() is not available on \(deviceType)"
1821
case .internal(let message):
1922
return message
2023
case .unknown(let err):

0 commit comments

Comments
 (0)