Test cleanup

- Added `swipeUpUntilElementIsVisible` method, so as to prevent test failure on the iPhone 6S Simulator (previously was not swiping to reveal appropriate tappable elements)

- Split giant test into four smaller tests, for better issue detection
This commit is contained in:
Gemma Barlow 2017-04-16 15:19:52 -04:00
parent abb6f7065e
commit 7099e4221b
1 changed files with 38 additions and 29 deletions

View File

@ -9,33 +9,24 @@
import XCTest
class FSCalendarSwiftExampleUITests: XCTestCase {
// MARK: - Setup / Tear Down
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().launch()
// In UI tests its important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to 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 testExample() {
self.doTestDIY()
self.doTestScope()
self.doTestDelegateAppearance()
self.doTestInterfaceBuilder()
}
func doTestDIY() {
// MARK: - Tests
func testDIY() {
let application = XCUIApplication()
application.tables.element(boundBy: 0).staticTexts["DIY"].tap()
let calendar: XCUIElement = application.otherElements["calendar"]
@ -53,7 +44,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase {
application.buttons.element(boundBy: 0).tap()
}
func doTestDelegateAppearance() {
func testDelegateAppearance() {
let application = XCUIApplication()
application.tables.element(boundBy: 0).staticTexts["Delegate Appearance"].tap()
@ -88,7 +79,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase {
application.buttons.element(boundBy: 0).tap()
}
func doTestScope() {
func testScope() {
let application = XCUIApplication()
application.tables.element(boundBy: 0).staticTexts["FSCalendarScope"].tap()
let tableView: XCUIElement = application.tables.element(boundBy: 0)
@ -114,8 +105,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase {
application.buttons.element(boundBy: 0).tap()
}
func doTestInterfaceBuilder() {
func testInterfaceBuilder() {
let application = XCUIApplication()
application.tables.element(boundBy: 0).staticTexts["Interface Builder"].tap()
let calendar = application.otherElements["calendar"]
@ -177,22 +167,29 @@ class FSCalendarSwiftExampleUITests: XCTestCase {
Thread.sleep(forTimeInterval: 0.5)
configButton.tap()
application.tables.element(boundBy: 0).swipeUp()
application.tables.staticTexts["Monday"].tap()
let table = application.tables.element(boundBy: 0)
let monday = application.tables.staticTexts["Monday"]
swipeUpUntilElementIsVisible(table: table, element: monday)
monday.tap()
calendar.swipeUp()
calendar.swipeDown()
Thread.sleep(forTimeInterval: 0.5)
configButton.tap()
application.tables.element(boundBy: 0).swipeUp()
application.tables.staticTexts["Tuesday"].tap()
let tuesday = application.tables.staticTexts["Tuesday"]
swipeUpUntilElementIsVisible(table: table, element: tuesday)
tuesday.tap()
calendar.swipeUp()
calendar.swipeDown()
Thread.sleep(forTimeInterval: 0.5)
configButton.tap()
application.tables.element(boundBy: 0).swipeUp()
application.tables.staticTexts["Sunday"].tap()
let sunday = application.tables.staticTexts["Sunday"]
swipeUpUntilElementIsVisible(table: table, element: sunday)
sunday.tap()
calendar.swipeUp()
calendar.swipeDown()
Thread.sleep(forTimeInterval: 1.5)
@ -209,6 +206,18 @@ class FSCalendarSwiftExampleUITests: XCTestCase {
// Exit
Thread.sleep(forTimeInterval: 1.0)
application.buttons.element(boundBy: 0).tap()
}
// MARK: - Helper Methods
private let maxSwipes = 5
private func swipeUpUntilElementIsVisible(table: XCUIElement, element: XCUIElement) {
var swipes = 0
while !element.exists && swipes < maxSwipes {
table.swipeUp()
swipes += 1
}
}
}