| 1 |
// |
| 2 |
// ipjsua_swiftVidTest.swift |
| 3 |
// ipjsua-swiftVidTest |
| 4 |
// |
| 5 |
|
| 6 |
import XCTest |
| 7 |
|
| 8 |
final class ipjsua_swiftVidTest: XCTestCase { |
| 9 |
|
| 10 |
override func setUpWithError() throws { |
| 11 |
// Put setup code here. This method is called before the invocation of each test method in the class. |
| 12 |
|
| 13 |
// Add an interruption monitor to handle system alerts |
| 14 |
addUIInterruptionMonitor(withDescription: "Allow network permission") { (alert) -> Bool in |
| 15 |
print("UI alert: ", alert.description) |
| 16 |
if alert.buttons["Allow"].exists { |
| 17 |
alert.buttons["Allow"].tap() |
| 18 |
return true |
| 19 |
} |
| 20 |
if alert.buttons["OK"].exists { |
| 21 |
alert.buttons["OK"].tap() |
| 22 |
return true |
| 23 |
} |
| 24 |
return false |
| 25 |
} |
| 26 |
|
| 27 |
// In UI tests it is usually best to stop immediately when a failure occurs. |
| 28 |
continueAfterFailure = false |
| 29 |
|
| 30 |
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. |
| 31 |
} |
| 32 |
|
| 33 |
override func tearDownWithError() throws { |
| 34 |
// Put teardown code here. This method is called after the invocation of each test method in the class. |
| 35 |
} |
| 36 |
|
| 37 |
func testVideo() throws { |
| 38 |
// UI tests must launch the application that they test. |
| 39 |
let app = XCUIApplication() |
| 40 |
app.launch() |
| 41 |
|
| 42 |
// Access the Destination text field |
| 43 |
let textField = app.textFields["sip:[email protected]"] |
| 44 |
|
| 45 |
// Type localhost into the text field |
| 46 |
textField.tap() |
| 47 |
textField.tap(withNumberOfTaps: 3, numberOfTouches: 1) |
| 48 |
let dest = "sip:localhost:5080" |
| 49 |
textField.typeText(dest) |
| 50 |
|
| 51 |
// Use XCTAssert to verify the text is correct |
| 52 |
XCTAssertEqual(textField.value as? String, dest) |
| 53 |
|
| 54 |
// Click "Make call" button |
| 55 |
print("Making video call") |
| 56 |
app.buttons["Make call"].tap() |
| 57 |
|
| 58 |
// Wait for video to appear |
| 59 |
let expectation = XCTestExpectation(description: "Wait for video") |
| 60 |
let label = app.staticTexts["Video"] |
| 61 |
waitForElement(label, timeout: 6) |
| 62 |
|
| 63 |
expectation.fulfill() |
| 64 |
|
| 65 |
// This is necessary to invoke UI interruption monitor above |
| 66 |
app.staticTexts["Video"].tap() |
| 67 |
|
| 68 |
sleep(1) |
| 69 |
|
| 70 |
// Capture a screenshot of the entire screen |
| 71 |
let fullScreenshot = app.windows.firstMatch.screenshot() |
| 72 |
// Save the screenshot to a file |
| 73 |
saveScreenshot(image: fullScreenshot) |
| 74 |
} |
| 75 |
|
| 76 |
// Helper method to wait for an element to appear/exist |
| 77 |
func waitForElement(_ element: XCUIElement, timeout: TimeInterval) |
| 78 |
{ |
| 79 |
let predicate = NSPredicate(format: "exists == 1") |
| 80 |
let expectation = XCTNSPredicateExpectation(predicate: predicate, |
| 81 |
object: element) |
| 82 |
|
| 83 |
let result = XCTWaiter().wait(for: [expectation], timeout: timeout) |
| 84 |
XCTAssertEqual(result, .completed, "Element not found within " + |
| 85 |
"\(timeout) seconds") |
| 86 |
} |
| 87 |
|
| 88 |
func saveScreenshot(image: XCUIScreenshot) { |
| 89 |
let pngData = image.pngRepresentation |
| 90 |
let documentsDirectory = FileManager.default.urls( |
| 91 |
for: .documentDirectory, |
| 92 |
in: .userDomainMask).first! |
| 93 |
let fileURL = documentsDirectory.appendingPathComponent("screenshot.png") |
| 94 |
|
| 95 |
do { |
| 96 |
try pngData.write(to: fileURL) |
| 97 |
print("Screenshot saved to:", fileURL) |
| 98 |
} catch { |
| 99 |
XCTFail("Failed to save screenshot: \(error)") |
| 100 |
} |
| 101 |
} |
| 102 |
/* |
| 103 |
func testLaunchPerformance() throws { |
| 104 |
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { |
| 105 |
// This measures how long it takes to launch your application. |
| 106 |
measure(metrics: [XCTApplicationLaunchMetric()]) { |
| 107 |
XCUIApplication().launch() |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
*/ |
| 112 |
} |