2016-12-01 18:28:57 +00:00
|
|
|
/**
|
|
|
|
|
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
|
|
|
|
|
|
|
|
|
The examples provided by Facebook are for non-commercial testing and evaluation
|
|
|
|
|
purposes only. Facebook reserves all rights not expressly granted.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
|
|
class UITestCase: XCTestCase {
|
2016-12-07 14:28:29 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
override func setUp() {
|
|
|
|
|
super.setUp()
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
continueAfterFailure = false
|
2016-12-07 14:28:29 +00:00
|
|
|
XCUIApplication().launch()
|
2016-12-01 18:28:57 +00:00
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
override func tearDown() {
|
|
|
|
|
super.tearDown()
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
// Adapted from http://masilotti.com/xctest-helpers/
|
|
|
|
|
internal func waitToAppear(element: XCUIElement,
|
2017-05-16 14:30:08 +00:00
|
|
|
timeout: TimeInterval = 2,
|
|
|
|
|
file: String = #file,
|
|
|
|
|
line: UInt = #line) {
|
2016-12-01 18:28:57 +00:00
|
|
|
waitToAppear(elements: [element], timeout: timeout, file: file, line: line)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
internal func waitToAppear(elements: [XCUIElement],
|
2017-05-16 14:30:08 +00:00
|
|
|
timeout: TimeInterval = 2,
|
|
|
|
|
file: String = #file,
|
|
|
|
|
line: UInt = #line) {
|
2016-12-01 18:28:57 +00:00
|
|
|
waitTo(appear: true, elements: elements, timeout: timeout, file: file, line: line)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
internal func waitToDisappear(element: XCUIElement,
|
2017-05-16 14:30:08 +00:00
|
|
|
timeout: TimeInterval = 2,
|
|
|
|
|
file: String = #file,
|
|
|
|
|
line: UInt = #line) {
|
2016-12-01 18:28:57 +00:00
|
|
|
waitToDisappear(elements: [element], timeout: timeout, file: file, line: line)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
internal func waitToDisappear(elements: [XCUIElement],
|
2017-05-16 14:30:08 +00:00
|
|
|
timeout: TimeInterval = 2,
|
|
|
|
|
file: String = #file,
|
|
|
|
|
line: UInt = #line) {
|
2016-12-01 18:28:57 +00:00
|
|
|
waitTo(appear: false, elements: elements, timeout: timeout, file: file, line: line)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
internal func waitTo(appear: Bool,
|
2017-05-16 14:30:08 +00:00
|
|
|
elements: [XCUIElement],
|
|
|
|
|
timeout: TimeInterval = 2,
|
|
|
|
|
file: String = #file,
|
|
|
|
|
line: UInt = #line) {
|
2016-12-01 18:28:57 +00:00
|
|
|
let existsPredicate = NSPredicate(format: "exists == \(appear)")
|
|
|
|
|
elements.forEach { element in
|
|
|
|
|
expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-12-01 18:28:57 +00:00
|
|
|
waitForExpectations(timeout: timeout) { error in
|
|
|
|
|
if error != nil {
|
|
|
|
|
let message = "Failed to \(appear ? "" : "not ")find element(s) after \(timeout) seconds."
|
|
|
|
|
self.recordFailure(withDescription: message,
|
|
|
|
|
inFile: file,
|
2017-09-22 13:34:52 +00:00
|
|
|
atLine: Int(line),
|
2016-12-01 18:28:57 +00:00
|
|
|
expected: true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|