From 80db341c78f1547be1ce0b2861c91e1b549b34e3 Mon Sep 17 00:00:00 2001 From: Marco Pagliari Date: Tue, 15 Oct 2019 10:29:59 +0200 Subject: [PATCH 1/2] Added basic accessibility identifier to ease the search during UI tests --- .../project.pbxproj | 150 +++++++++++++++++- .../xcschemes/JGProgressHUD-Tests.xcscheme | 88 ++++++++++ .../Info.plist | 22 +++ .../JGProgressHUD_TestsUITests_Swift.swift | 31 ++++ JGProgressHUD/JGProgressHUD/JGProgressHUD.m | 3 + .../JGProgressHUDIndicatorView.m | 1 + 6 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 Examples/JGProgressHUD-Tests.xcodeproj/xcshareddata/xcschemes/JGProgressHUD-Tests.xcscheme create mode 100644 Examples/JGProgressHUD-TestsUITests-Swift/Info.plist create mode 100644 Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift diff --git a/Examples/JGProgressHUD-Tests.xcodeproj/project.pbxproj b/Examples/JGProgressHUD-Tests.xcodeproj/project.pbxproj index f6fca4c..df60acf 100644 --- a/Examples/JGProgressHUD-Tests.xcodeproj/project.pbxproj +++ b/Examples/JGProgressHUD-Tests.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 6BC018D8197BF28100DA4C49 /* JGAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BC018D7197BF28100DA4C49 /* JGAppDelegate.m */; }; 6BC018E1197BF28100DA4C49 /* JGMainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BC018E0197BF28100DA4C49 /* JGMainViewController.m */; }; 6BC018E3197BF28100DA4C49 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6BC018E2197BF28100DA4C49 /* Images.xcassets */; }; + A97064362355B57B0087FF49 /* JGProgressHUD_TestsUITests_Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97064352355B57B0087FF49 /* JGProgressHUD_TestsUITests_Swift.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -96,6 +97,20 @@ remoteGlobalIDString = 6BABF9A21F7A6133005E783F; remoteInfo = "JGProgressHUD-tvOS"; }; + A97064382355B57B0087FF49 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6BC018BC197BF28100DA4C49 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6BC018C3197BF28100DA4C49; + remoteInfo = "JGProgressHUD-Tests"; + }; + A970643D2355B7260087FF49 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6BC018BC197BF28100DA4C49 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6B6E775F1F7970570031D476; + remoteInfo = "JGProgressHUD-Tests-Swift"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -166,6 +181,9 @@ 6BC018E9197BF28100DA4C49 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 6BC01909197C1D0F00DA4C49 /* JGProgressHUD-Tests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "JGProgressHUD-Tests-Info.plist"; sourceTree = ""; }; 6BCC80A12351225C00988AA4 /* JGProgressHUD-Tests-Swift.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "JGProgressHUD-Tests-Swift.entitlements"; sourceTree = ""; }; + A97064332355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "JGProgressHUD-TestsUITests-Swift.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + A97064352355B57B0087FF49 /* JGProgressHUD_TestsUITests_Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JGProgressHUD_TestsUITests_Swift.swift; sourceTree = ""; }; + A97064372355B57B0087FF49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -195,6 +213,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A97064302355B57B0087FF49 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -238,6 +263,7 @@ 6BC018CD197BF28100DA4C49 /* JGProgressHUD-Tests */, 6B6E77611F7970570031D476 /* JGProgressHUD-Tests-Swift */, 6BABF9DA1F7A67E4005E783F /* JGProgressHUD-Tests-tvOS */, + A97064342355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift */, 6BC018C6197BF28100DA4C49 /* Frameworks */, 6BC018C5197BF28100DA4C49 /* Products */, ); @@ -249,6 +275,7 @@ 6BC018C4197BF28100DA4C49 /* JGProgressHUD-Tests.app */, 6B6E77601F7970570031D476 /* JGProgressHUD-Tests-Swift.app */, 6BABF9D91F7A67E3005E783F /* JGProgressHUD-Tests-tvOS.app */, + A97064332355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift.xctest */, ); name = Products; sourceTree = ""; @@ -292,6 +319,15 @@ name = "Supporting Files"; sourceTree = ""; }; + A97064342355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift */ = { + isa = PBXGroup; + children = ( + A97064352355B57B0087FF49 /* JGProgressHUD_TestsUITests_Swift.swift */, + A97064372355B57B0087FF49 /* Info.plist */, + ); + path = "JGProgressHUD-TestsUITests-Swift"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -356,6 +392,25 @@ productReference = 6BC018C4197BF28100DA4C49 /* JGProgressHUD-Tests.app */; productType = "com.apple.product-type.application"; }; + A97064322355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift */ = { + isa = PBXNativeTarget; + buildConfigurationList = A970643C2355B57B0087FF49 /* Build configuration list for PBXNativeTarget "JGProgressHUD-TestsUITests-Swift" */; + buildPhases = ( + A970642F2355B57B0087FF49 /* Sources */, + A97064302355B57B0087FF49 /* Frameworks */, + A97064312355B57B0087FF49 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + A97064392355B57B0087FF49 /* PBXTargetDependency */, + A970643E2355B7260087FF49 /* PBXTargetDependency */, + ); + name = "JGProgressHUD-TestsUITests-Swift"; + productName = "JGProgressHUD-TestsUITests-Swift"; + productReference = A97064332355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -363,7 +418,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = JG; - LastSwiftUpdateCheck = 0900; + LastSwiftUpdateCheck = 1110; LastUpgradeCheck = 1030; ORGANIZATIONNAME = "Jonas Gessner"; TargetAttributes = { @@ -377,6 +432,11 @@ LastSwiftMigration = 1030; ProvisioningStyle = Automatic; }; + A97064322355B57B0087FF49 = { + CreatedOnToolsVersion = 11.1; + ProvisioningStyle = Automatic; + TestTargetID = 6B6E775F1F7970570031D476; + }; }; }; buildConfigurationList = 6BC018BF197BF28100DA4C49 /* Build configuration list for PBXProject "JGProgressHUD-Tests" */; @@ -401,6 +461,7 @@ 6BC018C3197BF28100DA4C49 /* JGProgressHUD-Tests */, 6B6E775F1F7970570031D476 /* JGProgressHUD-Tests-Swift */, 6BABF9D81F7A67E3005E783F /* JGProgressHUD-Tests-tvOS */, + A97064322355B57B0087FF49 /* JGProgressHUD-TestsUITests-Swift */, ); }; /* End PBXProject section */ @@ -451,6 +512,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A97064312355B57B0087FF49 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -483,6 +551,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A970642F2355B57B0087FF49 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A97064362355B57B0087FF49 /* JGProgressHUD_TestsUITests_Swift.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -521,6 +597,16 @@ name = "JGProgressHUD-tvOS"; targetProxy = 6BABF9EF1F7A6820005E783F /* PBXContainerItemProxy */; }; + A97064392355B57B0087FF49 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6BC018C3197BF28100DA4C49 /* JGProgressHUD-Tests */; + targetProxy = A97064382355B57B0087FF49 /* PBXContainerItemProxy */; + }; + A970643E2355B7260087FF49 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6B6E775F1F7970570031D476 /* JGProgressHUD-Tests-Swift */; + targetProxy = A970643D2355B7260087FF49 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -813,6 +899,59 @@ }; name = Release; }; + A970643A2355B57B0087FF49 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = "JGProgressHUD-TestsUITests-Swift/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.1; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "de.j-gessner.JGProgressHUD-Tests-Swift.JGProgressHUD-TestsUITests-Swift"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = "JGProgressHUD-Tests-Swift"; + }; + name = Debug; + }; + A970643B2355B57B0087FF49 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = "JGProgressHUD-TestsUITests-Swift/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.1; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "de.j-gessner.JGProgressHUD-Tests-Swift.JGProgressHUD-TestsUITests-Swift"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = "JGProgressHUD-Tests-Swift"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -852,6 +991,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + A970643C2355B57B0087FF49 /* Build configuration list for PBXNativeTarget "JGProgressHUD-TestsUITests-Swift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A970643A2355B57B0087FF49 /* Debug */, + A970643B2355B57B0087FF49 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 6BC018BC197BF28100DA4C49 /* Project object */; diff --git a/Examples/JGProgressHUD-Tests.xcodeproj/xcshareddata/xcschemes/JGProgressHUD-Tests.xcscheme b/Examples/JGProgressHUD-Tests.xcodeproj/xcshareddata/xcschemes/JGProgressHUD-Tests.xcscheme new file mode 100644 index 0000000..cba98d0 --- /dev/null +++ b/Examples/JGProgressHUD-Tests.xcodeproj/xcshareddata/xcschemes/JGProgressHUD-Tests.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/JGProgressHUD-TestsUITests-Swift/Info.plist b/Examples/JGProgressHUD-TestsUITests-Swift/Info.plist new file mode 100644 index 0000000..64d65ca --- /dev/null +++ b/Examples/JGProgressHUD-TestsUITests-Swift/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift b/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift new file mode 100644 index 0000000..071c1d7 --- /dev/null +++ b/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift @@ -0,0 +1,31 @@ +import XCTest + +class JGProgressHUD_TestsUITests_Swift: XCTestCase { + + override func setUp() { + continueAfterFailure = false + } + + override func tearDown() { + + } + + func testExample() { + let app = XCUIApplication() + app.launch() + + var completed = false + while (!completed) { + let hud = app.otherElements.matching(identifier: "HUD") + let textLabel = hud.descendants(matching: .any).matching(identifier: "HUD_textLabel").firstMatch + let detailTextLabel = hud.descendants(matching: .any).matching(identifier: "HUD_detailTextLabel").firstMatch + let indicatorView = hud.descendants(matching: .any).matching(identifier: "HUD_indicatorView").firstMatch + + print("HUD Text Label: ", textLabel.exists ? textLabel.label : "-") + print("HUD Detail Text Label: ", detailTextLabel.exists ? detailTextLabel.label : "-") + print("HUD Indicator View: ", indicatorView.exists ? indicatorView.label : "-") + + completed = textLabel.label == "Simple example in Swift" && detailTextLabel.label == "See JGProgressHUD-Tests for more examples" + } + } +} diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUD.m b/JGProgressHUD/JGProgressHUD/JGProgressHUD.m index 86fd7ac..444488d 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUD.m +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUD.m @@ -130,6 +130,7 @@ - (instancetype)initWithStyle:(JGProgressHUDStyle)style { _HUDView = [[UIView alloc] init]; self.HUDView.backgroundColor = [UIColor clearColor]; + self.HUDView.accessibilityIdentifier = @"HUD"; [self addSubview:self.HUDView]; _blurViewContainer = [[UIView alloc] init]; @@ -728,6 +729,7 @@ - (UILabel *)textLabel { [_textLabel addObserver:self forKeyPath:@"text" options:(NSKeyValueObservingOptions)kNilOptions context:NULL]; [_textLabel addObserver:self forKeyPath:@"font" options:(NSKeyValueObservingOptions)kNilOptions context:NULL]; _textLabel.isAccessibilityElement = YES; + _textLabel.accessibilityIdentifier = @"HUD_textLabel"; [self.contentView addSubview:_textLabel]; } @@ -752,6 +754,7 @@ - (UILabel *)detailTextLabel { [_detailTextLabel addObserver:self forKeyPath:@"text" options:(NSKeyValueObservingOptions)kNilOptions context:NULL]; [_detailTextLabel addObserver:self forKeyPath:@"font" options:(NSKeyValueObservingOptions)kNilOptions context:NULL]; _detailTextLabel.isAccessibilityElement = YES; + _detailTextLabel.accessibilityIdentifier = @"HUD_detailTextLabel"; [self.contentView addSubview:_detailTextLabel]; } diff --git a/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m b/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m index 1a69631..bdd3ed9 100755 --- a/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m +++ b/JGProgressHUD/JGProgressHUD/JGProgressHUDIndicatorView.m @@ -40,6 +40,7 @@ - (instancetype)initWithContentView:(UIView *)contentView { self.backgroundColor = [UIColor clearColor]; self.isAccessibilityElement = YES; + self.accessibilityIdentifier = @"HUD_indicatorView"; [self setNeedsAccessibilityUpdate]; if (contentView) { From 2f166fdd570e564eb6b1a8e7ff88eb13ea784172 Mon Sep 17 00:00:00 2001 From: Marco Pagliari Date: Fri, 26 Jun 2020 17:34:18 +0200 Subject: [PATCH 2/2] Update JGProgressHUD_TestsUITests_Swift.swift Added an actual meaning to UI tests, checking all the steps of the Demo swift app --- .../JGProgressHUD_TestsUITests_Swift.swift | 85 ++++++++++++++++--- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift b/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift index 071c1d7..a82ee0c 100644 --- a/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift +++ b/Examples/JGProgressHUD-TestsUITests-Swift/JGProgressHUD_TestsUITests_Swift.swift @@ -2,30 +2,89 @@ import XCTest class JGProgressHUD_TestsUITests_Swift: XCTestCase { + var app: XCUIApplication! + override func setUp() { continueAfterFailure = false + + app = XCUIApplication() + app.launch() } override func tearDown() { } - func testExample() { - let app = XCUIApplication() - app.launch() + func testDemo() { + XCTAssert(app.waitHud(textLabel: "Downloading")) + XCTAssert(app.waitHud(textLabel: "Downloading", detailTextLabel: "100% Complete")) + XCTAssert(app.waitHud(textLabel: "Success")) + XCTAssert(app.waitHud(textLabel: "Loading")) + XCTAssert(app.waitHud(textLabel: "Done")) - var completed = false - while (!completed) { - let hud = app.otherElements.matching(identifier: "HUD") - let textLabel = hud.descendants(matching: .any).matching(identifier: "HUD_textLabel").firstMatch - let detailTextLabel = hud.descendants(matching: .any).matching(identifier: "HUD_detailTextLabel").firstMatch - let indicatorView = hud.descendants(matching: .any).matching(identifier: "HUD_indicatorView").firstMatch + #if os(tvOS) + XCTAssert(app.waitHud(textLabel: "Simple example on tvOS in Swift", detailTextLabel: "See JGProgressHUD-Tests for more examples")) + #else + XCTAssert(app.waitHud(textLabel: "Simple example in Swift", detailTextLabel: "See JGProgressHUD-Tests for more examples")) + #endif + } +} + +extension XCUIApplication { + + var huds: XCUIElementQuery { + return self.otherElements.matching(identifier: "HUD") + } + + var hudTextLabel: String? { + return hudElement(identifier: "HUD_textLabel") + } + + var hudTextDetailLabel: String? { + return hudElement(identifier: "HUD_detailTextLabel") + } - print("HUD Text Label: ", textLabel.exists ? textLabel.label : "-") - print("HUD Detail Text Label: ", detailTextLabel.exists ? detailTextLabel.label : "-") - print("HUD Indicator View: ", indicatorView.exists ? indicatorView.label : "-") + func hudElement(identifier: String) -> String? { + let hud = huds.firstMatch + let descendants = hud.descendants(matching: .any) + let query = descendants.matching(identifier: identifier) + guard query.count > 0 else { + return nil + } + + let label = query.firstMatch.label + print("\(identifier): \(label)") + return label + } + + func waitHud(textLabel: String, detailTextLabel: String, timeout: TimeInterval = 10) -> Bool { + waitHud { text, detail -> Bool in + return (text?.contains(textLabel) ?? false) && (detail?.contains(detailTextLabel) ?? false) + } + } + + func waitHud(detailTextLabel: String, timeout: TimeInterval = 10) -> Bool { + waitHud { _, detail -> Bool in + return detail?.contains(detailTextLabel) ?? false + } + } + + func waitHud(textLabel: String, timeout: TimeInterval = 10) -> Bool { + waitHud { text, _ -> Bool in + return text?.contains(textLabel) ?? false + } + } + + func waitHud(timeout: TimeInterval = 10, when:((String?, String?) -> Bool)) -> Bool { + var completed = false + let stop = Date(timeIntervalSinceNow: timeout) - completed = textLabel.label == "Simple example in Swift" && detailTextLabel.label == "See JGProgressHUD-Tests for more examples" + while !completed { + completed = when(hudTextLabel, hudTextDetailLabel) + if Date() > stop { + return false + } } + return true } }