2022-04-13 17:19:11 +03:00
|
|
|
//
|
2022-08-11 08:54:24 +01:00
|
|
|
// Copyright 2022 New Vector Ltd
|
2022-04-13 17:19:11 +03:00
|
|
|
//
|
2022-08-11 08:54:24 +01:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2022-04-13 17:19:11 +03:00
|
|
|
//
|
|
|
|
|
2022-08-11 15:02:47 +03:00
|
|
|
import SnapshotTesting
|
2022-04-13 17:19:11 +03:00
|
|
|
import XCTest
|
|
|
|
|
|
|
|
struct Application {
|
2022-04-29 10:11:42 +03:00
|
|
|
static func launch() -> XCUIApplication {
|
2022-04-13 17:19:11 +03:00
|
|
|
let app = XCUIApplication()
|
|
|
|
app.launchEnvironment = ["IS_RUNNING_UI_TESTS": "1"]
|
2022-08-11 15:02:47 +03:00
|
|
|
Bundle.elementFallbackLanguage = "en"
|
2022-04-13 17:19:11 +03:00
|
|
|
app.launch()
|
2022-04-29 10:11:42 +03:00
|
|
|
return app
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension XCUIApplication {
|
2022-06-21 20:28:42 +03:00
|
|
|
func goToScreenWithIdentifier(_ identifier: UITestScreenIdentifier) {
|
2022-07-06 14:49:05 +01:00
|
|
|
let button = buttons[identifier.rawValue]
|
2022-04-29 10:11:42 +03:00
|
|
|
let lastLabel = staticTexts["lastItem"]
|
|
|
|
|
2022-07-06 14:49:05 +01:00
|
|
|
while !button.isHittable, !lastLabel.isHittable {
|
|
|
|
tables.firstMatch.swipeUp()
|
2022-04-29 10:11:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
button.tap()
|
2022-04-13 17:19:11 +03:00
|
|
|
}
|
2022-08-11 15:02:47 +03:00
|
|
|
|
|
|
|
/// Assert screenshot for a screen with the given identifier. Does not fail if a screenshot is newly created.
|
|
|
|
/// - Parameter identifier: Identifier of the UI test screen
|
|
|
|
func assertScreenshot(_ identifier: UITestScreenIdentifier) {
|
|
|
|
let failure = verifySnapshot(matching: screenshot().image,
|
2022-09-28 10:25:59 +03:00
|
|
|
as: .image(precision: 0.98, perceptualPrecision: 0.98, scale: nil),
|
2022-08-11 15:02:47 +03:00
|
|
|
named: identifier.rawValue,
|
|
|
|
testName: testName)
|
|
|
|
|
2022-10-17 09:56:17 +01:00
|
|
|
if let failure,
|
2022-08-11 15:02:47 +03:00
|
|
|
!failure.contains("No reference was found on disk."),
|
|
|
|
!failure.contains("to test against the newly-recorded snapshot") {
|
|
|
|
XCTFail(failure)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var testName: String {
|
|
|
|
osVersion + "-" + languageCode + "-" + regionCode + "-" + deviceName
|
|
|
|
}
|
|
|
|
|
|
|
|
private var deviceName: String {
|
|
|
|
UIDevice.current.name
|
|
|
|
}
|
|
|
|
|
|
|
|
private var languageCode: String {
|
2022-10-28 17:08:51 +03:00
|
|
|
Locale.current.language.languageCode?.identifier ?? ""
|
2022-08-11 15:02:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private var regionCode: String {
|
2022-10-28 17:08:51 +03:00
|
|
|
Locale.current.language.region?.identifier ?? ""
|
2022-08-11 15:02:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private var osVersion: String {
|
|
|
|
UIDevice.current.systemVersion.replacingOccurrences(of: ".", with: "-")
|
|
|
|
}
|
2022-04-13 17:19:11 +03:00
|
|
|
}
|