diff --git a/xcuitest-sample-proj.xcodeproj/project.pbxproj b/xcuitest-sample-proj.xcodeproj/project.pbxproj index 58c9e4e..b9c0b03 100644 --- a/xcuitest-sample-proj.xcodeproj/project.pbxproj +++ b/xcuitest-sample-proj.xcodeproj/project.pbxproj @@ -91,7 +91,6 @@ isa = PBXGroup; children = ( FFF0348E2A6CFA6500A33E97 /* FirstPage.swift */, - FFF034902A6CFA8B00A33E97 /* BasePage.swift */, FFF034922A6CFEA200A33E97 /* SecondPage.swift */, FFF034942A6D027B00A33E97 /* TabBar.swift */, ); @@ -139,12 +138,12 @@ FF79C2012A66F1B700BBC60A /* xcuitest-sample-projUITests */ = { isa = PBXGroup; children = ( + FFF034972A6D1B3900A33E97 /* Foundations */, FF4D5CAB2A67FDA300B52624 /* Pages */, FF79C2872A66F9E500BBC60A /* Helpers */, FF79C2842A66F71100BBC60A /* Props */, FF79C27D2A66F31800BBC60A /* Extensions */, FF79C2022A66F1B700BBC60A /* xcuitest_sample_projUITests.swift */, - FF79C2822A66F54E00BBC60A /* BaseTest.swift */, ); path = "xcuitest-sample-projUITests"; sourceTree = ""; @@ -183,6 +182,15 @@ path = Views; sourceTree = ""; }; + FFF034972A6D1B3900A33E97 /* Foundations */ = { + isa = PBXGroup; + children = ( + FF79C2822A66F54E00BBC60A /* BaseTest.swift */, + FFF034902A6CFA8B00A33E97 /* BasePage.swift */, + ); + path = Foundations; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ diff --git a/xcuitest-sample-proj.xcodeproj/project.xcworkspace/xcuserdata/shamanec.xcuserdatad/UserInterfaceState.xcuserstate b/xcuitest-sample-proj.xcodeproj/project.xcworkspace/xcuserdata/shamanec.xcuserdatad/UserInterfaceState.xcuserstate index a69de83..0d85096 100644 Binary files a/xcuitest-sample-proj.xcodeproj/project.xcworkspace/xcuserdata/shamanec.xcuserdatad/UserInterfaceState.xcuserstate and b/xcuitest-sample-proj.xcodeproj/project.xcworkspace/xcuserdata/shamanec.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/xcuitest-sample-projUITests/Extensions/XCUIElementQuery+Extensions.swift b/xcuitest-sample-projUITests/Extensions/XCUIElementQuery+Extensions.swift index 807a70d..f898101 100644 --- a/xcuitest-sample-projUITests/Extensions/XCUIElementQuery+Extensions.swift +++ b/xcuitest-sample-projUITests/Extensions/XCUIElementQuery+Extensions.swift @@ -15,78 +15,24 @@ extension XCUIElementQuery { var isEmpty: Bool { count == 0 } // MARK: Return element by predicate methods - /// Returns element with label matching provided string. - /// - note: - /// String matching is customizable with operators available in `NSPredicate` specification. - /// Check the `StringComparisonOperator` for available options. - /// ```swift - /// let text = app.staticTexts.element(withLabelMatching: "John*", comparisonOperator: .like) - /// XCTAssertTrue(text.exists) - /// ``` - /// - Parameters: - /// - text: String to search for. - /// - comparisonOperator: Operation to use when performing comparison. - /// - Returns: `XCUIElement` that label matches to given text. - func element( - withLabelMatching text: String, - comparisonOperator: StringComparisonOperator = .equals - ) -> XCUIElement { - return element(matching: NSPredicate(format: "label \(comparisonOperator.rawValue) %@", text)) + func element(withLabelMatching text: String) -> XCUIElement { + return element(matching: NSPredicate(format: "label == %@", text)) } - /// Returns element with label which contains provided string. - /// ```swift - /// let text = app.staticTexts.element(withLabelContaining: "John") - /// XCTAssertTrue(text.exists) - /// ``` - /// - Parameter text: String to search for. - /// - Returns: `XCUIElement` that label contains given text. func element(withLabelContaining text: String) -> XCUIElement { - return element(withLabelMatching: text, comparisonOperator: .contains) + return element(matching: NSPredicate(format: "label CONTAINS %@", text)) } - /// Returns element with label which ends with provided string. - /// ```swift - /// let text = app.staticTexts.element(withLabelPrefixed: "John") - /// XCTAssertTrue(text.exists) - /// ``` - /// - Parameter text: String to search for. - /// - Returns: `XCUIElement` that label begins with given text. func element(withLabelSuffixed text: String) -> XCUIElement { - return element(withLabelMatching: text, comparisonOperator: .endsWith) + return element(matching: NSPredicate(format: "label ENDSWITH %@", text)) } - enum StringComparisonOperator: RawRepresentable { - case equals - case beginsWith - case contains - case endsWith - case like - case matches - case other(comparisonOperator: String) - - var rawValue: String { - switch self { - case .equals: return "==" - case .beginsWith: return "BEGINSWITH" - case .contains: return "CONTAINS" - case .endsWith: return "ENDSWITH" - case .like: return "LIKE" - case .matches: return "MATCHES" - case .other(let comparisonOperator): return comparisonOperator - } - } - - init(rawValue: String) { - switch rawValue { - case "==": self = .equals - case "BEGINSWITH": self = .beginsWith - case "CONTAINS": self = .contains - case "ENDSWITH": self = .endsWith - case "LIKE": self = .like - case "MATCHES": self = .matches - default: self = .other(comparisonOperator: rawValue) - } - } + func element(withLabelPrefixed text: String) -> XCUIElement { + return element(matching: NSPredicate(format: "label BEGINSWITH %@", text)) } + + func element(withLabelLike text: String) -> XCUIElement { + return element(matching: NSPredicate(format: "label LIKE %@", text)) + } + } diff --git a/xcuitest-sample-projUITests/Pages/BasePage.swift b/xcuitest-sample-projUITests/Foundations/BasePage.swift similarity index 100% rename from xcuitest-sample-projUITests/Pages/BasePage.swift rename to xcuitest-sample-projUITests/Foundations/BasePage.swift diff --git a/xcuitest-sample-projUITests/BaseTest.swift b/xcuitest-sample-projUITests/Foundations/BaseTest.swift similarity index 100% rename from xcuitest-sample-projUITests/BaseTest.swift rename to xcuitest-sample-projUITests/Foundations/BaseTest.swift diff --git a/xcuitest-sample-projUITests/Helpers/ElementsHelper.swift b/xcuitest-sample-projUITests/Helpers/ElementsHelper.swift index db86d61..9b85859 100644 --- a/xcuitest-sample-projUITests/Helpers/ElementsHelper.swift +++ b/xcuitest-sample-projUITests/Helpers/ElementsHelper.swift @@ -15,7 +15,7 @@ class ElementsHelper: XCTest { /// - timeoutValue: How long to wait until the condition is met /// - elementsCount: Minimum number of elements to expect in the XCUIElementQuery /// - Returns: Boolean value if the condition was met and the query has at least the X number of elements - class func waitUntilTableFilled(_ elements: XCUIElementQuery, + static func waitUntilTableFilled(_ elements: XCUIElementQuery, _ elementsCount: Int = 1, _ timeoutValue: Double = TestConstants.Timeout.medium) { var result = false @@ -37,7 +37,7 @@ class ElementsHelper: XCTest { /// - firstElement: The element that will be dragged /// - secondElement: The element which will be used as an end coordinate to drag the first element to /// - pressDuration: How long to press the element to activate the drag and drop functionality before moving it - class func dragAndDrop(_ firstElement: XCUIElement, _ secondElement: XCUIElement, _ pressDuration: TimeInterval) { + static func dragAndDrop(_ firstElement: XCUIElement, _ secondElement: XCUIElement, _ pressDuration: TimeInterval) { let startCoordinate = firstElement.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) let endCoordinate = secondElement.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) startCoordinate.press(forDuration: pressDuration, thenDragTo: endCoordinate) @@ -48,7 +48,7 @@ class ElementsHelper: XCTest { /// - Parameters: /// - element: XCUIElement that will be polled until it disappears /// - timeoutValue: How long to poll the XCUIElement until it disappears - class func waitUntilElementDisappears(_ element: XCUIElement, _ timeoutValue: Double) { + static func waitUntilElementDisappears(_ element: XCUIElement, _ timeoutValue: Double) { let startTime = Date().timeIntervalSince1970 var elementVisible = true @@ -68,7 +68,7 @@ class ElementsHelper: XCTest { /// - firstElement: The element for which we validate the position /// - secondElement: The element against which we validate the first element position /// - relativePosition: The expected position of the first element relative to the second element - class func validateElementToElementPosition(_ firstElement: XCUIElement, + static func validateElementToElementPosition(_ firstElement: XCUIElement, _ secondElement: XCUIElement, _ relativePosition: TestConstants.ElementPosition) { var result = false diff --git a/xcuitest-sample-projUITests/Pages/FirstPage.swift b/xcuitest-sample-projUITests/Pages/FirstPage.swift index 93a30be..b9b46af 100644 --- a/xcuitest-sample-projUITests/Pages/FirstPage.swift +++ b/xcuitest-sample-projUITests/Pages/FirstPage.swift @@ -11,4 +11,6 @@ class FirstPage: BasePage { var carousel: XCUIElement { app.scrollViews.matching(identifier: "carousel-view").firstMatch } var carouselItems: XCUIElementQuery { carousel.staticTexts } var disappearingButton: XCUIElement { app.buttons["disappearing-button"] } + + }