Skip to content

Commit

Permalink
Merge pull request #450 from Kommunicate-io/CM-2230
Browse files Browse the repository at this point in the history
[CM-2230] Automation 6 Sanity Task | iOS SDK
  • Loading branch information
kandpal025 authored Nov 8, 2024
2 parents e613857 + a36b95b commit 36754db
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Example/Kommunicate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
607FACEC1AFB9204008FA782 /* KommunicateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* KommunicateTests.swift */; };
63F0B99A18711F1213DF6677 /* Pods_Kommunicate_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3ACC731FA31F694014AFCD5 /* Pods_Kommunicate_Example.framework */; };
778B59CFD2A9AA01B2C8BB47 /* Pods_Kommunicate_ExampleUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C12430200CB714F7C6EC6DE /* Pods_Kommunicate_ExampleUITests.framework */; };
8213687C2CDA2CEE00B09F37 /* KommunicateConfigurationTesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8213687B2CDA2CEE00B09F37 /* KommunicateConfigurationTesting.swift */; };
8213687E2CDA332100B09F37 /* KommunicateLoginAndWelcomeMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8213687D2CDA332100B09F37 /* KommunicateLoginAndWelcomeMessage.swift */; };
8B33037F2226A494003BF306 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B33037E2226A494003BF306 /* LoginViewController.swift */; };
8B5BC12A22002FDC00F39956 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8B5BC12822002FDC00F39956 /* Localizable.strings */; };
8B8FFA9421D5171F00C8ED57 /* PaymentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B8FFA9321D5171F00C8ED57 /* PaymentTests.swift */; };
Expand Down Expand Up @@ -63,6 +65,8 @@
6C12430200CB714F7C6EC6DE /* Pods_Kommunicate_ExampleUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Kommunicate_ExampleUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
707E7F0040A81A7354816747 /* Pods-Kommunicate_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kommunicate_Example.debug.xcconfig"; path = "Target Support Files/Pods-Kommunicate_Example/Pods-Kommunicate_Example.debug.xcconfig"; sourceTree = "<group>"; };
78226602544E9745BB6CB084 /* Pods_Kommunicate_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Kommunicate_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8213687B2CDA2CEE00B09F37 /* KommunicateConfigurationTesting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KommunicateConfigurationTesting.swift; sourceTree = "<group>"; };
8213687D2CDA332100B09F37 /* KommunicateLoginAndWelcomeMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KommunicateLoginAndWelcomeMessage.swift; sourceTree = "<group>"; };
8AFCF2C4706B87B553819E20 /* Pods-Kommunicate_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kommunicate_Tests.debug.xcconfig"; path = "Target Support Files/Pods-Kommunicate_Tests/Pods-Kommunicate_Tests.debug.xcconfig"; sourceTree = "<group>"; };
8B33037E2226A494003BF306 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
8B5BC12422002C4000F39956 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -237,12 +241,14 @@
C698B49A24AB77D5008BB4D9 /* Kommunicate_ExampleUITests */ = {
isa = PBXGroup;
children = (
8213687B2CDA2CEE00B09F37 /* KommunicateConfigurationTesting.swift */,
C698B48F24AB76A5008BB4D9 /* KommunicateCreateConversationAndSendMessagesTests.swift */,
C698B48E24AB76A5008BB4D9 /* TestCaseInfo.swift */,
C698B49D24AB77D5008BB4D9 /* Info.plist */,
C67D56E724AE439A001BA419 /* KommunicateLoginAsVisitorUITests.swift */,
C6C24FE324C22E8B005B0A84 /* KommunicateRichMessageUITests.swift */,
C6EC7F3F24FAC01700AE7764 /* KommunicateFormRichMessageUITests.swift */,
8213687D2CDA332100B09F37 /* KommunicateLoginAndWelcomeMessage.swift */,
);
path = Kommunicate_ExampleUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -588,6 +594,8 @@
C698B4A424AB7803008BB4D9 /* KommunicateCreateConversationAndSendMessagesTests.swift in Sources */,
C67D56E824AE439A001BA419 /* KommunicateLoginAsVisitorUITests.swift in Sources */,
C698B4A324AB7803008BB4D9 /* TestCaseInfo.swift in Sources */,
8213687E2CDA332100B09F37 /* KommunicateLoginAndWelcomeMessage.swift in Sources */,
8213687C2CDA2CEE00B09F37 /* KommunicateConfigurationTesting.swift in Sources */,
C6EC7F4024FAC01700AE7764 /* KommunicateFormRichMessageUITests.swift in Sources */,
C6C24FE424C22E8B005B0A84 /* KommunicateRichMessageUITests.swift in Sources */,
);
Expand Down
4 changes: 4 additions & 0 deletions Example/Kommunicate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
var appId = ""

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
/// For Regex Automation Testing.
if let regexPattern = ProcessInfo.processInfo.environment["restrictedMessageRegexPattern"] {
Kommunicate.defaultConfiguration.restrictedMessageRegexPattern = regexPattern
}
setUpNavigationBarAppearance()

