Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
piotruela committed Nov 13, 2023
1 parent 920eae4 commit 084fafc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
34 changes: 18 additions & 16 deletions packages/patrol/ios/Classes/AutomatorServer/Automator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,27 +395,27 @@
return views
}
}

func getUITreeRoots(installedApps: [String]) throws -> [NativeView] {
try runAction("getting ui tree roots") {
let foregroundApp = self.getForegroundApp(installedApps: installedApps)
let snapshot = try foregroundApp.snapshot()
return [NativeView.fromXCUIElementSnapshot(snapshot, foregroundApp.identifier)]
let foregroundApp = self.getForegroundApp(installedApps: installedApps)
let snapshot = try foregroundApp.snapshot()
return [NativeView.fromXCUIElementSnapshot(snapshot, foregroundApp.identifier)]
}
}

private func getForegroundApp(installedApps: [String]) -> XCUIApplication {
let app = XCUIApplication()
if app.state == .runningForeground {
return app
return app
} else {
for bundleIdentifier in installedApps {
let app = XCUIApplication(bundleIdentifier: bundleIdentifier)
if app.state == .runningForeground {
return app
}
for bundleIdentifier in installedApps {
let app = XCUIApplication(bundleIdentifier: bundleIdentifier)
if app.state == .runningForeground {
return app
}
return self.springboard
}
return self.springboard
}
}

Expand Down Expand Up @@ -849,12 +849,14 @@
return NativeView.fromXCUIElement(child, bundleId)
})
}

static func fromXCUIElementSnapshot(_ xcuielement: XCUIElementSnapshot, _ bundleId: String) -> NativeView {

static func fromXCUIElementSnapshot(_ xcuielement: XCUIElementSnapshot, _ bundleId: String)
-> NativeView
{
return NativeView(
className: getElementTypeName(elementType: xcuielement.elementType),
text: xcuielement.label,
contentDescription: "", // TODO: Separate request
contentDescription: "", // TODO: Separate request
focused: xcuielement.hasFocus,
enabled: xcuielement.isEnabled,
resourceName: xcuielement.identifier,
Expand All @@ -863,6 +865,6 @@
return NativeView.fromXCUIElementSnapshot(child, bundleId)
})
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Foundation

final class AutomatorServer: NativeAutomatorServer {
final class AutomatorServer: NativeAutomatorServer {
private let automator: Automator

private let onAppReady: (Bool) -> Void
Expand Down Expand Up @@ -70,11 +70,11 @@ final class AutomatorServer: NativeAutomatorServer {
return GetNativeViewsResponse(nativeViews: nativeViews)
}
}

func getNativeUITree(request: GetNativeUITreeRequest) throws -> GetNativeUITreeRespone {
let roots = try automator.getUITreeRoots(installedApps: request.iosInstalledApps ?? [])
let roots = try automator.getUITreeRoots(installedApps: request.iosInstalledApps ?? [])

return GetNativeUITreeRespone(roots: roots)
return GetNativeUITreeRespone(roots: roots)
}

func tap(request: TapRequest) throws {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if PATROL_ENABLED

import Foundation
import XCTest
import Foundation
import XCTest

private let elementTypeNames = [
private let elementTypeNames = [
XCUIElement.ElementType.any: "any",
XCUIElement.ElementType.other: "other",
XCUIElement.ElementType.application: "application",
Expand Down Expand Up @@ -86,12 +86,11 @@ private let elementTypeNames = [
XCUIElement.ElementType.stepper: "stepper",
XCUIElement.ElementType.tab: "tab",
XCUIElement.ElementType.touchBar: "touchBar",
XCUIElement.ElementType.statusItem: "statusItem"
]

XCUIElement.ElementType.statusItem: "statusItem",
]

func getElementTypeName(elementType: XCUIElement.ElementType) -> String? {
func getElementTypeName(elementType: XCUIElement.ElementType) -> String? {
return elementTypeNames[elementType]
}
}

#endif

0 comments on commit 084fafc

Please sign in to comment.