From 763487fe8902dbffbeba129752837a3b5d9023dd Mon Sep 17 00:00:00 2001 From: Roman Zakharov Date: Fri, 16 Dec 2022 15:28:11 +0200 Subject: [PATCH] Adds a new .center extension --- .../XCTestExtensions/XCUIElement+Extensions.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/ScreenObject/XCTestExtensions/XCUIElement+Extensions.swift b/Sources/ScreenObject/XCTestExtensions/XCUIElement+Extensions.swift index e751594..dac0116 100644 --- a/Sources/ScreenObject/XCTestExtensions/XCUIElement+Extensions.swift +++ b/Sources/ScreenObject/XCTestExtensions/XCUIElement+Extensions.swift @@ -12,6 +12,11 @@ import XCTest @available(iOS 9.0, *) @available(tvOS 9.1, *) public extension XCUIElement { + // Returns the center's coordinate of the element's frame + var center: XCUICoordinate { + coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) + } + // Types delete symbols into the element. func clearText() { XCTContext.runActivity(named: "Clear \(self) text") { _ in @@ -31,7 +36,7 @@ public extension XCUIElement { // Sends a tap event at the element's coordinate. Useful if the regular .tap() fails. func tapUnhittable() { XCTContext.runActivity(named: "Tap \(self) by coordinate") { _ in - coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap() + center.tap() } } #endif