/
PushedPage.swift
68 lines (60 loc) · 1.57 KB
/
PushedPage.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
//
// PushedPage.swift
// AutoMate
//
// Created by Bartosz Janda on 31.01.2017.
// Copyright © 2017 PGS Software. All rights reserved.
//
import Foundation
import XCTest
// MARK: - PushedPage protocol
/// Page object protocol describing behaviour of pushed.
///
/// Default implementation use "back" as `accessibilityIdentifier`.
///
/// **Example:**
///
/// ```swift
/// class AboutTheAppPage: BaseAppPage, PushedPage {}
///
/// let aboutTheAppPage = AboutTheAppPage(in: containerView)
/// aboutTheAppPage.goBack()
/// ```
///
/// - requires:
/// It is required to use "back" as `accessibilityIdentifier` in custom back button in the application to work with default implementation of this protocol.
public protocol PushedPage: BaseAppPageProtocol {
// MARK: Elements
/// Back button element.
var backButton: XCUIElement { get }
// MARK: Actions
/// Pop view action.
func goBack()
}
// MARK: Default implementation
/// Default implementation of the `PushedPage` protocol.
public extension PushedPage {
// MARK: Elements
/// Back button.
///
/// - note:
/// The button with "back" as `accessibilityIdentifier` is used.
var backButton: XCUIElement {
return view.navigationBars.buttons.firstMatch
}
// MARK: Actions
/// Pop view by tapping on `backButton` button.
#if !os(tvOS)
func goBack() {
#if os(iOS)
backButton.tap()
#elseif os(macOS)
backButton.click()
#endif
}
#endif
}
// MARK: - Locators
private enum Locators: String, Locator {
case backButton = "back"
}