// C o p y r i g h t © 2 0 1 5 A b h i s h e k B a n t h i a
import XCTest
let CLOnboaringTestsLaunchArgument = " isTestingTheOnboardingFlow "
class OnboardingTests : XCTestCase {
var app : XCUIApplication !
override func setUp ( ) {
continueAfterFailure = false
app = XCUIApplication ( )
app . launchArguments . append ( CLOnboaringTestsLaunchArgument )
app . launch ( )
}
// W e t e s t a c o u p l e o f t h i n g s i n t h e O n b o a r d i n g P r o c e s s
// 1 . T h e f l o w ( f o r w a r d b u t t o n a n d b a c k b u t t o n t a k e t h e u s e r t o t h e c o r r e c t s c r e e n )
// 2 . S t a t i c t e x t s a n d b u t t o n t i t l e ' s a r e a p p r o p r i a t e
func testForwardButton ( ) {
welcomeControllerTests ( )
// L e t ' s g o t o t h e P e r m i s s i o n s V i e w
moveForward ( )
permissionsControllerTests ( )
// T i m e t o t e s t t h e l a u n c h A t L o g i n V i e w
moveForward ( )
startupControllerTests ( )
// L e t ' s g o t o O n b o a r d i n g S e a r c h C o n t r o l l e r
moveForward ( )
searchControllerTests ( )
// L e t ' s g o t o t h e F i n a l O n b o a r d i n g C o n t r o l l e r
moveForward ( )
finalOnboardingControllerTests ( )
backButtonTests ( )
}
func backButtonTests ( ) {
moveBackward ( )
searchControllerTests ( )
moveBackward ( )
startupControllerTests ( )
moveBackward ( )
permissionsControllerTests ( )
moveBackward ( )
welcomeControllerTests ( )
alternateStartupFlowTests ( )
}
func alternateStartupFlowTests ( ) {
// L e t ' s g o t o t h e P e r m i s s i o n s V i e w
moveForward ( )
permissionsControllerTests ( )
// T i m e t o t e s t t h e l a u n c h A t L o g i n V i e w
moveForward ( )
startupControllerTests ( )
// L e t ' s g o t o O n b o a r d i n g S e a r c h C o n t r o l l e r
alternateMoveForward ( )
searchControllerTests ( )
// L e t ' s g o t o t h e F i n a l O n b o a r d i n g C o n t r o l l e r
moveForward ( )
finalOnboardingControllerTests ( )
moveForward ( )
XCTAssertTrue ( app . statusItems . count > 0 , " Status item was not installed in the menubar " )
}
private func moveForward ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
onboardingWindow . buttons [ " Forward " ] . click ( )
sleep ( 1 )
}
private func alternateMoveForward ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
onboardingWindow . buttons [ " Alternate " ] . click ( )
sleep ( 1 )
}
private func moveBackward ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
onboardingWindow . buttons [ " Backward " ] . click ( )
sleep ( 1 )
}
private func welcomeControllerTests ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
// T e s t s s t a t i c t e x t s
XCTAssertTrue ( onboardingWindow . staticTexts [ " Clocker " ] . exists , " Static text Clocker was unexpectedly missing " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " It only takes 3 steps to set up Clocker. " ] . exists , " Accessory label's static text was unexpectedly wrong. " )
let button = onboardingWindow . buttons [ " Forward " ]
// T e s t t h e b u t t o n t i t l e
XCTAssertTrue ( button . exists , " Button title was unexpectedly wrong. Expected \" Get Started \" , Actual: \" \( onboardingWindow . buttons . firstMatch . title ) \" " )
XCTAssertTrue ( onboardingWindow . buttons . count = = 1 , " More than 1 button on Welcome screen! " )
}
private func permissionsControllerTests ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
XCTAssertTrue ( onboardingWindow . staticTexts [ " Permissions " ] . exists , " Header label's static text was unexpectedly wrong. " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " These can be configured later in System Preferences. " ] . exists , " Onboarding Info label's static text was unexpectedly wrong. " )
XCTAssertTrue ( onboardingWindow . buttons [ " Forward " ] . title = = " Continue " , " Forward button title's was unexpectedly wrong " )
XCTAssertTrue ( onboardingWindow . buttons [ " Backward " ] . exists , " Back button was unexpectedly missing " )
XCTAssertFalse ( onboardingWindow . buttons [ " Alternate " ] . exists , " Alternate button was unexpectedly present. " )
}
private func startupControllerTests ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
XCTAssertTrue ( onboardingWindow . buttons [ " Forward " ] . title = = " Open Clocker At Login " , " Forward button title's was unexpectedly wrong " )
XCTAssertTrue ( onboardingWindow . buttons [ " Alternate " ] . title = = " Don't Open " , " Alternate button title's was unexpectedly wrong " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " Launch at Login " ] . exists , " Header label's static text was unexpectedly wrong. " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " Should Clocker open automatically on startup? " ] . exists , " Accessory label's static text was unexpectedly wrong. " )
}
private func searchControllerTests ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
XCTAssertFalse ( onboardingWindow . buttons [ " Alternate " ] . exists , " Alternate button was unexpectedly present. " )
XCTAssertTrue ( onboardingWindow . buttons [ " Forward " ] . title = = " Continue " , " Forward button title's was unexpectedly wrong " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " Quick Add Locations " ] . exists , " Header label's static text was unexpectedly wrong. " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " More search options in Clocker Preferences. " ] . exists , " Accessory label's static text was unexpectedly wrong. " )
}
private func finalOnboardingControllerTests ( ) {
let onboardingWindow = app . windows [ " OnboardingWindow " ]
// L e t ' s t e s t t h e b u t t o n s
XCTAssertTrue ( onboardingWindow . staticTexts [ " You're all set! " ] . exists , " Header label's static text was unexpectedly wrong. " )
XCTAssertTrue ( onboardingWindow . staticTexts [ " Thank you for the details. " ] . exists , " Accessory label's static text was unexpectedly wrong. " )
XCTAssertFalse ( onboardingWindow . buttons [ " Alternate " ] . exists , " Alternate button was unexpectedly present. " )
XCTAssertTrue ( onboardingWindow . buttons [ " Forward " ] . title = = " Launch Clocker " , " Forward button's title was unexpectedly wrong. " )
}
}