Skip to content

Commit

Permalink
added UI Test for validating switch domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Espinola committed Jun 14, 2024
1 parent 2c83ada commit 35f5da1
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 2 deletions.
25 changes: 24 additions & 1 deletion Example/CreativeUITest/CreativeUITest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class CreativeUITest: XCTestCase, BaseXCTestCase {

HomePage
.tapOnPushMeToCreative()
.addDelay(seconds: 3)
.addDelay(seconds: 4)

CreativePage.tapOnCloseCreative()

Expand Down Expand Up @@ -96,6 +96,29 @@ final class CreativeUITest: XCTestCase, BaseXCTestCase {

HomePage.verifyPushMeToCreativeIsHittable()
}

func testLoadCreative_switchDomain_shouldDisplayNewCreative() {
launch(with: .production)

HomePage
.verifyDomainTitle(text: "mobileapps")
.tapOnSwitchDomain()

SwitchDomainPage
.verifyIfTitleExists()
.fillDomainInput(text: "games")
.tapOnOk()
.addDelay(seconds: 1)

HomePage
.verifyDomainTitle(text: "games")
.tapOnPushMeToCreative()
.addDelay(seconds: 4)

CreativePage
.verifyIfElementExists(label: "AttentiveGames", elementType: .image)
.tapOnCloseCreative()
}
}

extension CreativeUITest {
Expand Down
22 changes: 22 additions & 0 deletions Example/CreativeUITest/Pages/HomePage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ struct HomePage: Page {
productTabItem.tapOnElement()
return self
}

@discardableResult
static func tapOnSwitchDomain() -> Self.Type {
switchDomainButton.tapOnElement()
return self
}

@discardableResult
static func verifyDomainTitle(text: String) -> Self.Type {
let domainLabel = app.staticTexts["Domain: \(text)"]

guard domainLabel.elementExists() else {
XCTFail("Domain label does not exists")
return self
}

return self
}
}

fileprivate extension HomePage {
Expand All @@ -52,4 +70,8 @@ fileprivate extension HomePage {
static var productTabItem: XCUIElement {
app.tabBars.buttons["Product"]
}

static var switchDomainButton: XCUIElement {
app.buttons["Switch Domain"]
}
}
12 changes: 12 additions & 0 deletions Example/CreativeUITest/Pages/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ extension Page {
window.tap()
return self
}

@discardableResult
static func verifyIfElementExists(label: String, elementType: XCUIElement.ElementType) -> Self.Type {
let element = app.descendants(matching: elementType)[label]

guard element.elementExists() else {
XCTFail("Element with label \(label) of type \(elementType) does not exists")
return self
}

return self
}
}
58 changes: 58 additions & 0 deletions Example/CreativeUITest/Pages/SwitchDomainPage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// SwitchDomainPage.swift
// CreativeUITest
//
// Created by Vladimir - Work on 2024-06-14.
//

import XCTest

struct SwitchDomainPage: Page {
private init() { }

@discardableResult
static func tapOnOk() -> Self.Type {
okButton.tapOnElement()
return self
}

@discardableResult
static func tapOnCancel() -> Self.Type {
cancelButton.tapOnElement()
return self
}

@discardableResult
static func fillDomainInput(text: String) -> Self.Type {
domainTextField.tapOnElement()
domainTextField.fillTextField(text)
return self
}

@discardableResult
static func verifyIfTitleExists() -> Self.Type {
guard title.elementExists() else {
XCTFail("Title does not exists")
return self
}
return self
}
}

fileprivate extension SwitchDomainPage {
static var title: XCUIElement {
app.staticTexts["Switch Domain"]
}

static var domainTextField: XCUIElement {
app.textFields["Enter the new Domain here"]
}

static var okButton: XCUIElement {
app.buttons["OK"]
}

static var cancelButton: XCUIElement {
app.buttons["Cancel"]
}
}
4 changes: 4 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
69CCAF5C28DCDE5A007620BD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 69CCAF5B28DCDE5A007620BD /* Assets.xcassets */; };
69CCAF5F28DCDE5A007620BD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69CCAF5D28DCDE5A007620BD /* LaunchScreen.storyboard */; };
69CCAF6228DCDE5A007620BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 69CCAF6128DCDE5A007620BD /* main.m */; };
FB080C742C1C8AE500834BAA /* SwitchDomainPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB080C732C1C8AE500834BAA /* SwitchDomainPage.swift */; };
FB2F35B32C18D4CE0016CAE8 /* ATTNSDKFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB2F35B22C18D4CE0016CAE8 /* ATTNSDKFramework.framework */; };
FB2F35B42C18D4CE0016CAE8 /* ATTNSDKFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FB2F35B22C18D4CE0016CAE8 /* ATTNSDKFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
FB90EF122C10AE66004DFC4A /* CreativeUITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB90EF112C10AE66004DFC4A /* CreativeUITest.swift */; };
Expand Down Expand Up @@ -82,6 +83,7 @@
69CCAF6028DCDE5A007620BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
69CCAF6128DCDE5A007620BD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
69D3C149299EF2D10027934F /* CreativeUITest.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CreativeUITest.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
FB080C732C1C8AE500834BAA /* SwitchDomainPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchDomainPage.swift; sourceTree = "<group>"; };
FB2F35B22C18D4CE0016CAE8 /* ATTNSDKFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ATTNSDKFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FB6723742C134C13008D5516 /* Example - Pod-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Example - Pod-Bridging-Header.h"; sourceTree = "<group>"; };
FB90EF102C10AE66004DFC4A /* CreativeUITest-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CreativeUITest-Bridging-Header.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -211,6 +213,7 @@
FB90EF1F2C10CF13004DFC4A /* SMSPage.swift */,
FB90EF212C10D412004DFC4A /* PricacyPolicyPage.swift */,
FB90EF232C10D83B004DFC4A /* ProductPage.swift */,
FB080C732C1C8AE500834BAA /* SwitchDomainPage.swift */,
);
path = Pages;
sourceTree = "<group>";
Expand Down Expand Up @@ -392,6 +395,7 @@
FB90EF202C10CF13004DFC4A /* SMSPage.swift in Sources */,
FB90EF152C10B871004DFC4A /* HomePage.swift in Sources */,
FB90EF122C10AE66004DFC4A /* CreativeUITest.swift in Sources */,
FB080C742C1C8AE500834BAA /* SwitchDomainPage.swift in Sources */,
FB90EF1C2C10B959004DFC4A /* XCUIElement+Extension.swift in Sources */,
FB90EF172C10B887004DFC4A /* BaseXCTestCase.swift in Sources */,
FB90EF222C10D412004DFC4A /* PricacyPolicyPage.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (void)viewDidLoad {
[super viewDidLoad];

// Replace with your Attentive domain to test with your Attentive account
_domain = @"mobileapps";
_domain = @"YOUR_ATTENTIVE_DOMAIN";
_mode = @"production";

// Setup for Testing purposes only
Expand Down

0 comments on commit 35f5da1

Please sign in to comment.