簡體   English   中英

UITest在UITableViewCell內部查詢UIImage

[英]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.imagesapp.tables.cells.imagesapp.tables.cells.otherElements 在UI層次結構中似乎找不到圖像圖標。

已經晚了,但對於其他用戶...

我解決了如下問題:

  1. 添加表的accessibilityIdentifier。

self.tableView.accessibilityIdentifier = "ExampleTableView"

  1. 將imageView isAccessibilityElement設置為true!

cell.icon.isAccessibilityElement = true

  1. 圖像名稱在變量中,並使用變量名稱設置accessibilityLabel的圖像。

let imageName = "example_image"

cell.icon.accessibilityIdentifier = "ExampleTableViewCellIcon"

cell.icon.accessibilityLabel = imageName

cell.icon.image = UIImage(named: imageName)!

  1. 測試

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM