Skip to content

Commit

Permalink
test: add UI tests to example application (#58)
Browse files Browse the repository at this point in the history
* test: add UI test configs
  • Loading branch information
andrewjl-mux authored Oct 1, 2024
1 parent 1fd0d34 commit 8cea0e0
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 31 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
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="jr0-37-Rsf">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23094" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="jr0-37-Rsf">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23084"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -43,6 +43,7 @@
</label>
</subviews>
</tableViewCellContentView>
<accessibility key="accessibilityConfiguration" identifier="SinglePlayerExample"/>
<connections>
<segue destination="BYZ-38-t0r" kind="show" id="dET-KM-oHN"/>
</connections>
Expand Down Expand Up @@ -97,6 +98,7 @@
</label>
</subviews>
</tableViewCellContentView>
<accessibility key="accessibilityConfiguration" identifier="SinglePlayerLayerExample"/>
<connections>
<segue destination="JrU-9c-zyG" kind="show" id="q3v-VV-Yv9"/>
</connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class SinglePlayerExampleController: UIViewController {
super.viewDidLoad()

view.backgroundColor = .black
view.accessibilityLabel = "A single player example that uses AVPlayerViewController"
view.accessibilityIdentifier = "SinglePlayerView"

let maximumResolutionsMenu = UIMenu(
title: "Set Maximum Resolution",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class SinglePlayerLayerExampleViewController: UIViewController {
super.viewDidLoad()

playerView.backgroundColor = .black
view.accessibilityLabel = "A single player example that uses AVPlayerLayer"
view.accessibilityIdentifier = "SinglePlayerLayerView"

playerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(playerView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +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 testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
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 8cea0e0

Please sign in to comment.