Example iOS Feature Test
import XCTest | |
import Hamcrest | |
import PactConsumerSwift | |
class CandiesMasterDetailFeature: XCTestCase { | |
override func setUp() { | |
super.setUp() | |
continueAfterFailure = false | |
XCUIApplication().launch() | |
} | |
func testMasterDetail() { | |
let expectation = expectationWithDescription("Pact tests complete") | |
let candiesService = MockService( | |
candy: "Service API", | |
consumer: "Our App", | |
done: { result in | |
assertThat(result, equalTo(PactVerificationResult.Passed)) | |
expectation.fulfill() | |
}) | |
candiesService | |
.given("a list of candies") | |
.uponReceiving("a request for candies") | |
.withRequest( | |
method:.GET, | |
path: "/candies", | |
query: ["search-text": "fruit"]) | |
.willRespondWith( | |
status:200, | |
headers: ["Content-Type": "application/json"], | |
body: ["candies": [ | |
[ | |
"id": "1", | |
"name": "Lemon Drops", | |
], | |
[ | |
"id": "2", | |
"name": "Chocolate Covered Candied Ginger", | |
], | |
[ | |
"id": "3", | |
"name": "Orange Slices", | |
], | |
]]) | |
candiesService | |
.given("Orange slices") | |
.uponReceiving("a request for orange slice information") | |
.withRequest( | |
method:.GET, | |
path: "/candies/3") | |
.willRespondWith( | |
status:200, | |
headers: ["Content-Type": "application/json"], | |
body: ["candy": [ | |
"name": "Orange Slices", | |
"price": 6.75, | |
"flavors": [ | |
"orange", | |
"lemon", | |
"lime", | |
"cherry", | |
] | |
]]) | |
candiesService.run { (testComplete) -> Void in | |
let app = XCUIApplication() | |
let searchBar = app | |
.otherElements["CandiesSearchTextBox"] | |
.childrenMatchingType(.SearchField) | |
.element | |
searchBar.tap() | |
searchBar.typeText("fruit") | |
app.keyboards.buttons["Search"].tap() | |
let orangeSlicesRow = app.tables.cells.elementBoundByIndex(2) | |
assertThat(orangeSlicesRow.staticTexts["Orange Slices"].exists, equalTo(true)) | |
orangeSlicesRow.tap() | |
assertThat(app.staticTexts["Orange Slices"].exists, equalTo(true)) | |
let candyNameDetailRow = app.tables.cells.elementBoundByIndex(0) | |
assertThat(candyNameDetailRow.images["OrangeSlices"].exists, equalTo(true)) | |
app.swipeUp() | |
let priceRow = app.tables.cells.elementBoundByIndex(1) | |
assertThat(priceRow.staticTexts["$6.75"].exists, equalTo(true)) | |
let flavorsRow = app.tables.cells.elementBoundByIndex(2) | |
assertThat(flavorsRow.staticTexts["orange, lemon, lime, cherry"].exists, equalTo(true)) | |
testComplete() | |
} | |
waitForExpectationsWithTimeout(20, handler: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
This is out-of-date.
'childrenMatchingType' has been renamed to 'children(matching:)'
'SearchField' has been renamed to 'searchField'