Ios 执行XCUITest时,点击“当前视图中不工作的方法”

Ios 执行XCUITest时,点击“当前视图中不工作的方法”,ios,swift,ios-simulator,xcode-ui-testing,xcuitest,Ios,Swift,Ios Simulator,Xcode Ui Testing,Xcuitest,我有一个带有小部件的应用程序,我需要自动创建它的屏幕截图 然而,我很难做到这一点,因为我不能点击“编辑”按钮在今天的看法。如果没有安装小部件,则可以轻松单击该按钮。但是,在模拟器重置后,会出现小部件(地图、提醒、快捷方式等),并且按钮不再可单击。更糟糕的是,“isHittable”返回true:( 我尝试运行的代码是: let app = XCUIApplication() app.launch() app.activate() // Open Notification Center by s

我有一个带有小部件的应用程序,我需要自动创建它的屏幕截图

然而,我很难做到这一点,因为我不能点击“编辑”按钮在今天的看法。如果没有安装小部件,则可以轻松单击该按钮。但是,在模拟器重置后,会出现小部件(地图、提醒、快捷方式等),并且按钮不再可单击。更糟糕的是,“isHittable”返回true:(

我尝试运行的代码是:

let app = XCUIApplication()
app.launch()
app.activate()

// Open Notification Center by swiping down
let bottomPoint = app.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 2))
app.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)).press(forDuration: 0.1, thenDragTo: bottomPoint)
sleep(1)

// now swipe to reveal Today View (uses custom method)
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboard.scrollViews.firstMatch.swipeRight()
sleep(1)

// To make sure Edit button is visible, swipeUP
springboard.scrollViews.firstMatch.swipeUp()
sleep(2)

// Now tap the edit button (DOESN"T WORK)
springboard.buttons["Edit"].press(forDuration: 1)
sleep(2)
我创建了一个简单的项目来说明所定位的bug

要亲自查看错误,请打开iPhone 11 Pro Max并将以下小部件添加到“今日视图”:

  • 提醒
  • 历法
  • 地图目的地
  • 捷径
  • 新闻
  • 然后,尝试从
    xguitests
    运行
    testExample
    测试。如果成功,最后应单击编辑按钮,您将看到编辑屏幕。但是,从未单击过:(

    如果有人能帮我找到一个很好的解决方案。我已经尝试了我能想到的所有方法,但都不起作用…

    有时
    tap()
    失败或什么也不做。一个常见的解决方案是点击元素的坐标,而不是元素本身

    扩展XUIElement{
    func tapUnhittable(){
    runActivity(命名为:“按坐标点击\(self)”{in
    坐标(使用规格化偏移:CGVector(dx:0.0,dy:0.0)).tap()
    }
    }
    }
    
    下面是有效的代码

    导入XCTest
    类XCuitestTests:XCTestCase{
    func testExample()抛出{
    让app=xguiapplication()
    app.launch()
    让底部点=应用坐标(使用规格化偏移:CGVector(dx:0,dy:2))
    应用坐标(使用规格化偏移:CGVector(dx:0,dy:0))。按(持续时间:0.1,然后拖动到:底点)
    让springboard=XCUIApplication(bundleIdentifier:“com.apple.springboard”)
    跳板
    跳板
    springboard.buttons[“编辑”].tapUnhittable()
    }
    }
    
    幸好你修改了代码。我复制了这个bug。