Skip to content

Commit

Permalink
test: Add BaseUITest class (#3373)
Browse files Browse the repository at this point in the history
Add a base class for UITests for the iOSSwift to remove
some redundant code.
  • Loading branch information
philipphofmann authored Nov 6, 2023
1 parent 105a36c commit 8d90d43
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 51 deletions.
4 changes: 4 additions & 0 deletions Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0AAAB8572887F7C60011845C /* PermissionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AABE2E928855FF80057ED69 /* PermissionsViewController.swift */; };
0AABE2EA28855FF80057ED69 /* PermissionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AABE2E928855FF80057ED69 /* PermissionsViewController.swift */; };
62C07D5C2AF3E3F500894688 /* BaseUITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62C07D5B2AF3E3F500894688 /* BaseUITest.swift */; };
630853532440C60F00DDE4CE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 630853322440C44F00DDE4CE /* Sentry.framework */; };
637AFDAA243B02760034958B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637AFDA9243B02760034958B /* AppDelegate.swift */; };
637AFDAE243B02760034958B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637AFDAD243B02760034958B /* ViewController.swift */; };
Expand Down Expand Up @@ -270,6 +271,7 @@

/* Begin PBXFileReference section */
0AABE2E928855FF80057ED69 /* PermissionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsViewController.swift; sourceTree = "<group>"; };
62C07D5B2AF3E3F500894688 /* BaseUITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseUITest.swift; sourceTree = "<group>"; };
6308532C2440C44F00DDE4CE /* Sentry.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Sentry.xcodeproj; path = ../../Sentry.xcodeproj; sourceTree = "<group>"; };
637AFDA6243B02760034958B /* iOS-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; };
637AFDA9243B02760034958B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -478,6 +480,7 @@
isa = PBXGroup;
children = (
D83A30DF279F1F5C00372D0A /* fatal-error-binary-images-message2.json */,
62C07D5B2AF3E3F500894688 /* BaseUITest.swift */,
7B64386A26A6C544000D0F65 /* LaunchUITests.swift */,
D8C33E2529FBB8D90071B75A /* UIEventBreadcrumbTests.swift */,
84A5D72C29D2708D00388BFA /* UITestHelpers.swift */,
Expand Down Expand Up @@ -929,6 +932,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
62C07D5C2AF3E3F500894688 /* BaseUITest.swift in Sources */,
84A5D72629D2705000388BFA /* ProfilingUITests.swift in Sources */,
84A5D72D29D2708D00388BFA /* UITestHelpers.swift in Sources */,
84B527B928DD24BA00475E8D /* SentryDeviceTests.mm in Sources */,
Expand Down
25 changes: 25 additions & 0 deletions Samples/iOS-Swift/iOS-SwiftUITests/BaseUITest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import XCTest

class BaseUITest: XCTestCase {
internal let app: XCUIApplication = XCUIApplication()

override func setUp() {
super.setUp()
continueAfterFailure = false
XCUIDevice.shared.orientation = .portrait
app.launchEnvironment["io.sentry.ui-test.test-name"] = name
app.launch()

waitForExistenceOfMainScreen()
}

override func tearDown() {
app.terminate()
super.tearDown()
}

func waitForExistenceOfMainScreen() {
app.waitForExistence( "Home Screen doesn't exist.")
}

}
21 changes: 1 addition & 20 deletions Samples/iOS-Swift/iOS-SwiftUITests/LaunchUITests.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import XCTest

class LaunchUITests: XCTestCase {
private let app: XCUIApplication = XCUIApplication()

override func setUp() {
super.setUp()
continueAfterFailure = false
XCUIDevice.shared.orientation = .portrait
app.launchEnvironment["io.sentry.ui-test.test-name"] = name
app.launch()

waitForExistenceOfMainScreen()
}

override func tearDown() {
app.terminate()
super.tearDown()
}
class LaunchUITests: BaseUITest {

func testCrashRecovery() {
//We will be removing this test from iOS 12 because it fails during CI, which looks like a bug that we cannot reproduce.
Expand Down Expand Up @@ -120,9 +104,6 @@ class LaunchUITests: XCTestCase {
}

private extension LaunchUITests {
func waitForExistenceOfMainScreen() {
app.waitForExistence( "Home Screen doesn't exist.")
}

func checkSlowAndFrozenFrames() {
let frameStatsLabel = app.staticTexts["framesStatsLabel"]
Expand Down
11 changes: 1 addition & 10 deletions Samples/iOS-Swift/iOS-SwiftUITests/ProfilingUITests.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import XCTest

final class ProfilingUITests: XCTestCase {
private let app: XCUIApplication = XCUIApplication()

override func setUpWithError() throws {
try super.setUpWithError()
continueAfterFailure = false
XCUIDevice.shared.orientation = .portrait
app.launchEnvironment["io.sentry.ui-test.test-name"] = name
app.launch()
}
final class ProfilingUITests: BaseUITest {

/**
* We had a bug where we forgot to install the frames tracker into the profiler, so weren't sending any GPU frame information with profiles. Since it's not possible to enforce such installation via the compiler, we test for the results we expect here, by starting a transaction, triggering an ANR which will cause degraded frame rendering, stop the transaction, and inspect the profile payload.
Expand Down
22 changes: 1 addition & 21 deletions Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import XCTest

class UIEventBreadcrumbTests: XCTestCase {
private let app: XCUIApplication = XCUIApplication()

override func setUp() {
super.setUp()
continueAfterFailure = false
XCUIDevice.shared.orientation = .portrait
app.launchEnvironment["io.sentry.ui-test.test-name"] = name
app.launch()

waitForExistenceOfMainScreen()
}

override func tearDown() {
app.terminate()
super.tearDown()
}
class UIEventBreadcrumbTests: BaseUITest {

func testNoBreadcrumbForTextFieldEditingChanged() {
app.buttons["Extra"].tap()
Expand Down Expand Up @@ -44,8 +28,4 @@ class UIEventBreadcrumbTests: XCTestCase {

XCTAssertNotEqual(info, "ERROR")
}

func waitForExistenceOfMainScreen() {
app.waitForExistence( "Home Screen doesn't exist.")
}
}

0 comments on commit 8d90d43

Please sign in to comment.