/
HealthPermissionPage.swift
141 lines (122 loc) · 3.98 KB
/
HealthPermissionPage.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// HealthPermissionPage.swift
// AutoMate
//
// Created by Bartosz Janda on 15.02.2017.
// Copyright © 2017 PGS Software. All rights reserved.
//
import Foundation
import XCTest
// MARK: - HealthPermissionPage
#if os(iOS)
/// Page object representing HealthKit permission view.
///
/// It can only allow to tap on buttons:
///
/// - Allow
/// - Deny
/// - Turn on all permissions
/// - Turn off all permissions
///
/// **Example:**
///
/// ```swift
/// let healthPermissionPage = HealthPermissionPage(in: self.app)
/// healthPermissionPage.turnOnAllElement.tap()
/// healthPermissionPage.allowElement.tap()
/// ```
open class HealthPermissionPage: BaseAppPage, HealthAlertAllow, HealthAlertDeny, HealthAlertTurnOnAll, HealthAlertTurnOffAll {
// MARK: Elements
/// Navigation bar on HealthKit permission view.
///
/// This bar can be used to identify if the permission view is visible.
open var healthAccessElement: XCUIElement {
return view.navigationBars[Locators.healthAccess]
}
}
// MARK: - IdentifiableByElement
extension HealthPermissionPage: IdentifiableByElement {
/// Identifing `XCUIElement`.
///
/// The `healthAccessElement` is used.
public var identifingElement: XCUIElement {
return healthAccessElement
}
}
// MARK: - Locators
public extension HealthPermissionPage {
/// Locators used in the HealthKit permission view.
///
/// - `healthAccess`: Navigation bar identifier.
enum Locators: String, Locator {
/// Navigation bar identifier.
case healthAccess = "Health Access"
}
}
// MARK: - Health protocols
/// Protocol defining health alert allow element and messages.
public protocol HealthAlertAllow: SystemMessages {
/// Allow messages.
static var allow: [String] { get }
/// Allow element.
var allowElement: XCUIElement { get }
}
/// Protocol defining health alert deny element and messages.
public protocol HealthAlertDeny: SystemMessages {
/// Deny messages.
static var deny: [String] { get }
/// Deny element.
var denyElement: XCUIElement { get }
}
/// Protocol defining health alert "turn on all" element and messages.
public protocol HealthAlertTurnOnAll: SystemMessages {
/// Turn On All messages.
static var turnOnAll: [String] { get }
/// Turn On All element.
var turnOnAllElement: XCUIElement { get }
}
/// Protocol defining health alert "turn off all" element and messages.
public protocol HealthAlertTurnOffAll: SystemMessages {
/// Turn Off All messages.
static var turnOffAll: [String] { get }
/// Turn Off All element.
var turnOffAllElement: XCUIElement { get }
}
// MARK: - Default implementation
extension HealthAlertAllow where Self: BaseAppPage {
/// Allow element.
public var allowElement: XCUIElement {
guard let button = view.buttons.elements(withLabelsMatching: type(of: self).allow).first else {
preconditionFailure("Cannot find allow button.")
}
return button
}
}
extension HealthAlertDeny where Self: BaseAppPage {
/// Deny element.
public var denyElement: XCUIElement {
guard let button = view.buttons.elements(withLabelsMatching: type(of: self).deny).first else {
preconditionFailure("Cannot find deny button.")
}
return button
}
}
extension HealthAlertTurnOnAll where Self: BaseAppPage {
/// Turn On All element.
public var turnOnAllElement: XCUIElement {
guard let button = view.staticTexts.elements(withLabelsMatching: type(of: self).turnOnAll).first else {
preconditionFailure("Cannot find turn on all button.")
}
return button
}
}
extension HealthAlertTurnOffAll where Self: BaseAppPage {
/// Turn Off All element.
public var turnOffAllElement: XCUIElement {
guard let button = view.staticTexts.elements(withLabelsMatching: type(of: self).turnOffAll).first else {
preconditionFailure("Cannot find turn off all button.")
}
return button
}
}
#endif