UNUserNotificationCenter.current().delegate = self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// KommunicateConfigurationTesting.swift
// Kommunicate_ExampleUITests
//
// Created by Abhijeet Ranjan on 04/11/24.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import XCTest

class KommunicateRegexConfigurationTesting: XCTestCase {
enum GroupData {
static let restrictedText = "This message is containg word restricted which is not allowed"
static let validText = "This messaga dosen't contain any regex word."
static let AppId = loginCreadentials.testAppID
static let fillUserId = loginCreadentials.userID
static let fillPassword = loginCreadentials.password
}

override func setUp() {
super.setUp()
continueAfterFailure = false
addUIInterruptionMonitor(withDescription: AppPermission.AlertMessage.accessNotificationInApplication) { alerts -> Bool in
if alerts.buttons[AppPermission.AlertButton.allow].exists {
alerts.buttons[AppPermission.AlertButton.allow].tap()
}
return true
}
let app = XCUIApplication()
app.launchEnvironment["restrictedMessageRegexPattern"] = Configuration.resgexPattern
if let appId = appIdFromEnvVars() {
app.launchArguments = [GroupData.AppId, appId]
}
app.launch()
sleep(5)
guard !XCUIApplication().scrollViews.otherElements.buttons[InAppButton.LaunchScreen.getStarted].exists else {
login()
return
}
}

func testRegexInChatBar() {
let appInstance = beforeTest_Launch_NewConversation()
waitFor(object: appInstance) { $0.exists }

appInstance.typeText(GroupData.restrictedText)
appInstance.buttons[InAppButton.ConversationScreen.send].tap()
sleep(3) // Wait for response

appInstance.buttons["Ok"].tap()

appInstance.typeText(GroupData.validText)
appInstance.buttons[InAppButton.ConversationScreen.send].tap()

let sendMessage = appInstance.tables[AppScreen.innerChatScreenTableView]
.textViews[GroupData.validText]
}


private func login() {
let path = Bundle(for: KommunicateRichMessageUITests.self).url(forResource: "Info", withExtension: "plist")
let dict = NSDictionary(contentsOf: path!) as? [String: Any]
let userId = GroupData.fillUserId
let password = GroupData.fillPassword
XCUIApplication().tap()
let elementsQuery = XCUIApplication().scrollViews.otherElements
let userIdTextField = elementsQuery.textFields[AppTextFeild.userId]
userIdTextField.tap()
userIdTextField.typeText(userId)
let passwordSecureTextField = elementsQuery.secureTextFields[AppTextFeild.password]
passwordSecureTextField.tap()
passwordSecureTextField.typeText(password)
elementsQuery.buttons[InAppButton.LaunchScreen.getStarted].tap()
}

private func beforeTest_Launch_NewConversation() -> (XCUIApplication) {
let app = XCUIApplication()
let launchConversationButton = app.buttons[InAppButton.EditGroup.launch]
waitFor(object: launchConversationButton) { $0.exists }
launchConversationButton.tap()
sleep(3)
// Check if the specific screen is on top
let isScreenOnTop = app.navigationBars[AppScreen.myChatScreen].exists

if isScreenOnTop {
// Perform actions only if the screen is not on top
let createConversationButton = app.navigationBars[AppScreen.myChatScreen]
waitFor(object: createConversationButton) { $0.exists }
createConversationButton.buttons[InAppButton.CreatingGroup.startNewIcon].tap()

let inputView = app.otherElements[AppScreen.chatBar].children(matching: .textView).matching(identifier: AppTextFeild.chatTextView).firstMatch
waitFor(object: inputView) { $0.exists }
inputView.tap()
inputView.tap()
inputView.tap()
} else {

let inputView = app.otherElements[AppScreen.chatBar].children(matching: .textView).matching(identifier: AppTextFeild.chatTextView).firstMatch
waitFor(object: inputView) { $0.exists }
inputView.tap()
inputView.tap()
inputView.tap()
}

return app
}

private func appIdFromEnvVars() -> String? {
let path = Bundle(for: KommunicateRichMessageUITests.self).url(forResource: "Info", withExtension: "plist")
let dict = NSDictionary(contentsOf: path!) as? [String: Any]
let appId = dict?[GroupData.AppId] as? String
return appId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// KommunicateLoginAndWelcomeMessage.swift
// Kommunicate_ExampleUITests
//
// Created by Abhijeet Ranjan on 05/11/24.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import XCTest

class KommunicateLoginAndWelcomeMessage: XCTestCase {
enum GroupData {
static let AppId = loginCreadentials.testAppID
static let fillUserId = loginCreadentials.userID
static let fillPassword = loginCreadentials.password
}

override func setUp() {
super.setUp()
continueAfterFailure = false
addUIInterruptionMonitor(withDescription: AppPermission.AlertMessage.accessNotificationInApplication) { alerts -> Bool in
if alerts.buttons[AppPermission.AlertButton.allow].exists {
alerts.buttons[AppPermission.AlertButton.allow].tap()
}
return true
}
let app = XCUIApplication()
if let appId = appIdFromEnvVars() {
app.launchArguments = [GroupData.AppId, appId]
}
app.launch()
sleep(5)
if app.buttons[InAppButton.LaunchScreen.logoutButton].exists {
app.buttons[InAppButton.LaunchScreen.logoutButton].tap()
}
guard !XCUIApplication().scrollViews.otherElements.buttons[InAppButton.LaunchScreen.getStarted].exists else {
login()
return
}
}

func testLoginAndCustomWelcomeMessage() {
let app = beforeTest_Launch_NewConversation()
waitFor(object: app) { $0.exists }
let innerchatscreentableviewTable = app.tables[AppScreen.innerChatScreenTableView]
let welcomMessageResponse = innerchatscreentableviewTable.textViews[RichMessageResponseText.customWelcomeMessage]
waitFor(object: welcomMessageResponse) { $0.exists }
}

private func beforeTest_Launch_NewConversation() -> (XCUIApplication) {
let app = XCUIApplication()
let launchConversationButton = app.buttons[InAppButton.EditGroup.launch]
waitFor(object: launchConversationButton) { $0.exists }
launchConversationButton.tap()
sleep(3)
// Check if the specific screen is on top
let isScreenOnTop = app.navigationBars[AppScreen.myChatScreen].exists

if isScreenOnTop {
// Perform actions only if the screen is not on top
let createConversationButton = app.navigationBars[AppScreen.myChatScreen]
waitFor(object: createConversationButton) { $0.exists }
createConversationButton.buttons[InAppButton.CreatingGroup.startNewIcon].tap()

let inputView = app.otherElements[AppScreen.chatBar].children(matching: .textView).matching(identifier: AppTextFeild.chatTextView).firstMatch
waitFor(object: inputView) { $0.exists }
inputView.tap()
inputView.tap()
inputView.tap()
} else {

let inputView = app.otherElements[AppScreen.chatBar].children(matching: .textView).matching(identifier: AppTextFeild.chatTextView).firstMatch
waitFor(object: inputView) { $0.exists }
inputView.tap()
inputView.tap()
inputView.tap()
}

return app
}

private func login() {
sleep(5)
let path = Bundle(for: KommunicateLoginAndWelcomeMessage.self).url(forResource: "Info", withExtension: "plist")
let dict = NSDictionary(contentsOf: path!) as? [String: Any]
let userId = GroupData.fillUserId
let password = GroupData.fillPassword
XCUIApplication().tap()
let elementsQuery = XCUIApplication().scrollViews.otherElements
let userIdTextField = elementsQuery.textFields[AppTextFeild.userId]
userIdTextField.tap()
userIdTextField.typeText(userId)
let passwordSecureTextField = elementsQuery.secureTextFields[AppTextFeild.password]
passwordSecureTextField.tap()
passwordSecureTextField.typeText(password)
elementsQuery.buttons[InAppButton.LaunchScreen.getStarted].tap()
}

private func appIdFromEnvVars() -> String? {
let path = Bundle(for: KommunicateLoginAndWelcomeMessage.self).url(forResource: "Info", withExtension: "plist")
let dict = NSDictionary(contentsOf: path!) as? [String: Any]
let appId = dict?[GroupData.AppId] as? String
return appId
}
}


5 changes: 5 additions & 0 deletions Example/Kommunicate_ExampleUITests/TestCaseInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ enum AppPermission {
}
}

enum Configuration {
static let resgexPattern = "restricted"
}

enum loginCreadentials {
static let testAppID = "<Enter-Your-AppID>" /// Enter your AppID here
static let userID = "<Enter-Your-UserID>" /// Enter your UserID for testing
Expand Down Expand Up @@ -95,6 +99,7 @@ enum RichMessageButtons {

enum RichMessageResponseText {
static let welcomeMessage = "Hi, how can we help you?"
static let customWelcomeMessage = "Hi \(loginCreadentials.userID), how can we help you?"
static let suggestedButtonResponse = "Cool! send me more."
static let linkButtonResponse = "Link Button Rich Message"
static let differentButtonResponse1 = "optional- this message will be used as acknowledgement text when user clicks the button"
Expand Down
Loading

0 comments on commit 36754db

Please sign in to comment.