Skip to content

Instantly share code, notes, and snippets.

@th3hunt
Last active January 11, 2016 18:06
Show Gist options
  • Save th3hunt/68e23299a8c8e3072fe2 to your computer and use it in GitHub Desktop.
Save th3hunt/68e23299a8c8e3072fe2 to your computer and use it in GitHub Desktop.
An XCTest example
class MovieRamaInSwiftTests: XCTestCase {
let client = HttpClient.init()
let applicationManager = ApplicationManager.init()
func testExample() {
let expectation = expectationWithDescription("AlamofireGetMovies")
var searchResults : Array<MovieObj> = Array()
client.getMovieListForSearchText("She", limit: 7, currentPage: 1) { responseObject, error in
XCTAssertNil(error, "Whoops, error \(error)")
var moviesUnSerialized: [NSDictionary] = []
var total : Int = 0
if let _ = responseObject?.valueForKey("movies") as? [NSDictionary]{
moviesUnSerialized = responseObject?.valueForKey("movies") as! [NSDictionary]
total = Int((responseObject?.valueForKey("total"))! as! NSNumber)
}
let moviesSerialized = self.applicationManager.serializeMovies(moviesUnSerialized)
searchResults.appendContentsOf(moviesSerialized)
let shelterMovie : MovieObj = searchResults[0] as MovieObj
XCTAssertEqual(shelterMovie.title, "Shrek 2")
expectation.fulfill()
}
waitForExpectationsWithTimeout(5) { (error) -> Void in }
}
func testExampleUI() {
let tables = app.tables
let arrowleft = String.fontAwesomeIconWithName(.AngleLeft)
let backButtonTitle = arrowleft + " back"
//wait until search field appears
let exists = NSPredicate(format: "exists == 1")
let okAlert = self.app.buttons["OK"]
expectationForPredicate(exists, evaluatedWithObject: okAlert, handler: nil)
waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error == nil){
okAlert.tap()
}else{
print ("error: \(error)")
}
}
let searchField = tables.searchFields["Search for movies"]
expectationForPredicate(exists, evaluatedWithObject: searchField, handler: nil)
waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error == nil){
tables.searchFields["Search for movies"].tap()
self.app.searchFields["Search for movies"].typeText("the")
self.app.buttons["Done"].tap()
self.app.buttons["Cancel"].tap()
}else{
print ("error: \(error)")
}
}
tables.childrenMatchingType(.Cell).elementBoundByIndex(1).staticTexts["Point Break"].tap()
// tables.element.cells.elementBoundByIndex(4).tap()
self.app.buttons["Remind Me"].tap()
self.app.alerts["Reminder Set!"].buttons["OK"].tap()
self.app.navigationBars["Point Break"].buttons[backButtonTitle].tap()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment