Skip to content

Commit

Permalink
Added test case for form and open perticular conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhijeetRanjan308 committed Nov 20, 2024
1 parent 36754db commit 6a3b16e
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import XCTest

class KommunicateFormRichMessageUITests: XCTestCase {
enum GroupData {
static let typeText = "Form"
static let typeText1 = "Form Template 1"
static let typeText2 = "Form Template 2"
static let typeText3 = "Form Template 3"
static let AppId = loginCreadentials.testAppID
static let fillUserId = loginCreadentials.userID
static let fillPassword = loginCreadentials.password
Expand All @@ -37,48 +39,116 @@ class KommunicateFormRichMessageUITests: XCTestCase {
}
}

func testFormTemplate() {
func testFormTemplate1() {
let app = beforeTest_Launch_NewConversation()
waitFor(object: app) { $0.exists }

app.typeText(GroupData.typeText) // typing message
sleep(4)
app.typeText(GroupData.typeText1) // typing message
app.buttons[InAppButton.ConversationScreen.send].tap() // sending message in group
let formFirstResponse = app.tables[AppScreen.innerChatScreenTableView]
.textViews[RichMessageResponseText.formFirstResponse]
waitFor(object: formFirstResponse) { $0.exists }
let nameField = app.tables.textFields[FormIdentifier.name]
let passwordField = app.tables.secureTextFields[FormIdentifier.password]
waitFor(object: nameField) { $0.exists }
nameField.tap()
nameField.typeText(FormData.name)
passwordField.tap()
passwordField.typeText(FormData.password)
let innerchatscreentableviewTable = app.tables[AppScreen.innerChatScreenTableView]
innerchatscreentableviewTable.staticTexts[RichMessageButtons.male].tap()
innerchatscreentableviewTable.staticTexts[RichMessageButtons.metal].tap()
innerchatscreentableviewTable.staticTexts[RichMessageButtons.pop].tap()
app.tables[AppScreen.innerChatScreenTableView].staticTexts[RichMessageButtons.submit].tap()
let submitResponse = innerchatscreentableviewTable.textViews[RichMessageResponseText.formTemplateResponse]
let submitResponse = innerchatscreentableviewTable.textViews[RichMessageResponseText.formTemplateResponse1]
waitFor(object: submitResponse) { $0.exists }
}


func testFormTemplate2() {
let app = beforeTest_Launch_NewConversation()
waitFor(object: app) { $0.exists }
sleep(4)
app.typeText(GroupData.typeText2) // typing message
app.buttons[InAppButton.ConversationScreen.send].tap() // sending message in group
let formFirstResponse = app.tables[AppScreen.innerChatScreenTableView]
.textViews[RichMessageResponseText.formFirstResponse]
waitFor(object: formFirstResponse) { $0.exists }
let nameField = app.tables.textFields[FormIdentifier.name]
let passwordField = app.tables.secureTextFields[FormIdentifier.password]
let emailField = app.tables.textFields[FormIdentifier.email]
let phoneField = app.tables.textFields[FormIdentifier.phoneNumber]
let addressField = app.tables.textFields[FormIdentifier.address]
waitFor(object: nameField) { $0.exists }
nameField.tap()
nameField.typeText(FormData.name)
passwordField.tap()
passwordField.typeText(FormData.password)
emailField.tap()
emailField.typeText(FormData.email)
phoneField.tap()
phoneField.typeText(FormData.phoneNumber)
addressField.tap()
addressField.typeText(FormData.address)
let innerchatscreentableviewTable = app.tables[AppScreen.innerChatScreenTableView]
app.tables[AppScreen.innerChatScreenTableView].staticTexts[RichMessageButtons.submit].tap()
let submitResponse = innerchatscreentableviewTable.textViews[RichMessageResponseText.formTemplateResponse2]
waitFor(object: submitResponse) { $0.exists }
}

func testFormTemplate3() {
let app = beforeTest_Launch_NewConversation()
waitFor(object: app) { $0.exists }
sleep(4)
app.typeText(GroupData.typeText3) // typing message
app.buttons[InAppButton.ConversationScreen.send].tap() // sending message in group
let formFirstResponse = app.tables[AppScreen.innerChatScreenTableView]
.textViews[RichMessageResponseText.formFirstResponse]
waitFor(object: formFirstResponse) { $0.exists }
let nameField = app.tables.textFields[FormIdentifier.name]
let passwordField = app.tables.secureTextFields[FormIdentifier.password]
waitFor(object: nameField) { $0.exists }
nameField.tap()
nameField.typeText(FormData.name)
passwordField.tap()
passwordField.typeText(FormData.password)

let dateField = app.tables.textFields[FormIdentifier.dateTime]
dateField.tap()
sleep(1)
app.buttons[InAppButton.ConversationScreen.doneButton].tap()
sleep(1)
let innerchatscreentableviewTable = app.tables[AppScreen.innerChatScreenTableView]
innerchatscreentableviewTable.staticTexts[RichMessageButtons.male].tap()
app.tables[AppScreen.innerChatScreenTableView].staticTexts[RichMessageButtons.submit].tap()
let submitResponse = innerchatscreentableviewTable.textViews[RichMessageResponseText.formTemplateResponse1]
waitFor(object: submitResponse) { $0.exists }
}

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

private func beforeTest_Launch_NewConversation() -> (XCUIApplication) {
let app = XCUIApplication()
if app.buttons[InAppButton.LaunchScreen.logoutButton].exists {
app.buttons[InAppButton.LaunchScreen.logoutButton].tap()
sleep(5)
let loginAsVisitorButton = app.scrollViews.otherElements
loginAsVisitorButton.buttons[InAppButton.LaunchScreen.loginAsVisitor].tap()
}
sleep(5)
let loginAsVisitorButton = app.scrollViews.otherElements
loginAsVisitorButton.buttons[InAppButton.LaunchScreen.loginAsVisitor].tap()

let launchConversationButton = app.buttons[InAppButton.EditGroup.launch]
waitFor(object: launchConversationButton) { $0.exists }
launchConversationButton.tap()
Expand Down
21 changes: 20 additions & 1 deletion Example/Kommunicate_ExampleUITests/TestCaseInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum InAppButton {
static let openLocation = "locationButtonInConversationScreen"
static let sendLocation = "Send Location"
static let done = "Done"
static let doneButton = "DONE"
static let back = "Back"
static let backButton = "BackButton"
static let faqButton = "FAQ"
Expand All @@ -83,6 +84,23 @@ enum AppTextFeild {
static let Helpcenter = "Helpcenter | Helpcenter"
}

enum FormData {
static let name = "Alex Williams"
static let password = "12345678"
static let email = "alex@gmail.com"
static let phoneNumber = "1234567890"
static let address = "123 Maplewood Avenue, Apt 4B, Springfield, IL 62704, USA"
}

enum FormIdentifier {
static let name = "Enter your name"
static let password = "Enter your password"
static let email = "Enter your email"
static let phoneNumber = "Enter your phone number"
static let address = "Enter your address"
static let dateTime = "dd/MM/yyyy, hh:mm a"
}

enum RichMessageButtons {
static let button = "Button"
static let goToGoogle = "Go To Google"
Expand All @@ -105,7 +123,8 @@ enum RichMessageResponseText {
static let differentButtonResponse1 = "optional- this message will be used as acknowledgement text when user clicks the button"
static let differentButtonResponse2 = "text will be sent as message"
static let submitButtonResponse = "optional, will be used as acknowledgement message to user in case of requestType JSON. Default value is same as name parameter"
static let formTemplateResponse = "optional- this message will be used as acknowledgement text when user clicks the button"
static let formTemplateResponse1 = "optional- this message will be used as acknowledgement text when user clicks the button"
static let formTemplateResponse2 = "Thank you for submitting your details!"
static let imageResponse = "IRON MAN"
static let listTemplateResponse = "List template Rich Message"
static let singleCardResponse = "Single card template"
Expand Down
39 changes: 39 additions & 0 deletions Example/Tests/KommunicateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,45 @@ class KommunicateTests: XCTestCase {
}
}

func testOpenPerticularConversation() {
KommunicateMock.applozicClientType = ApplozicClientMock.self
let expectation = self.expectation(description: "Completion handler called")

// Dummy View Controller For Testing
let dummyViewController = UIViewController()
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = dummyViewController
window.makeKeyAndVisible()

let kmConversation = KMConversationBuilder()
.useLastConversation(false)
.withMetaData(["TestMetadata": "SampleValue"])
.withConversationTitle("Automation Conversation")
.build()

KommunicateMock.createConversation(conversation: kmConversation) { result in
switch result {
case .success(let conversationId):
print("Conversation created with ID: \(conversationId)")
KommunicateMock.showConversationWith(groupId: conversationId, from: dummyViewController) { response in
print("Show conversation response: \(response)")
if !response {
XCTFail("Conversation opening Failed")
expectation.fulfill()
return
}
XCTAssertTrue(true)
expectation.fulfill()
}
case .failure(let kmConversationError):
XCTAssertNotNil(kmConversationError, "Conversation creation failed")
expectation.fulfill()
}
}

waitForExpectations(timeout: 30)
}

func testUpdateConversationFunction() {
KommunicateMock.applozicClientType = ApplozicClientMock.self
let expectation = self.expectation(description: "Completion handler called")
Expand Down

0 comments on commit 6a3b16e

Please sign in to comment.