簡體   English   中英

最快捷的刷新控制

[英]Uitest refresh control swift

我正在嘗試添加用於刷新控制的uitest ,但由於無法訪問具有可訪問性標識符( refreshControl.accessibilityIdentifier = "refreshControlList" )的刷新控制,所以無法完成此操作

launchAppWithArgs(json: OrdersResultJSON.ok, xcuiApp: app)

        let table = app.tables["agendaTable"]

        DispatchQueue.main.async {
            table.otherElements["sectionHeader0"].press(forDuration: 2, thenDragTo: table.otherElements["sectionHeader2"])
        }

        if !table.otherElements[""].waitForExistence(timeout: 6) {
            print("XXX")
        }

有什么建議可以測試嗎?

要執行拉動刷新,只需獲取第一個單元格並將其向下拖動即可:

let firstCell = app.tables["agendaTable"].cells.firstMatch
let start = firstCell.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0))
let finish = firstCell.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 10))
start.press(forDuration: 0, thenDragTo: finish)

希望這可以幫助!

您可以抓住UIRefreshControl的標題標簽並在其上放置一個標識符,如下所示:

func setSubviewAccessibility(for tableView: UITableView) {
            guard let titleLabel = tableView.refreshControl?.subviews.first?.subviews.last as? UILabel else {
                return
            }
            titleLabel.isAccessibilityElement = true
            titleLabel.accessibilityIdentifier = "refresh_control_label"
        }

調用此方法,以傳遞為UIRefreshControl設置的表視圖,您應該一切順利。

然后,在測試端:

let refreshControl = XCUIApplication().staticTexts["refresh_control_label"]

            guard refreshControl.waitForExistence(timeout: 5) else {
                return XCTFail("Refresh control label not found.")
            }

剩下的唯一問題是您可能需要將列表加載時間花一秒鍾多一點的時間,以便您的測試不會錯過UIRefreshControl。 使用waitForExistence總是很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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