diff --git a/Example/CreativeUITest/CreativeUITest.m b/Example/CreativeUITest/CreativeUITest.m index 5b8d79e..8681218 100644 --- a/Example/CreativeUITest/CreativeUITest.m +++ b/Example/CreativeUITest/CreativeUITest.m @@ -22,18 +22,22 @@ @implementation CreativeUITest { - (void)setUp { + [super setUp]; // In UI tests it is usually best to stop immediately when a failure occurs. self.continueAfterFailure = NO; - [[self class] clearCookies]; - app = [[XCUIApplication alloc] init]; } -+ (void)tearDown { +- (void)tearDown { // reset cookies & user defaults after all tests have run [self clearCookies]; [self resetUserDefaults]; + + [app terminate]; + [self deleteApp]; + + [super tearDown]; } @@ -60,7 +64,7 @@ - (void)testLoadCreative_fillOutFormAndSubmit_launchesSmsAppWithPrePopulatedText // Fill in the email XCUIElement *emailField = app.webViews.textFields[@"Email Address"]; [emailField tapOnElement]; - [emailField typeText:@"testemail@attentivemobile.com"]; + [emailField fillTextField:@"testemail@attentivemobile.com"]; // Tap something else on the creative to dismiss the keyboard [app.staticTexts[@"10% OFF"] tapOnElement]; @@ -137,7 +141,7 @@ - (void)testLoadCreative_clickProductPage_closesCreative { } -+ (void)clearCookies { +- (void)clearCookies { NSLog(@"Clearing cookies!"); NSSet *websiteDataTypes = [NSSet setWithArray:@[ WKWebsiteDataTypeCookies ]]; NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; @@ -149,7 +153,7 @@ + (void)clearCookies { } -+ (void)resetUserDefaults { +- (void)resetUserDefaults { // Reset user defaults for example app, not the test runner [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:@"com.attentive.ExampleTest"]; } diff --git a/Example/CreativeUITest/Extensions/XCTestCase+Extension.swift b/Example/CreativeUITest/Extensions/XCTestCase+Extension.swift new file mode 100644 index 0000000..49cafe9 --- /dev/null +++ b/Example/CreativeUITest/Extensions/XCTestCase+Extension.swift @@ -0,0 +1,24 @@ +// +// XCTestCase+Extension.swift +// CreativeUITest +// +// Created by Vladimir - Work on 2024-05-23. +// + +import XCTest + +extension XCTestCase { + @objc func deleteApp() { + let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") + + let icon = springboard.icons["Example - Local"] + + guard icon.exists else { return } + + icon.press(forDuration: 1) + + springboard.buttons["Remove App"].tapOnElement() + springboard.buttons["Delete App"].tapOnElement() + springboard.buttons["Delete"].tapOnElement() + } +} diff --git a/Example/CreativeUITest/XCUIElement+Extension.swift b/Example/CreativeUITest/Extensions/XCUIElement+Extension.swift similarity index 78% rename from Example/CreativeUITest/XCUIElement+Extension.swift rename to Example/CreativeUITest/Extensions/XCUIElement+Extension.swift index 2d9ac61..4297b50 100644 --- a/Example/CreativeUITest/XCUIElement+Extension.swift +++ b/Example/CreativeUITest/Extensions/XCUIElement+Extension.swift @@ -21,6 +21,15 @@ extension XCUIElement { @objc func elementExists() -> Bool { elementExists(timeout: 5) } + + @objc func fillTextField(_ text: String) { + guard elementExists() else { + XCTFail("\(description) does not exists") + return + } + + typeText(text) + } } fileprivate extension XCUIElement { diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 7e91fc7..a5beefd 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 5806DE7529774E0700C18FFA /* ProductViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5806DE7429774E0700C18FFA /* ProductViewController.m */; }; 5806DE7629774E0700C18FFA /* ProductViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5806DE7429774E0700C18FFA /* ProductViewController.m */; }; - 58317968292EEEAA0003D6B0 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + 58317968292EEEAA0003D6B0 /* (null) in Sources */ = {isa = PBXBuildFile; }; 58317969292EEEAA0003D6B0 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF5628DCDE57007620BD /* ViewController.m */; }; 5831796A292EEEAA0003D6B0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF5028DCDE57007620BD /* AppDelegate.m */; }; 5831796D292EEEAA0003D6B0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF6128DCDE5A007620BD /* main.m */; }; @@ -19,7 +19,7 @@ 58317974292EEEAA0003D6B0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69CCAF5828DCDE57007620BD /* Main.storyboard */; }; 588B597529B94AB100E3BA33 /* attentive_ios_sdk_framework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 588B597429B94AB100E3BA33 /* attentive_ios_sdk_framework.framework */; }; 588B597629B94AB100E3BA33 /* attentive_ios_sdk_framework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 588B597429B94AB100E3BA33 /* attentive_ios_sdk_framework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 58D52E3F292EDA1600CF32DE /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + 58D52E3F292EDA1600CF32DE /* (null) in Sources */ = {isa = PBXBuildFile; }; 69CCAF5128DCDE57007620BD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF5028DCDE57007620BD /* AppDelegate.m */; }; 69CCAF5428DCDE57007620BD /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF5328DCDE57007620BD /* SceneDelegate.m */; }; 69CCAF5728DCDE57007620BD /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF5628DCDE57007620BD /* ViewController.m */; }; @@ -29,6 +29,7 @@ 69CCAF6228DCDE5A007620BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF6128DCDE5A007620BD /* main.m */; }; 69D3C14C299EF2D10027934F /* CreativeUITest.m in Sources */ = {isa = PBXBuildFile; fileRef = 69D3C14B299EF2D10027934F /* CreativeUITest.m */; }; FB51061A2BFE4A9700D9A72D /* XCUIElement+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB5106192BFE4A9700D9A72D /* XCUIElement+Extension.swift */; }; + FBA017C92BFFE54400CB2969 /* XCTestCase+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA017C82BFFE54400CB2969 /* XCTestCase+Extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -79,6 +80,7 @@ 69D3C14B299EF2D10027934F /* CreativeUITest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CreativeUITest.m; sourceTree = ""; }; FB5106182BFE4A9700D9A72D /* CreativeUITest-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CreativeUITest-Bridging-Header.h"; sourceTree = ""; }; FB5106192BFE4A9700D9A72D /* XCUIElement+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIElement+Extension.swift"; sourceTree = ""; }; + FBA017C82BFFE54400CB2969 /* XCTestCase+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTestCase+Extension.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -170,8 +172,8 @@ 69D3C14A299EF2D10027934F /* CreativeUITest */ = { isa = PBXGroup; children = ( + FBA017CA2BFFE70500CB2969 /* Extensions */, 69D3C14B299EF2D10027934F /* CreativeUITest.m */, - FB5106192BFE4A9700D9A72D /* XCUIElement+Extension.swift */, FB5106182BFE4A9700D9A72D /* CreativeUITest-Bridging-Header.h */, ); path = CreativeUITest; @@ -184,6 +186,15 @@ path = Pods; sourceTree = ""; }; + FBA017CA2BFFE70500CB2969 /* Extensions */ = { + isa = PBXGroup; + children = ( + FB5106192BFE4A9700D9A72D /* XCUIElement+Extension.swift */, + FBA017C82BFFE54400CB2969 /* XCTestCase+Extension.swift */, + ); + path = Extensions; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -315,7 +326,7 @@ buildActionMask = 2147483647; files = ( 5806DE7629774E0700C18FFA /* ProductViewController.m in Sources */, - 58317968292EEEAA0003D6B0 /* BuildFile in Sources */, + 58317968292EEEAA0003D6B0 /* (null) in Sources */, 58317969292EEEAA0003D6B0 /* ViewController.m in Sources */, 5831796A292EEEAA0003D6B0 /* AppDelegate.m in Sources */, 5831796D292EEEAA0003D6B0 /* main.m in Sources */, @@ -328,7 +339,7 @@ buildActionMask = 2147483647; files = ( 5806DE7529774E0700C18FFA /* ProductViewController.m in Sources */, - 58D52E3F292EDA1600CF32DE /* BuildFile in Sources */, + 58D52E3F292EDA1600CF32DE /* (null) in Sources */, 69CCAF5728DCDE57007620BD /* ViewController.m in Sources */, 69CCAF5128DCDE57007620BD /* AppDelegate.m in Sources */, 69CCAF6228DCDE5A007620BD /* main.m in Sources */, @@ -340,6 +351,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FBA017C92BFFE54400CB2969 /* XCTestCase+Extension.swift in Sources */, 69D3C14C299EF2D10027934F /* CreativeUITest.m in Sources */, FB51061A2BFE4A9700D9A72D /* XCUIElement+Extension.swift in Sources */, );