Skip to content

Commit

Permalink
added delete app method
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Espinola committed May 23, 2024
1 parent 0fe263f commit f0efbb3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
16 changes: 10 additions & 6 deletions Example/CreativeUITest/CreativeUITest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}


Expand All @@ -60,7 +64,7 @@ - (void)testLoadCreative_fillOutFormAndSubmit_launchesSmsAppWithPrePopulatedText
// Fill in the email
XCUIElement *emailField = app.webViews.textFields[@"Email Address"];
[emailField tapOnElement];
[emailField typeText:@"[email protected]"];
[emailField fillTextField:@"[email protected]"];

// Tap something else on the creative to dismiss the keyboard
[app.staticTexts[@"10% OFF"] tapOnElement];
Expand Down Expand Up @@ -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];
Expand All @@ -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"];
}
Expand Down
24 changes: 24 additions & 0 deletions Example/CreativeUITest/Extensions/XCTestCase+Extension.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 17 additions & 5 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand All @@ -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 */
Expand Down Expand Up @@ -79,6 +80,7 @@
69D3C14B299EF2D10027934F /* CreativeUITest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CreativeUITest.m; sourceTree = "<group>"; };
FB5106182BFE4A9700D9A72D /* CreativeUITest-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CreativeUITest-Bridging-Header.h"; sourceTree = "<group>"; };
FB5106192BFE4A9700D9A72D /* XCUIElement+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIElement+Extension.swift"; sourceTree = "<group>"; };
FBA017C82BFFE54400CB2969 /* XCTestCase+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTestCase+Extension.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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;
Expand All @@ -184,6 +186,15 @@
path = Pods;
sourceTree = "<group>";
};
FBA017CA2BFFE70500CB2969 /* Extensions */ = {
isa = PBXGroup;
children = (
FB5106192BFE4A9700D9A72D /* XCUIElement+Extension.swift */,
FBA017C82BFFE54400CB2969 /* XCTestCase+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
);
Expand Down

0 comments on commit f0efbb3

Please sign in to comment.