diff --git a/Example/CreativeUITest/CreativeUITest.swift b/Example/CreativeUITest/CreativeUITest.swift index 6fc9fe6..8af0c3f 100644 --- a/Example/CreativeUITest/CreativeUITest.swift +++ b/Example/CreativeUITest/CreativeUITest.swift @@ -30,7 +30,7 @@ final class CreativeUITest: XCTestCase, BaseXCTestCase { HomePage .tapOnPushMeToCreative() - .addDelay(seconds: 3) + .addDelay(seconds: 4) CreativePage.tapOnCloseCreative() @@ -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 { diff --git a/Example/CreativeUITest/Pages/HomePage.swift b/Example/CreativeUITest/Pages/HomePage.swift index d81226f..c70f94c 100644 --- a/Example/CreativeUITest/Pages/HomePage.swift +++ b/Example/CreativeUITest/Pages/HomePage.swift @@ -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 { @@ -52,4 +70,8 @@ fileprivate extension HomePage { static var productTabItem: XCUIElement { app.tabBars.buttons["Product"] } + + static var switchDomainButton: XCUIElement { + app.buttons["Switch Domain"] + } } diff --git a/Example/CreativeUITest/Pages/Page.swift b/Example/CreativeUITest/Pages/Page.swift index 309390c..eb1fcbb 100644 --- a/Example/CreativeUITest/Pages/Page.swift +++ b/Example/CreativeUITest/Pages/Page.swift @@ -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 + } } diff --git a/Example/CreativeUITest/Pages/SwitchDomainPage.swift b/Example/CreativeUITest/Pages/SwitchDomainPage.swift new file mode 100644 index 0000000..d2c9e82 --- /dev/null +++ b/Example/CreativeUITest/Pages/SwitchDomainPage.swift @@ -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"] + } +} diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index a17d584..e6f9499 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -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 */; }; @@ -82,6 +83,7 @@ 69CCAF6028DCDE5A007620BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 69CCAF6128DCDE5A007620BD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; FB90EF102C10AE66004DFC4A /* CreativeUITest-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CreativeUITest-Bridging-Header.h"; sourceTree = ""; }; @@ -211,6 +213,7 @@ FB90EF1F2C10CF13004DFC4A /* SMSPage.swift */, FB90EF212C10D412004DFC4A /* PricacyPolicyPage.swift */, FB90EF232C10D83B004DFC4A /* ProductPage.swift */, + FB080C732C1C8AE500834BAA /* SwitchDomainPage.swift */, ); path = Pages; sourceTree = ""; @@ -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 */, diff --git a/Example/Example/ViewController.m b/Example/Example/ViewController.m index e41e2f4..caafe09 100644 --- a/Example/Example/ViewController.m +++ b/Example/Example/ViewController.m @@ -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