Last active
February 23, 2018 01:49
-
-
Save timefrancesco/67ce0a860d1964f38492e536ef12c8d2 to your computer and use it in GitHub Desktop.
Succulent Test setup - Xcode
This file contains hidden or 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
import Succulent | |
@testable import TestAppUITests | |
class SucculentTestUITest: XCTestCase { | |
private var succulent: Succulent! | |
var session: URLSession! | |
var baseURL: URL! | |
/// The name of the trace file for the current test | |
private var traceName: String { | |
return self.description.trimmingCharacters(in: CharacterSet(charactersIn: "-[] ")).replacingOccurrences(of: " ", with: "_") | |
} | |
/// The URL to the trace file for the current test when running tests | |
private var traceUrl: URL? { | |
let bundle = Bundle(for: type(of: self)) | |
return bundle.url(forResource: self.traceName, withExtension: "trace", subdirectory: "Traces") | |
} | |
/// The URL to the trace file for the current test when recording | |
private var recordUrl: URL { | |
let bundle = Bundle(for: type(of: self)) | |
let recordPath = bundle.infoDictionary!["TraceRecordPath"] as! String | |
return URL(fileURLWithPath: "\(recordPath)/\(self.traceName).trace") | |
} | |
override func setUp() { | |
super.setUp() | |
continueAfterFailure = false | |
if let traceUrl = self.traceUrl { // Replay using an existing trace file | |
succulent = Succulent(traceUrl: traceUrl) | |
} else { // Record to a new trace file | |
succulent = Succulent(recordUrl: self.recordUrl, baseUrl: URL(string: "https//base-url-to-record.com/")!) | |
} | |
succulent.start() | |
let app = XCUIApplication() | |
app.launchEnvironment["succulentBaseURL"] = "http://localhost:\(succulent.actualPort)/" | |
app.launch() | |
} | |
override func tearDown() { | |
super.tearDown() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment