├── README.md ├── Resources ├── 1.png ├── 2.png └── 3.png ├── XCUITestExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── danielcarlos.xcuserdatad │ └── xcschemes │ ├── XCUITestExample.xcscheme │ └── xcschememanagement.plist ├── XCUITestExample ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift └── XCUITestExampleUITests ├── Info.plist └── XCUITestExampleUITests.swift /README.md: -------------------------------------------------------------------------------- 1 | # XCUITestExample 2 | Tests more readable with Page Objects and Method Chaining : 3 | ``` 4 | func testSearchResultFlow() { 5 | SearchPage() 6 | .type(query: "XCode") { self.takeScreenShot() } 7 | .tapOk() 8 | .getTitle { 9 | XCTAssertEqual("Result for XCode", $0) 10 | } 11 | } 12 | ``` 13 | 14 | Every Page subclass must override the rootElement 15 | ``` 16 | class ResultPage: Page { 17 | override var rootElement: XCUIElement { 18 | return app.otherElements["view_result"] 19 | } 20 | ``` 21 | 22 | 23 | Use Accessibility Identifiers instead of elements' values 24 | 25 | `app.buttons["btn_send"].tap()` 26 | 27 | ![accessibility identifiers](Resources/2.png) 28 | 29 | 30 | Disable automatic screenshots. 31 | 32 | ![disable automatic screenshots](Resources/1.png) 33 | 34 | Log your tests properly to make a better report. 35 | 36 | ![test report](Resources/3.png) 37 | -------------------------------------------------------------------------------- /Resources/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielCarlosCE/XCUITestExample/459bbfb9f9628b34a362fabc78868a765a90d0b1/Resources/1.png -------------------------------------------------------------------------------- /Resources/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielCarlosCE/XCUITestExample/459bbfb9f9628b34a362fabc78868a765a90d0b1/Resources/2.png -------------------------------------------------------------------------------- /Resources/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielCarlosCE/XCUITestExample/459bbfb9f9628b34a362fabc78868a765a90d0b1/Resources/3.png -------------------------------------------------------------------------------- /XCUITestExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A4341A6A1FD2E2FF00288489 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4341A691FD2E2FF00288489 /* AppDelegate.swift */; }; 11 | A4341A6C1FD2E2FF00288489 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4341A6B1FD2E2FF00288489 /* ViewController.swift */; }; 12 | A4341A6F1FD2E2FF00288489 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A4341A6D1FD2E2FF00288489 /* Main.storyboard */; }; 13 | A4341A711FD2E2FF00288489 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A4341A701FD2E2FF00288489 /* Assets.xcassets */; }; 14 | A4341A741FD2E2FF00288489 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A4341A721FD2E2FF00288489 /* LaunchScreen.storyboard */; }; 15 | A4341A7F1FD2E2FF00288489 /* XCUITestExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4341A7E1FD2E2FF00288489 /* XCUITestExampleUITests.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXContainerItemProxy section */ 19 | A4341A7B1FD2E2FF00288489 /* PBXContainerItemProxy */ = { 20 | isa = PBXContainerItemProxy; 21 | containerPortal = A4341A5E1FD2E2FF00288489 /* Project object */; 22 | proxyType = 1; 23 | remoteGlobalIDString = A4341A651FD2E2FF00288489; 24 | remoteInfo = XCUITestExample; 25 | }; 26 | /* End PBXContainerItemProxy section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | A4341A661FD2E2FF00288489 /* XCUITestExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XCUITestExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | A4341A691FD2E2FF00288489 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 31 | A4341A6B1FD2E2FF00288489 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 32 | A4341A6E1FD2E2FF00288489 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 33 | A4341A701FD2E2FF00288489 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 34 | A4341A731FD2E2FF00288489 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 35 | A4341A751FD2E2FF00288489 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 36 | A4341A7A1FD2E2FF00288489 /* XCUITestExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XCUITestExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | A4341A7E1FD2E2FF00288489 /* XCUITestExampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCUITestExampleUITests.swift; sourceTree = ""; }; 38 | A4341A801FD2E2FF00288489 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | A4341A631FD2E2FF00288489 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | A4341A771FD2E2FF00288489 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | A4341A5D1FD2E2FF00288489 = { 60 | isa = PBXGroup; 61 | children = ( 62 | A4341A681FD2E2FF00288489 /* XCUITestExample */, 63 | A4341A7D1FD2E2FF00288489 /* XCUITestExampleUITests */, 64 | A4341A671FD2E2FF00288489 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | A4341A671FD2E2FF00288489 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | A4341A661FD2E2FF00288489 /* XCUITestExample.app */, 72 | A4341A7A1FD2E2FF00288489 /* XCUITestExampleUITests.xctest */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | A4341A681FD2E2FF00288489 /* XCUITestExample */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | A4341A691FD2E2FF00288489 /* AppDelegate.swift */, 81 | A4341A6B1FD2E2FF00288489 /* ViewController.swift */, 82 | A4341A6D1FD2E2FF00288489 /* Main.storyboard */, 83 | A4341A701FD2E2FF00288489 /* Assets.xcassets */, 84 | A4341A721FD2E2FF00288489 /* LaunchScreen.storyboard */, 85 | A4341A751FD2E2FF00288489 /* Info.plist */, 86 | ); 87 | path = XCUITestExample; 88 | sourceTree = ""; 89 | }; 90 | A4341A7D1FD2E2FF00288489 /* XCUITestExampleUITests */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | A4341A7E1FD2E2FF00288489 /* XCUITestExampleUITests.swift */, 94 | A4341A801FD2E2FF00288489 /* Info.plist */, 95 | ); 96 | path = XCUITestExampleUITests; 97 | sourceTree = ""; 98 | }; 99 | /* End PBXGroup section */ 100 | 101 | /* Begin PBXNativeTarget section */ 102 | A4341A651FD2E2FF00288489 /* XCUITestExample */ = { 103 | isa = PBXNativeTarget; 104 | buildConfigurationList = A4341A831FD2E2FF00288489 /* Build configuration list for PBXNativeTarget "XCUITestExample" */; 105 | buildPhases = ( 106 | A4341A621FD2E2FF00288489 /* Sources */, 107 | A4341A631FD2E2FF00288489 /* Frameworks */, 108 | A4341A641FD2E2FF00288489 /* Resources */, 109 | ); 110 | buildRules = ( 111 | ); 112 | dependencies = ( 113 | ); 114 | name = XCUITestExample; 115 | productName = XCUITestExample; 116 | productReference = A4341A661FD2E2FF00288489 /* XCUITestExample.app */; 117 | productType = "com.apple.product-type.application"; 118 | }; 119 | A4341A791FD2E2FF00288489 /* XCUITestExampleUITests */ = { 120 | isa = PBXNativeTarget; 121 | buildConfigurationList = A4341A861FD2E2FF00288489 /* Build configuration list for PBXNativeTarget "XCUITestExampleUITests" */; 122 | buildPhases = ( 123 | A4341A761FD2E2FF00288489 /* Sources */, 124 | A4341A771FD2E2FF00288489 /* Frameworks */, 125 | A4341A781FD2E2FF00288489 /* Resources */, 126 | ); 127 | buildRules = ( 128 | ); 129 | dependencies = ( 130 | A4341A7C1FD2E2FF00288489 /* PBXTargetDependency */, 131 | ); 132 | name = XCUITestExampleUITests; 133 | productName = XCUITestExampleUITests; 134 | productReference = A4341A7A1FD2E2FF00288489 /* XCUITestExampleUITests.xctest */; 135 | productType = "com.apple.product-type.bundle.ui-testing"; 136 | }; 137 | /* End PBXNativeTarget section */ 138 | 139 | /* Begin PBXProject section */ 140 | A4341A5E1FD2E2FF00288489 /* Project object */ = { 141 | isa = PBXProject; 142 | attributes = { 143 | LastSwiftUpdateCheck = 0910; 144 | LastUpgradeCheck = 0910; 145 | ORGANIZATIONNAME = "Daniel Carlos"; 146 | TargetAttributes = { 147 | A4341A651FD2E2FF00288489 = { 148 | CreatedOnToolsVersion = 9.1; 149 | ProvisioningStyle = Automatic; 150 | }; 151 | A4341A791FD2E2FF00288489 = { 152 | CreatedOnToolsVersion = 9.1; 153 | ProvisioningStyle = Automatic; 154 | TestTargetID = A4341A651FD2E2FF00288489; 155 | }; 156 | }; 157 | }; 158 | buildConfigurationList = A4341A611FD2E2FF00288489 /* Build configuration list for PBXProject "XCUITestExample" */; 159 | compatibilityVersion = "Xcode 8.0"; 160 | developmentRegion = en; 161 | hasScannedForEncodings = 0; 162 | knownRegions = ( 163 | en, 164 | Base, 165 | ); 166 | mainGroup = A4341A5D1FD2E2FF00288489; 167 | productRefGroup = A4341A671FD2E2FF00288489 /* Products */; 168 | projectDirPath = ""; 169 | projectRoot = ""; 170 | targets = ( 171 | A4341A651FD2E2FF00288489 /* XCUITestExample */, 172 | A4341A791FD2E2FF00288489 /* XCUITestExampleUITests */, 173 | ); 174 | }; 175 | /* End PBXProject section */ 176 | 177 | /* Begin PBXResourcesBuildPhase section */ 178 | A4341A641FD2E2FF00288489 /* Resources */ = { 179 | isa = PBXResourcesBuildPhase; 180 | buildActionMask = 2147483647; 181 | files = ( 182 | A4341A741FD2E2FF00288489 /* LaunchScreen.storyboard in Resources */, 183 | A4341A711FD2E2FF00288489 /* Assets.xcassets in Resources */, 184 | A4341A6F1FD2E2FF00288489 /* Main.storyboard in Resources */, 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | A4341A781FD2E2FF00288489 /* Resources */ = { 189 | isa = PBXResourcesBuildPhase; 190 | buildActionMask = 2147483647; 191 | files = ( 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | /* End PBXResourcesBuildPhase section */ 196 | 197 | /* Begin PBXSourcesBuildPhase section */ 198 | A4341A621FD2E2FF00288489 /* Sources */ = { 199 | isa = PBXSourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | A4341A6C1FD2E2FF00288489 /* ViewController.swift in Sources */, 203 | A4341A6A1FD2E2FF00288489 /* AppDelegate.swift in Sources */, 204 | ); 205 | runOnlyForDeploymentPostprocessing = 0; 206 | }; 207 | A4341A761FD2E2FF00288489 /* Sources */ = { 208 | isa = PBXSourcesBuildPhase; 209 | buildActionMask = 2147483647; 210 | files = ( 211 | A4341A7F1FD2E2FF00288489 /* XCUITestExampleUITests.swift in Sources */, 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | }; 215 | /* End PBXSourcesBuildPhase section */ 216 | 217 | /* Begin PBXTargetDependency section */ 218 | A4341A7C1FD2E2FF00288489 /* PBXTargetDependency */ = { 219 | isa = PBXTargetDependency; 220 | target = A4341A651FD2E2FF00288489 /* XCUITestExample */; 221 | targetProxy = A4341A7B1FD2E2FF00288489 /* PBXContainerItemProxy */; 222 | }; 223 | /* End PBXTargetDependency section */ 224 | 225 | /* Begin PBXVariantGroup section */ 226 | A4341A6D1FD2E2FF00288489 /* Main.storyboard */ = { 227 | isa = PBXVariantGroup; 228 | children = ( 229 | A4341A6E1FD2E2FF00288489 /* Base */, 230 | ); 231 | name = Main.storyboard; 232 | sourceTree = ""; 233 | }; 234 | A4341A721FD2E2FF00288489 /* LaunchScreen.storyboard */ = { 235 | isa = PBXVariantGroup; 236 | children = ( 237 | A4341A731FD2E2FF00288489 /* Base */, 238 | ); 239 | name = LaunchScreen.storyboard; 240 | sourceTree = ""; 241 | }; 242 | /* End PBXVariantGroup section */ 243 | 244 | /* Begin XCBuildConfiguration section */ 245 | A4341A811FD2E2FF00288489 /* Debug */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_ANALYZER_NONNULL = YES; 250 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 256 | CLANG_WARN_BOOL_CONVERSION = YES; 257 | CLANG_WARN_COMMA = YES; 258 | CLANG_WARN_CONSTANT_CONVERSION = YES; 259 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 260 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 261 | CLANG_WARN_EMPTY_BODY = YES; 262 | CLANG_WARN_ENUM_CONVERSION = YES; 263 | CLANG_WARN_INFINITE_RECURSION = YES; 264 | CLANG_WARN_INT_CONVERSION = YES; 265 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 266 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 267 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 268 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 269 | CLANG_WARN_STRICT_PROTOTYPES = YES; 270 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 271 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 272 | CLANG_WARN_UNREACHABLE_CODE = YES; 273 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 274 | CODE_SIGN_IDENTITY = "iPhone Developer"; 275 | COPY_PHASE_STRIP = NO; 276 | DEBUG_INFORMATION_FORMAT = dwarf; 277 | ENABLE_STRICT_OBJC_MSGSEND = YES; 278 | ENABLE_TESTABILITY = YES; 279 | GCC_C_LANGUAGE_STANDARD = gnu11; 280 | GCC_DYNAMIC_NO_PIC = NO; 281 | GCC_NO_COMMON_BLOCKS = YES; 282 | GCC_OPTIMIZATION_LEVEL = 0; 283 | GCC_PREPROCESSOR_DEFINITIONS = ( 284 | "DEBUG=1", 285 | "$(inherited)", 286 | ); 287 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 288 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 289 | GCC_WARN_UNDECLARED_SELECTOR = YES; 290 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 291 | GCC_WARN_UNUSED_FUNCTION = YES; 292 | GCC_WARN_UNUSED_VARIABLE = YES; 293 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 294 | MTL_ENABLE_DEBUG_INFO = YES; 295 | ONLY_ACTIVE_ARCH = YES; 296 | SDKROOT = iphoneos; 297 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 298 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 299 | }; 300 | name = Debug; 301 | }; 302 | A4341A821FD2E2FF00288489 /* Release */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ALWAYS_SEARCH_USER_PATHS = NO; 306 | CLANG_ANALYZER_NONNULL = YES; 307 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 308 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 309 | CLANG_CXX_LIBRARY = "libc++"; 310 | CLANG_ENABLE_MODULES = YES; 311 | CLANG_ENABLE_OBJC_ARC = YES; 312 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_COMMA = YES; 315 | CLANG_WARN_CONSTANT_CONVERSION = YES; 316 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 317 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 318 | CLANG_WARN_EMPTY_BODY = YES; 319 | CLANG_WARN_ENUM_CONVERSION = YES; 320 | CLANG_WARN_INFINITE_RECURSION = YES; 321 | CLANG_WARN_INT_CONVERSION = YES; 322 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 323 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 324 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 325 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 326 | CLANG_WARN_STRICT_PROTOTYPES = YES; 327 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 328 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 329 | CLANG_WARN_UNREACHABLE_CODE = YES; 330 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 331 | CODE_SIGN_IDENTITY = "iPhone Developer"; 332 | COPY_PHASE_STRIP = NO; 333 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 334 | ENABLE_NS_ASSERTIONS = NO; 335 | ENABLE_STRICT_OBJC_MSGSEND = YES; 336 | GCC_C_LANGUAGE_STANDARD = gnu11; 337 | GCC_NO_COMMON_BLOCKS = YES; 338 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 339 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 340 | GCC_WARN_UNDECLARED_SELECTOR = YES; 341 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 342 | GCC_WARN_UNUSED_FUNCTION = YES; 343 | GCC_WARN_UNUSED_VARIABLE = YES; 344 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 345 | MTL_ENABLE_DEBUG_INFO = NO; 346 | SDKROOT = iphoneos; 347 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 348 | VALIDATE_PRODUCT = YES; 349 | }; 350 | name = Release; 351 | }; 352 | A4341A841FD2E2FF00288489 /* Debug */ = { 353 | isa = XCBuildConfiguration; 354 | buildSettings = { 355 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 356 | CODE_SIGN_STYLE = Automatic; 357 | INFOPLIST_FILE = XCUITestExample/Info.plist; 358 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 359 | PRODUCT_BUNDLE_IDENTIFIER = com.danielcarlosce.XCUITestExample; 360 | PRODUCT_NAME = "$(TARGET_NAME)"; 361 | SWIFT_VERSION = 4.0; 362 | TARGETED_DEVICE_FAMILY = "1,2"; 363 | }; 364 | name = Debug; 365 | }; 366 | A4341A851FD2E2FF00288489 /* Release */ = { 367 | isa = XCBuildConfiguration; 368 | buildSettings = { 369 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 370 | CODE_SIGN_STYLE = Automatic; 371 | INFOPLIST_FILE = XCUITestExample/Info.plist; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = com.danielcarlosce.XCUITestExample; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_VERSION = 4.0; 376 | TARGETED_DEVICE_FAMILY = "1,2"; 377 | }; 378 | name = Release; 379 | }; 380 | A4341A871FD2E2FF00288489 /* Debug */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 384 | CODE_SIGN_STYLE = Automatic; 385 | INFOPLIST_FILE = XCUITestExampleUITests/Info.plist; 386 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 387 | PRODUCT_BUNDLE_IDENTIFIER = com.danielcarlosce.XCUITestExampleUITests; 388 | PRODUCT_NAME = "$(TARGET_NAME)"; 389 | SWIFT_VERSION = 4.0; 390 | TARGETED_DEVICE_FAMILY = "1,2"; 391 | TEST_TARGET_NAME = XCUITestExample; 392 | }; 393 | name = Debug; 394 | }; 395 | A4341A881FD2E2FF00288489 /* Release */ = { 396 | isa = XCBuildConfiguration; 397 | buildSettings = { 398 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 399 | CODE_SIGN_STYLE = Automatic; 400 | INFOPLIST_FILE = XCUITestExampleUITests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_BUNDLE_IDENTIFIER = com.danielcarlosce.XCUITestExampleUITests; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | SWIFT_VERSION = 4.0; 405 | TARGETED_DEVICE_FAMILY = "1,2"; 406 | TEST_TARGET_NAME = XCUITestExample; 407 | }; 408 | name = Release; 409 | }; 410 | /* End XCBuildConfiguration section */ 411 | 412 | /* Begin XCConfigurationList section */ 413 | A4341A611FD2E2FF00288489 /* Build configuration list for PBXProject "XCUITestExample" */ = { 414 | isa = XCConfigurationList; 415 | buildConfigurations = ( 416 | A4341A811FD2E2FF00288489 /* Debug */, 417 | A4341A821FD2E2FF00288489 /* Release */, 418 | ); 419 | defaultConfigurationIsVisible = 0; 420 | defaultConfigurationName = Release; 421 | }; 422 | A4341A831FD2E2FF00288489 /* Build configuration list for PBXNativeTarget "XCUITestExample" */ = { 423 | isa = XCConfigurationList; 424 | buildConfigurations = ( 425 | A4341A841FD2E2FF00288489 /* Debug */, 426 | A4341A851FD2E2FF00288489 /* Release */, 427 | ); 428 | defaultConfigurationIsVisible = 0; 429 | defaultConfigurationName = Release; 430 | }; 431 | A4341A861FD2E2FF00288489 /* Build configuration list for PBXNativeTarget "XCUITestExampleUITests" */ = { 432 | isa = XCConfigurationList; 433 | buildConfigurations = ( 434 | A4341A871FD2E2FF00288489 /* Debug */, 435 | A4341A881FD2E2FF00288489 /* Release */, 436 | ); 437 | defaultConfigurationIsVisible = 0; 438 | defaultConfigurationName = Release; 439 | }; 440 | /* End XCConfigurationList section */ 441 | }; 442 | rootObject = A4341A5E1FD2E2FF00288489 /* Project object */; 443 | } 444 | -------------------------------------------------------------------------------- /XCUITestExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XCUITestExample.xcodeproj/xcuserdata/danielcarlos.xcuserdatad/xcschemes/XCUITestExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 35 | 41 | 42 | 43 | 44 | 45 | 51 | 52 | 53 | 54 | 55 | 56 | 67 | 69 | 75 | 76 | 77 | 78 | 79 | 80 | 86 | 88 | 94 | 95 | 96 | 97 | 99 | 100 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /XCUITestExample.xcodeproj/xcuserdata/danielcarlos.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | XCUITestExample.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A4341A651FD2E2FF00288489 16 | 17 | primary 18 | 19 | 20 | A4341A791FD2E2FF00288489 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /XCUITestExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // XCUITestExample 4 | // 5 | // Created by Daniel Carlos on 12/2/17. 6 | // Copyright © 2017 Daniel Carlos. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /XCUITestExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /XCUITestExample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /XCUITestExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /XCUITestExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /XCUITestExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // XCUITestExample 4 | // 5 | // Created by Daniel Carlos on 12/2/17. 6 | // Copyright © 2017 Daniel Carlos. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | @IBOutlet weak var inputSearch: UITextField! 13 | 14 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 15 | (segue.destination as! ResultViewController).term = inputSearch.text! 16 | } 17 | 18 | 19 | } 20 | 21 | class ResultViewController: UIViewController { 22 | @IBOutlet weak var titleLabel: UILabel! 23 | var term: String = "" 24 | override func viewDidLoad() { 25 | titleLabel.text = "Result for \(term)" 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /XCUITestExampleUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /XCUITestExampleUITests/XCUITestExampleUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // XCUITestExampleUITests.swift 3 | // XCUITestExampleUITests 4 | // 5 | // Created by Daniel Carlos on 12/2/17. 6 | // Copyright © 2017 Daniel Carlos. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class Logger { 12 | func log(_ m: String) { 13 | print(m) 14 | } 15 | } 16 | 17 | class Page { 18 | typealias Completion = (() -> Void)? 19 | let app = XCUIApplication() 20 | let log = Logger().log 21 | required init(timeout: TimeInterval = 10, completion: Completion = nil) { 22 | log("waiting \(timeout)s for \(String(describing: self)) existence") 23 | XCTAssert(rootElement.waitForExistence(timeout: timeout), 24 | "Page \(String(describing: self)) waited, but not loaded") 25 | completion?() 26 | } 27 | var rootElement: XCUIElement { 28 | fatalError("subclass should override rootElement") 29 | } 30 | } 31 | 32 | class SearchPage: Page { 33 | override var rootElement: XCUIElement { 34 | return app.otherElements["view_search"] 35 | } 36 | 37 | @discardableResult 38 | func type(query: String, completion: Completion = nil) -> Self { 39 | log("type \(query) in search field") 40 | let inputSearch = app.textFields["input_search"] 41 | inputSearch.tap() 42 | inputSearch.typeText(query) 43 | completion?() 44 | return self 45 | } 46 | 47 | @discardableResult 48 | func tapOk(completion: Completion = nil) -> ResultPage { 49 | log("tap on ok button") 50 | app.buttons["btn_ok"].tap() 51 | return ResultPage(completion: completion) 52 | } 53 | 54 | } 55 | 56 | class ResultPage: Page { 57 | override var rootElement: XCUIElement { 58 | return app.otherElements["view_result"] 59 | } 60 | 61 | @discardableResult 62 | func getTitle(completion: (String) -> Void) -> Self { 63 | completion(app.staticTexts["text_title"].label) 64 | return self 65 | } 66 | } 67 | 68 | extension XCTestCase { 69 | func takeScreenShot(name screenshotName: String? = nil) { 70 | let screenshot = XCUIScreen.main.screenshot() 71 | let attach = XCTAttachment(screenshot: screenshot, quality: .original) 72 | attach.name = screenshotName ?? name + "_" + UUID().uuidString 73 | attach.lifetime = .keepAlways 74 | add(attach) 75 | } 76 | } 77 | 78 | class XCUITestExampleUITests: XCTestCase { 79 | 80 | override func setUp() { 81 | super.setUp() 82 | continueAfterFailure = false 83 | XCUIApplication().launch() 84 | } 85 | 86 | func testSearchResultFlow() { 87 | SearchPage() 88 | .type(query: "XCode") { self.takeScreenShot() } 89 | .tapOk() 90 | .getTitle { 91 | XCTAssertEqual("Result for XCode", $0) 92 | } 93 | } 94 | 95 | override func tearDown() { 96 | takeScreenShot() 97 | } 98 | 99 | } 100 | --------------------------------------------------------------------------------