[英]Xcode UITest find out if specific image exists inside a UITableViewCell
[英]UITest Query for UIImage inside of a UITableViewCell
我正在針對iOS應用程序在Swift中編寫UI測試,該應用程序包含一個UITableView
和一個從筆尖加載的自定義UITableViewCell
。 該單元格包含一個UIImageView
和一個UILabel
。
呈現表時,沒有XCUIElementQuery
查找圖像元素。 在UI測試期間,如何獲得對ImageView的訪問權限,以了解在圖標字段中指定的圖像的來源?
class MyCell: UITableViewCell {
@IBOutlet var name: UILabel!
@IBOutlet var icon: UIImageView!
}
該圖像不會出現在app.images
, app.tables.cells.images
或app.tables.cells.otherElements
。 在UI層次結構中似乎找不到圖像圖標。
已經晚了,但對於其他用戶...
我解決了如下問題:
self.tableView.accessibilityIdentifier = "ExampleTableView"
cell.icon.isAccessibilityElement = true
let imageName = "example_image"
cell.icon.accessibilityIdentifier = "ExampleTableViewCellIcon"
cell.icon.accessibilityLabel = imageName
cell.icon.image = UIImage(named: imageName)!
XCTAssert(app.tables["ExampleTableView"].cells.element(boundBy: 0).images[ExampleTableViewCellIcon].label == "example_image")
在UI測試中無法訪問圖像的路徑。 該框架將應用程序視為用戶一樣,為什么有人會關心復選標記的文件名?
更新 :要將用戶界面/輔助功能與您的不同圖標相關聯,可以在設置圖像時設置輔助功能標識符。
MyCell().icon?.accessibilityIdentifier = "check"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.