Skip to content

Commit

Permalink
Added UI Test for Custom Welcome Message
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhijeetRanjan308 committed Nov 5, 2024
1 parent 69ff6da commit a36b95b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Example/Kommunicate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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 @@ -65,6 +66,7 @@
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 @@ -246,6 +248,7 @@
C67D56E724AE439A001BA419 /* KommunicateLoginAsVisitorUITests.swift */,
C6C24FE324C22E8B005B0A84 /* KommunicateRichMessageUITests.swift */,
C6EC7F3F24FAC01700AE7764 /* KommunicateFormRichMessageUITests.swift */,
8213687D2CDA332100B09F37 /* KommunicateLoginAndWelcomeMessage.swift */,
);
path = Kommunicate_ExampleUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -591,6 +594,7 @@
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
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
}
}


1 change: 1 addition & 0 deletions Example/Kommunicate_ExampleUITests/TestCaseInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,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

0 comments on commit a36b95b

Please sign in to comment.