Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

test: UI tests for Login and Sign Up screens #99

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
12 changes: 10 additions & 2 deletions mentorship ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
53A6DDEE24BE512D00D5DFCE /* SignUpViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A6DDEB24BE512D00D5DFCE /* SignUpViewModelTests.swift */; };
53C0206D249B88370000BEB5 /* ProfileProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53C0206C249B88370000BEB5 /* ProfileProperties.swift */; };
53C0206F249B8D270000BEB5 /* ProfileCommonDetailsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53C0206E249B8D270000BEB5 /* ProfileCommonDetailsSection.swift */; };
53CCE7BE24BF94BB00F1FC55 /* LoginScreenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53CCE7BD24BF94BB00F1FC55 /* LoginScreenTests.swift */; };
53CCE7C024BF990500F1FC55 /* SignUpScreenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53CCE7BF24BF990500F1FC55 /* SignUpScreenTests.swift */; };
53D127B1249C956A003B4756 /* ActivityWithText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D127B0249C956A003B4756 /* ActivityWithText.swift */; };
53D24E0A2499F4C40043C28F /* RelationDetailList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D24E092499F4C40043C28F /* RelationDetailList.swift */; };
53D24E0C2499F4FC0043C28F /* DetailListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D24E0B2499F4FC0043C28F /* DetailListCell.swift */; };
Expand Down Expand Up @@ -150,6 +152,8 @@
53A6DDEB24BE512D00D5DFCE /* SignUpViewModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpViewModelTests.swift; sourceTree = "<group>"; };
53C0206C249B88370000BEB5 /* ProfileProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileProperties.swift; sourceTree = "<group>"; };
53C0206E249B8D270000BEB5 /* ProfileCommonDetailsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCommonDetailsSection.swift; sourceTree = "<group>"; };
53CCE7BD24BF94BB00F1FC55 /* LoginScreenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreenTests.swift; sourceTree = "<group>"; };
53CCE7BF24BF990500F1FC55 /* SignUpScreenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpScreenTests.swift; sourceTree = "<group>"; };
53D127B0249C956A003B4756 /* ActivityWithText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityWithText.swift; sourceTree = "<group>"; };
53D24E092499F4C40043C28F /* RelationDetailList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RelationDetailList.swift; sourceTree = "<group>"; };
53D24E0B2499F4FC0043C28F /* DetailListCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailListCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -277,6 +281,8 @@
isa = PBXGroup;
children = (
530F44382482752600B1FD0B /* MentorshipUITests.swift */,
53CCE7BD24BF94BB00F1FC55 /* LoginScreenTests.swift */,
53CCE7BF24BF990500F1FC55 /* SignUpScreenTests.swift */,
530F443A2482752600B1FD0B /* Info.plist */,
);
path = "mentorship iosUITests";
Expand Down Expand Up @@ -721,6 +727,8 @@
buildActionMask = 2147483647;
files = (
530F44392482752600B1FD0B /* MentorshipUITests.swift in Sources */,
53CCE7C024BF990500F1FC55 /* SignUpScreenTests.swift in Sources */,
53CCE7BE24BF94BB00F1FC55 /* LoginScreenTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -890,7 +898,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "yugantarjain.mentorship-ios";
PRODUCT_BUNDLE_IDENTIFIER = org.anitab.mentorship;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -910,7 +918,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "yugantarjain.mentorship-ios";
PRODUCT_BUNDLE_IDENTIFIER = org.anitab.mentorship;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
65 changes: 65 additions & 0 deletions mentorship iosUITests/LoginScreenTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// LoginScreenTests.swift
// Created on 16/07/20
// Created for AnitaB.org Mentorship-iOS
//

import XCTest
import Foundation

class LoginScreenTests: XCTestCase {
let app = XCUIApplication()

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
// Makes sure we're on the login screen. Changes userdefault bool value for isLoggedIn.
app.launchArguments += ["-isLoggedIn", "NO"]
// Launch
app.launch()

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
app.terminate()
}

func testLoginButtonWithEmptyFields() {
// Login Button should be hittable
XCTAssert(app.buttons["Login"].isHittable)

// Initial state. Fields empty. Login button should be disabled.
XCTAssert(app.buttons["Login"].isEnabled == false)
}

func testLoginButtonWithFilledFields() {
// Tap on username text field and enter text
app.textFields["Username/Email"].tap()
app.textFields["Username/Email"].typeText("Test Username")

// Tap on password field and enter text
app.secureTextFields["Password"].tap()
app.secureTextFields["Password"].typeText("Test Password")

// Fields filled. The login button should be enabled now.
XCTAssert(app.buttons["Login"].isEnabled)
}

func testSignUpButton() {
// Sign Up button should be hittable/visible
XCTAssert(app.buttons["Signup"].isHittable)

// Tap on Sign Up button
app.buttons["Signup"].tap()

// Sign Up view should be visible now. Navigation bar should have Sign Up title.
XCTAssert(app.navigationBars["Sign Up"].isHittable)
}

}
101 changes: 101 additions & 0 deletions mentorship iosUITests/SignUpScreenTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// SignUpScreenTests.swift
// Created on 16/07/20
// Created for AnitaB.org Mentorship-iOS
//

import XCTest

class SignUpScreenTests: XCTestCase {
let app = XCUIApplication()

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
// Makes sure we're on the login screen. Changes userdefault bool value for isLoggedIn.
app.launchArguments += ["-isLoggedIn", "NO"]
// Launch
app.launch()
// Go to sign up screen
app.buttons["Signup"].tap()
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCUIApplication should be terminated here in teardown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in the other.. one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

app.terminate()
}

// Sign Up button should be disabled if even a single field is empty or tnc is unchecked.
// This test tests all the cases.
func testSignUpButtonWithEmptyFields() {
// Sign Up button should be hittable
XCTAssert(app.scrollViews.otherElements.buttons["Sign Up"].isHittable)

// MARK: - Initial State. All fields empty.
// Sign Up button should be disabled.
XCTAssert(app.scrollViews.otherElements.buttons["Sign Up"].isEnabled == false)

// MARK: - Name text field filled. Other fields empty.
// Tap Name text field and fill some text
app.scrollViews.otherElements.textFields["Name"].tap()
app.scrollViews.otherElements.textFields["Name"].typeText("Test Name")
// Sign Up button should be disabled.
XCTAssert(app.scrollViews.otherElements.buttons["Sign Up"].isEnabled == false)

// Return keyboard
app.keyboards.buttons["Return"].tap()

// MARK: - Check terms and conditions. Text fields still empty (except name)
app.scrollViews.otherElements.switches["Terms and Conditions"].tap()
// Terms and conditions toggle should be on.
XCTAssertEqual(app.scrollViews.otherElements.switches["Terms and Conditions"].value as? String, "1")
// Sign Up button should be disabled.
XCTAssert(app.scrollViews.otherElements.buttons["Sign Up"].isEnabled == false)
}

// The sign up button should enable once all the fields are filled and tnc is checked.
func testSignUpButtonWithFilledFields() {
// MARK: - Filled fields. But tnc unchecked.
// Text fields should be hittable. Check Name field for this purpose.
XCTAssert(app.scrollViews.otherElements.textFields["Name"].isHittable)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another inconsistency found.
Commenting out line 64 (XCTAssert(app.scrollViews.otherElements.textFields["Name"].isHittable) fails the test. Ideally, it shouldn't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it on popup screen?

Copy link
Contributor Author

@yugantarjain yugantarjain Jul 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is on sign up screen (modal screen). However, unlike the dismiss x button test, this involves a single screen only.

// Fill all text fields
app.scrollViews.otherElements.textFields["Name"].tap()
app.scrollViews.otherElements.textFields["Name"].typeText("Test")
app.scrollViews.otherElements.textFields["Username"].tap()
app.scrollViews.otherElements.textFields["Username"].typeText("Test")
app.scrollViews.otherElements.textFields["Email"].tap()
app.scrollViews.otherElements.textFields["Email"].typeText("Test")
app.scrollViews.otherElements.secureTextFields["Password"].tap()
app.scrollViews.otherElements.secureTextFields["Password"].typeText("Test")
app.scrollViews.otherElements.secureTextFields["Confirm Password"].tap()
app.scrollViews.otherElements.secureTextFields["Confirm Password"].typeText("Test")
// Return keyboard
app.keyboards.buttons["Return"].tap()
// Sign Up button should be disabled.
XCTAssert(app.scrollViews.otherElements.buttons["Sign Up"].isEnabled == false)

// MARK: - Check terms and conditions. Now, all requirements fulfilled.
app.scrollViews.otherElements.switches["Terms and Conditions"].tap()
// Terms and conditions toggle should be on.
XCTAssertEqual(app.scrollViews.otherElements.switches["Terms and Conditions"].value as? String, "1")
// Sign Up button should be enabled!!
XCTAssert(app.scrollViews.otherElements.buttons["Sign Up"].isEnabled)
}

// The 'x' button on navigation bar should dismiss sheet and login view should be visible.
func testDismissXButton() {
// 'x' button to dismiss should be visible
XCTAssert(app.navigationBars["Sign Up"].buttons["x.circle.fill"].isHittable)
// Press 'x' button
app.navigationBars["Sign Up"].buttons["x.circle.fill"].tap()
// Sheet should dismiss. Hence, login view should be visible.
// Without this line, test fails. SwiftUI UI test inconsistency maybe.
app.textFields["Username/Email"].tap()
XCTAssert(app.buttons["Login"].isHittable)
}

}