How to test UIImageView elements in iOS XCTest?

后端 未结 1 804
粉色の甜心
粉色の甜心 2021-01-04 22:38

I\'m trying to test my UIs using XCTest UI testing, and having troubles of testing UIImageViewsI have in my app (hit tests, presence etc).

In the list of the XCUIEle

1条回答
  •  被撕碎了的回忆
    2021-01-04 23:13

    Assert the presence of an image by its accessibility label.

    Production Code

    let image = UIImage(named: "profile")
    let imageView = UIImageView(image: image)
    imageView.accessibilityLabel = "Your profile image"
    

    UI Test Code

    let app = XCUIApplication()
    XCTAssert(app.images["Your profile image"].exists)
    

    0 讨论(0)
提交回复
热议问题