Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
shamanec committed Jul 23, 2023
1 parent aaab735 commit 220c0b5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 71 deletions.
12 changes: 10 additions & 2 deletions xcuitest-sample-proj.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
isa = PBXGroup;
children = (
FFF0348E2A6CFA6500A33E97 /* FirstPage.swift */,
FFF034902A6CFA8B00A33E97 /* BasePage.swift */,
FFF034922A6CFEA200A33E97 /* SecondPage.swift */,
FFF034942A6D027B00A33E97 /* TabBar.swift */,
);
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -183,6 +182,15 @@
path = Views;
sourceTree = "<group>";
};
FFF034972A6D1B3900A33E97 /* Foundations */ = {
isa = PBXGroup;
children = (
FF79C2822A66F54E00BBC60A /* BaseTest.swift */,
FFF034902A6CFA8B00A33E97 /* BasePage.swift */,
);
path = Foundations;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
File renamed without changes.
8 changes: 4 additions & 4 deletions xcuitest-sample-projUITests/Helpers/ElementsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions xcuitest-sample-projUITests/Pages/FirstPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }


}

0 comments on commit 220c0b5

Please sign in to comment.