Skip to content

Instantly share code, notes, and snippets.

class LegalView: UIView {
func setup() {
// add elements to the view
self.setupAccessibilityIdentifiers()
// ...
}
}
// In the LegalView.swift
func setup() {
// .. add element to subview
self.tosButton.accessibilityIdentifier = "legal_view.tos_button"
self.privacyButton.accessibilityIdentifier = "legal_view.privacy_button"
self.continueButton.accessibilityIdentifier = "legal_view.continue_button"
}
// ---
// In the UITest
func test() {
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
let tosButton = app.buttons["legal_view.tos_button"]
let privacyButton = app.buttons["legal_view.privacy_button"]
private func setup() {
// ... other view elements ...
self.addSubview(tosButton)
self.addSubview(privacyButton)
self.addSubview(continueButton)
// Add these lines to let the XCUITest access the buttons with identifiers
self.tosButton.accessibilityIdentifier = "legal_view.tos_button"
self.privacyButton.accessibilityIdentifier = "legal_view.privacy_button"
self.continueButton.accessibilityIdentifier = "legal_view.continue_button"
let tosButton = app.staticTexts["Tap to accept TOS"]
let privacyButton = app.staticTexts["Tap to Accept Privacy Policy"]
let continueButton = app.staticTexts["Continue"]
XCTAssertFalse(tosButton.isSelected)
XCTAssertFalse(privacyButton.isSelected)
XCTAssertFalse(continueButton.isEnabled)
tosButton.tap()
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// XCODE STARTS WRITING HERE:👇
let app = XCUIApplication()
import XCTest
class UITestAppUITests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
import Foundation
do {
let version = try String(contentsOfFile: ".version")
  .trimmingCharacters(in: CharacterSet.init(charactersIn: " \n"))
  print(version)
} catch {
  print("[ERROR] Unable to read file .version.\nError: \(error.localizedDescription)")
}
import Foundation
print("Hello, World!")
// Data structure for a Movie
struct Movie: Codable {
let id: String
let title: String
let description: String
let director: String
let producer: String
let releaseDate: String
let rtScore: String
let url: URL