Created
August 21, 2015 13:25
-
-
Save peterlafferty/a792523d2c1e6642839e 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
// | |
// UISearchTests.swift | |
// Hostelworld | |
// | |
// Created by Peter Lafferty on 21/08/2015. | |
// Copyright © 2015 Web Reservations International. All rights reserved. | |
// | |
import Foundation | |
import XCTest | |
class UISearchTests: 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 | |
XCUIApplication().launch() | |
sleep(2) //shouldn't do this? | |
} | |
override func tearDown() { | |
// Put teardown code here. This method is called after the invocation of each test method in the class. | |
super.tearDown() | |
} | |
func testCitySearch(){ | |
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.cells["Cell 41"].tap() | |
/* | |
Cell 0x7ff9c4035ad0: traits: 8589934592, {{0.0, 12224.0}, {375.0, 312.0}}, identifier: 'Cell 41', label: 'Dublin Citi Hotel is a HOTEL with a 63% rating out 16 ratings. prices start from $273 per night.'*/ | |
} | |
func testCitySearchLondon() { | |
let app = XCUIApplication() | |
app.otherElements["searchDestinationButton"].tap() | |
app.searchFields["Where do you want to go?"].typeText("London") | |
app.tables["searchSuggestionsTable"].staticTexts["London, England"].tap() | |
app.buttons["Search"].tap() | |
XCTAssertEqual(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Astor Hyde Park'" )).element.exists, true) | |
XCTAssertEqual(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Hotel Sergul'" )).element.exists, true) | |
XCTAssertEqual(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'bAstor Museum Inn'" )).element.exists, false) | |
} | |
func testCitySearchEquityPointLondon() { | |
let app = XCUIApplication() | |
app.otherElements["searchDestinationButton"].tap() | |
app.searchFields["Where do you want to go?"].typeText("Equity Point London") | |
app.tables["searchSuggestionsTable"].staticTexts["Equity Point London, London, England"].tap() | |
app.buttons["Search"].tap() | |
XCTAssert(app.staticTexts["Equity Point London"].exists) | |
XCTAssert(app.staticTexts["Westbourne Terrace 100-102, Paddington, London"].exists) | |
} | |
func testSearchSort() { | |
let app = XCUIApplication() | |
app.otherElements["searchDestinationButton"].tap() | |
app.searchFields["Where do you want to go?"].typeText("London") | |
app.tables["searchSuggestionsTable"].staticTexts["London, England"].tap() | |
app.buttons["Search"].tap() | |
XCTAssert(app.tables.cells.elementBoundByIndex(0).label.rangeOfString("Equity Point London") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(1).label.rangeOfString("Palmers Lodge - Swiss Cottage") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(2).label.rangeOfString("St Christopher's Camden") != nil) | |
app.buttons["sortResultsButton"].tap() | |
app.staticTexts["Price"].tap() | |
XCTAssert(app.tables.cells.elementBoundByIndex(0).label.rangeOfString("Generator Hostel London") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(1).label.rangeOfString("Hostel 639") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(2).label.rangeOfString("Hostel Ordnance") != nil) | |
app.buttons["sortResultsButton"].tap() | |
app.staticTexts["Rating"].tap() | |
XCTAssert(app.tables.cells.elementBoundByIndex(0).label.rangeOfString("Park Hotel Essex") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(1).label.rangeOfString("Blue Skies Hostel") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(2).label.rangeOfString("Lidos Hotel") != nil) | |
app.buttons["sortResultsButton"].tap() | |
app.staticTexts["Name (A-Z)"].tap() | |
XCTAssert(app.tables.cells.elementBoundByIndex(0).label.rangeOfString("20 Bendish Lodge Guest House") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(1).label.rangeOfString("247 London Studios") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(2).label.rangeOfString("247london Hostel and Private Rooms") != nil) | |
app.buttons["sortResultsButton"].tap() | |
app.staticTexts["Name (Z-A)"].tap() | |
XCTAssert(app.tables.cells.elementBoundByIndex(0).label.rangeOfString("YHA London St Pauls") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(1).label.rangeOfString("YHA London St Pancras") != nil) | |
XCTAssert(app.tables.cells.elementBoundByIndex(2).label.rangeOfString("YHA London Oxford Street") != nil) | |
} | |
func testSearchFilters() { | |
let app = XCUIApplication() | |
app.otherElements["searchDestinationButton"].tap() | |
app.searchFields["Where do you want to go?"].typeText("London") | |
app.tables["searchSuggestionsTable"].staticTexts["London, England"].tap() | |
app.buttons["Search"].tap() | |
app.buttons["filterResultsButton"].tap() | |
app.staticTexts["All"].tap() | |
app.staticTexts["Campsites"].tap() | |
app.buttons["applyFilter"].tap() | |
XCTAssertEqual(app.tables["searchResultsTableView"].cells.count, 0, "There should be no results") | |
app.buttons["filterResultsButton"].tap() | |
app.staticTexts["Campsites"].tap() | |
app.staticTexts["Apartments"].tap() | |
app.buttons["applyFilter"].tap() | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS '247 London Studios'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Victorian Apartment'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'MBD Apartments in Tower Hamlets'" )).element.exists) | |
app.buttons["filterResultsButton"].tap() | |
app.staticTexts["Apartments"].tap() | |
app.staticTexts["Bed & Breakfasts"].tap() | |
app.buttons["applyFilter"].tap() | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Stay in Chelsea'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'FCT Bed'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Queens Drive'" )).element.exists) | |
app.buttons["filterResultsButton"].tap() | |
app.staticTexts["Bed & Breakfasts"].tap() | |
app.staticTexts["Hotels"].tap() | |
app.buttons["applyFilter"].tap() | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Enrico Hotel'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Hotel Sergul'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'London House Hotel'" )).element.exists) | |
app.buttons["filterResultsButton"].tap() | |
app.staticTexts["All"].tap() | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Equity Point London'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'Palmers Lodge - Swiss Cottage'" )).element.exists) | |
XCTAssert(app.tables.cells.matchingPredicate(NSPredicate(format: "label CONTAINS 'St Christopher's Camden'" )).element.exists) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment