Skip to content

Commit

Permalink
test: add UI test configs
Browse files Browse the repository at this point in the history
put tests in right place
  • Loading branch information
andrewjl-mux committed Oct 1, 2024
1 parent 9e0019e commit eaece58
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
193228D72ACF6AC900966FE1 /* MuxPlayerSwiftExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MuxPlayerSwiftExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
193228DB2ACF6AC900966FE1 /* MuxPlayerSwiftExampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuxPlayerSwiftExampleUITests.swift; sourceTree = "<group>"; };
193228DD2ACF6AC900966FE1 /* MuxPlayerSwiftExampleUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuxPlayerSwiftExampleUITestsLaunchTests.swift; sourceTree = "<group>"; };
193D52E82CAC78C0004F20AA /* MuxPlayerSwiftExample.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = MuxPlayerSwiftExample.xctestplan; sourceTree = "<group>"; };
1966C52F2BEB4740005486D5 /* ProcessInfo+EnvironmentVariables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ProcessInfo+EnvironmentVariables.swift"; sourceTree = "<group>"; };
19DD16AE2BEC010400F4DF4F /* SinglePlayerExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SinglePlayerExampleController.swift; sourceTree = "<group>"; };
19DD16B02BEC028C00F4DF4F /* SmartCacheExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCacheExampleViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,6 +90,7 @@
193228AE2ACF6AC700966FE1 = {
isa = PBXGroup;
children = (
193D52E82CAC78C0004F20AA /* MuxPlayerSwiftExample.xctestplan */,
193228B92ACF6AC700966FE1 /* MuxPlayerSwiftExample */,
193228D02ACF6AC900966FE1 /* MuxPlayerSwiftExampleTests */,
193228DA2ACF6AC900966FE1 /* MuxPlayerSwiftExampleUITests */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:MuxPlayerSwiftExample.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
24 changes: 24 additions & 0 deletions Examples/MuxPlayerSwiftExample/MuxPlayerSwiftExample.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "3007B2FC-0024-43DA-94F6-B50D2335DA68",
"name" : "Configuration 1",
"options" : {

}
}
],
"defaultOptions" : {
"testTimeoutsEnabled" : true
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:MuxPlayerSwiftExample.xcodeproj",
"identifier" : "193228D62ACF6AC900966FE1",
"name" : "MuxPlayerSwiftExampleUITests"
}
}
],
"version" : 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,97 +15,4 @@ final class MuxPlayerSwiftExampleTests: XCTestCase {
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func launchAndWaitUntilInForeground(
application: XCUIApplication
) throws {
application.launchEnvironment = [
"ENV_KEY": "qr9665qr78dac0hqld9bjofps",
"PLAYBACK_ID": "qxb01i6T202018GFS02vp9RIe01icTcDCjVzQpmaB00CUisJ4"
]
application.launch()

let isRunningInForeground = application.wait(
for: .runningForeground,
timeout: 5.0
)

guard isRunningInForeground else {
XCTFail("Failed to launch application")
return
}
}

func tapCell(
cellIdentifier: String,
waitFor viewIdentifier: String,
application: XCUIApplication
) throws {
let cellElement = application.cells.element(
matching: .cell,
identifier: cellIdentifier
)

guard cellElement.exists else {
XCTFail("Failed to find cell element: \(cellIdentifier)")
return
}

cellElement.tap()

let viewElement = application.descendants(
matching: .any
).element(
matching: .any,
identifier: viewIdentifier
)

let isViewElementOnScreen = viewElement.waitForExistence(
timeout: 150.0
)

guard isViewElementOnScreen else {
XCTFail("Failed to navigate to view element: \(viewIdentifier)")
return
}

let isUnknown = application.wait(
for: .unknown,
timeout: 25.0
)

guard !isUnknown else {
XCTFail("Application interrupted while playing video")
return
}
}


func testVideoOnDemandPlayerViewController() throws {
let application = XCUIApplication()

try launchAndWaitUntilInForeground(
application: application
)

try tapCell(
cellIdentifier: "SinglePlayerExample",
waitFor: "SinglePlayerView",
application: application
)
}

func testVideoOnDemandPlayerLayer() throws {
let application = XCUIApplication()

try launchAndWaitUntilInForeground(
application: application
)

try tapCell(
cellIdentifier: "SinglePlayerLayerExample",
waitFor: "SinglePlayerLayerView",
application: application
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,96 @@ final class MuxPlayerSwiftExampleUITests: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
func launchAndWaitUntilInForeground(
application: XCUIApplication
) throws {
application.launchEnvironment = [
"ENV_KEY": "qr9665qr78dac0hqld9bjofps",
"PLAYBACK_ID": "qxb01i6T202018GFS02vp9RIe01icTcDCjVzQpmaB00CUisJ4"
]
application.launch()

// Use XCTAssert and related functions to verify your tests produce the correct results.
let isRunningInForeground = application.wait(
for: .runningForeground,
timeout: 5.0
)

guard isRunningInForeground else {
XCTFail("Failed to launch application")
return
}
}

func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
func tapCell(
cellIdentifier: String,
waitFor viewIdentifier: String,
application: XCUIApplication
) throws {
let cellElement = application.cells.element(
matching: .cell,
identifier: cellIdentifier
)

guard cellElement.exists else {
XCTFail("Failed to find cell element: \(cellIdentifier)")
return
}

cellElement.tap()

let viewElement = application.descendants(
matching: .any
).element(
matching: .any,
identifier: viewIdentifier
)

let isViewElementOnScreen = viewElement.waitForExistence(
timeout: 150.0
)

guard isViewElementOnScreen else {
XCTFail("Failed to navigate to view element: \(viewIdentifier)")
return
}

let isUnknown = application.wait(
for: .unknown,
timeout: 25.0
)

guard !isUnknown else {
XCTFail("Application interrupted while playing video")
return
}
}


func testVideoOnDemandPlayerViewController() throws {
let application = XCUIApplication()

try launchAndWaitUntilInForeground(
application: application
)

try tapCell(
cellIdentifier: "SinglePlayerExample",
waitFor: "SinglePlayerView",
application: application
)
}

func testVideoOnDemandPlayerLayer() throws {
let application = XCUIApplication()

try launchAndWaitUntilInForeground(
application: application
)

try tapCell(
cellIdentifier: "SinglePlayerLayerExample",
waitFor: "SinglePlayerLayerView",
application: application
)
}
}

0 comments on commit eaece58

Please sign in to comment.