iOS 13设备上的应用程序图标不在屏幕上,无法通过XCUITest按下

我正在使用以下方法从Springboard删除我的应用程序,但是似乎偶尔它的框架似乎不在屏幕上,因此isHittable变为false。

let springApp = XCUIApplication(bundleIdentifier: "com.apple.springboard")    
let icon = springApp.otherElements.icons["App Name"]
        if icon.exists {
            let iconFrame = icon.frame
            icon.press(forDuration: 3)

            springApp.tapAtPoint(iconFrame.origin)

            sleep(0.5)
            springApp.alerts.buttons["Delete"].tap()

以下是发生问题时提供的职位:

 ▿ (-2.0,-2.0,4.0,4.0)
  ▿ origin : (-2.0,-2.0)
    - x : -2.0
    - y : -2.0
  ▿ size : (4.0,4.0)
    - width : 4.0
    - height : 4.0

有人知道为什么会发生这种情况,如果我能以某种方式解决它吗?不过,它似乎无法在iOS 12设备上重现。

wang312627 回答:iOS 13设备上的应用程序图标不在屏幕上,无法通过XCUITest按下

如果重置主屏幕布局,Springboard似乎会返回正确的坐标: 设置->常规->重置->重置主屏幕布局。

下面您可以找到对我无忧的解决方案:

func resetHomeScreenLayout(file: String = #file,line: Int = #line) {
    settingsApp.launch()

    let settingsGeneralCell = settingsApp.cells["General"]
    XCTAssertTrue(settingsGeneralCell.waitForExistence(timeout: Constants.smallWaitTime),"The \"General\" cell in Settings was not found. Error in file \(file) at line \(line).")
    settingsGeneralCell.tap()

    let settingsResetCell = settingsApp.cells["Reset"]
    XCTAssertTrue(settingsResetCell.waitForExistence(timeout: Constants.smallWaitTime),"The \"Reset\" cell in Settings was not found. Error in file \(file) at line \(line).")
    settingsResetCell.tap()

    let settingsResetHomeScreenLayoutLink = settingsApp.staticTexts["Reset Home Screen Layout"]
    XCTAssertTrue(settingsResetHomeScreenLayoutLink.waitForExistence(timeout: Constants.smallWaitTime),"The \"Settings\" link \"Reset Home Screen Layout\" was not found. Error in file \(file) at line \(line).")
    settingsResetHomeScreenLayoutLink.tap()

    let settingsResetHomeScreenPopOverButton = settingsApp.sheets.buttons["Reset Home Screen"]
    XCTAssertTrue(settingsResetHomeScreenPopOverButton.waitForExistence(timeout: Constants.smallWaitTime),"The \"Settings\" popover \"Reset Home Screen\" button was not found. Error in file \(file) at line \(line).")
    settingsResetHomeScreenPopOverButton.tap()

    settingsApp.terminate()
}

在长按应用程序图标之前调用此方法,它应该是可命中的。 确保根据需要向左滑动跳板,以使应用程序图标变得可见。 这至少在iOS 13.1.3上对我有效。

,

这适用于所有操作系统版本(iOS11、12和13)

static let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")

    func deleteApp() {
        XCUIApplication().terminate()
        springboard.activate()

        let icon = springboard.icons[appName]

        if icon.exists {
            icon.firstMatch.press(forDuration: 5)
            icon.buttons["DeleteButton"].tap()
            XCUIDevice.springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + 3) / springboardFrame.maxX,dy: (iconFrame.minY + 3) / springboardFrame.maxY)).tap()
            let deleteConfirmation = springboard.alerts["Delete “\(appName)”?"].buttons["Delete"]
            XCTAssertTrue(deleteConfirmation.waitForExistence(timeout: 5),"Delete confirmation not shown")
            deleteConfirmation.tap()
        }
    }
本文链接:https://www.f2er.com/3159615.html

大家都在问