Reputation: 855
I am writing a react-native
bridge for healthkit that includes the initialization of Healthkit. I also need to write an unit test for the modules.
I would like to use Travis to auto test on the project. Therefore, I need a automatic way that can press on the Allow
button. Otherwise, the permission UI will block the unit testing process.
So, I need to know how automatically press on the allow button.
Upvotes: 1
Views: 436
Reputation: 4680
I am not sure how to get the accessibility IDs for these buttons, but I managed to get them using the hard coded String values. Make sure to set the Locale language to English in my Test Scheme if you were using English. Then this would work:
let healthKitTurnOnAllCategoriesButton = app.staticTexts["Turn On All"]
if healthKitTurnOnAllCategoriesButton.waitForExistence(timeout: 5) {
healthKitTurnOnAllCategoriesButton.tap()
}
let healthKitAllowButton = app.buttons["Allow"]
if healthKitAllowButton.waitForExistence(timeout: 5) {
systemAllowButton.tap()
}
Upvotes: 0
Reputation: 1373
I was able to reach those buttons with:
lazy var turnOnAllCategories = app.tables.cells.firstMatch
lazy var allowCategoriesConnectionButton = app.navigationBars.buttons.element(boundBy: 1)
On my test I check if the popup form is displayed with:
if turnOnAllCategories.waitForExistence(timeout: waitForExistenceTimeFrame) {
turnOnAllCategories.tap()
allowCategoriesConnectionButton.tap()
}
Keep in mind that base on your UI, maybe you will need to filter a bit more the results of app.tables and app.navigationBars.buttons
Upvotes: 0
Reputation: 1385
I'm using this library in my XCTests, I didn't specifically test HealthKit alerts but it seems to be supported.
https://github.com/PGSSoft/AutoMate/blob/master/AutoMate/Models/HealthAlerts.swift
Upvotes: 0