Created
August 20, 2015 08:47
-
-
Save peterlafferty/683a0e5595a2dab1e886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITests.swift | |
// UITests | |
// | |
// Created by Peter Lafferty on 19/08/2015. | |
// Copyright © 2015 Web Reservations International. All rights reserved. | |
// | |
import XCTest | |
class UITests: XCTestCase { | |
override func setUp() { | |
super.setUp() | |
// 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. | |
XCUIApplication().launchArguments = ["-AppleLocale es", "-AppleLanguages (es)"] | |
XCUIApplication().launch() | |
sleep(2) | |
} | |
override func tearDown() { | |
// Put teardown code here. This method is called after the invocation of each test method in the class. | |
super.tearDown() | |
} | |
func testExample() { | |
let app = XCUIApplication() | |
app.otherElements["searchDestinationButton"].tap() | |
app.searchFields["Where do you want to go?"].typeText("Dublin") | |
app.tables["searchSuggestionsTable"].staticTexts["Dublin, Ireland"].tap() | |
app.buttons["Search"].tap() | |
app.tables["searchResultsTableView"].cells["Cell 0"].tap() | |
app.buttons["Choose Room"].tap() | |
let tablesQuery = app.tables | |
tablesQuery.cells["4 Bed Female Dorm"].childrenMatchingType(.Button).matchingIdentifier("4 Bed Female Dorm").elementBoundByIndex(1).tap() | |
tablesQuery.staticTexts["1 Bed"].tap() | |
app.buttons["Book Now"].pressForDuration(0.8); | |
} | |
func testCustomerService() { | |
let app = XCUIApplication() | |
app.buttons["Menu"].tap() | |
app.buttons["menuSettings"].tap() | |
let tablesQuery = app.tables | |
tablesQuery.staticTexts["Help"].tap() | |
tablesQuery.staticTexts["Customer Service"].tap() | |
sleep(1) | |
//tablesQuery.textFields["helpEmailField"].typeText("peter") | |
app.navigationBars["Contact Customer Service"].buttons["Send"].tap() | |
} | |
func testSignin() { | |
let app = XCUIApplication() | |
app.buttons["Menu"].tap() | |
//if signed in then sign out | |
if app.buttons["Sign out"].exists { | |
app.buttons["Sign out"].tap() | |
app.alerts[" "].collectionViews.buttons["OK"].tap() | |
} | |
let signInButton = app.buttons["Sign in"] | |
signInButton.tap() | |
let usernameEmailTextField = app.textFields["username/email"] | |
usernameEmailTextField.tap() | |
usernameEmailTextField.typeText("peter.lafferty@hostelworld.com") | |
let passwordSecureTextField = app.secureTextFields["password"] | |
passwordSecureTextField.tap() | |
passwordSecureTextField.typeText("password") | |
app.buttons["Sign in"].tap() | |
XCTAssertEqual(app.buttons["Sign out"].exists, true, "User should be signed in and I should see the sign out button") | |
XCTAssertEqual(app.staticTexts["Peter Lafferty"].exists, true, "The user name of the person signed in should be visible") | |
} | |
func testSettings() { | |
let app = XCUIApplication() | |
app.buttons["Menu"].tap() | |
app.buttons["Settings"].tap() | |
let tablesQuery = app.tables | |
tablesQuery.staticTexts["US Dollar ($)"].tap() | |
tablesQuery.staticTexts["Azerbaijan New Manat"].tap() | |
tablesQuery.staticTexts["Miles (Mi)"].tap() | |
let okButton = app.alerts[" "].collectionViews.buttons["OK"] | |
okButton.tap() | |
tablesQuery.staticTexts["English (United States)"].tap() | |
okButton.tap() | |
let machineTranslationsSwitch = tablesQuery.switches["Machine Translations"] | |
machineTranslationsSwitch.tap() | |
machineTranslationsSwitch.tap() | |
tablesQuery.staticTexts["Help"].tap() | |
XCTAssertEqual(app.navigationBars["Help"].exists, true) | |
tablesQuery.staticTexts["Customer Service"].tap() | |
//XCTAssertEqual(app.navigationBars["Help"].staticTexts["Help"].exists, true) | |
XCTAssertEqual(tablesQuery.staticTexts["FEEDBACK"].exists, true) | |
XCTAssertEqual(tablesQuery.staticTexts["BOOKINGS"].exists, true) | |
XCTAssertEqual(tablesQuery.staticTexts["PRIVACY"].exists, true) | |
XCTAssertEqual(tablesQuery.staticTexts["ABOUT"].exists, true) | |
let helpemailfieldTextField = tablesQuery.textFields["helpEmailField"] | |
helpemailfieldTextField.tap() | |
helpemailfieldTextField.typeText("peter.lafferty@webresint.com") | |
let helpcommentsfieldTextView = tablesQuery.textViews["helpCommentsField"] | |
helpcommentsfieldTextView.tap() | |
helpcommentsfieldTextView.typeText("These are my comments. They are amazing.") | |
app.navigationBars["Contact Customer Service"].buttons["Send"].tap() | |
tablesQuery.staticTexts["App Feedback"].tap() | |
tablesQuery.switches["Would you use this app again?"].tap() | |
helpemailfieldTextField.tap() | |
helpemailfieldTextField.typeText("peter.lafferty@webresint.com") | |
helpcommentsfieldTextView.tap() | |
helpcommentsfieldTextView.typeText("These are my app feedback comments. These are also amazing.") | |
app.navigationBars["App Feedback"].buttons["Send"].tap() | |
let label = app.navigationBars["Help"] | |
let exists = NSPredicate(format: "exists == 1") | |
expectationForPredicate(exists, evaluatedWithObject: label, handler: nil) | |
waitForExpectationsWithTimeout(2, handler: nil) | |
tablesQuery.staticTexts["Cancel Booking"].tap() | |
app.navigationBars["Cancel Booking"].buttons["Back"].tap() | |
XCTAssert(app.staticTexts["Help"].exists); | |
tablesQuery.staticTexts["Privacy Policy"].tap() | |
sleep(1) | |
app.navigationBars["Privacy Policy"].buttons["Back"].tap() | |
tablesQuery.staticTexts["How We Use Your Data"].tap() | |
sleep(1) | |
app.navigationBars["How We Use Your Data"].buttons["Back"].tap() | |
sleep(1) | |
tablesQuery.staticTexts["Application Version"].tap() | |
app.navigationBars["Help"].buttons["Back"].tap() | |
app.navigationBars["Settings"].buttons["menu"].tap() | |
app.buttons["menuExplore"].tap() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment