iosswifttableviewuisliderxcode-ui-testing

UI Testing: Slider fails to adjust when nested in Table View Cell


In UI Testing on Xcode 9.0 (9A235), interacting with UISliderwith adjust(toNormalizedSliderPosition:) does not work at all when UISlideris nested in a UITableViewCell.

I have tested in many different scenarios: - Normal UISliders not embedded in a UITableView work fine with the adjust method. - UISlider that co-exists with a UITableView but not inside a Table View Cell continues to work with adjust - UISlider in a UITableView can be uniquely identified. - UISlider identified in a UITableView can respond to simple event like tap() - UISlider identified in a UITableView doesn't work with adjust method at all, even when I modify the number of rows to 1. The error message is:

Failure fetching attributes for element pid: 24415, elementOrHash.elementID: 106102876671744.43: Error Domain=XCTDaemonErrorDomain Code=13 "Fetching value for attribute 5011 returned AX error -25205." UserInfo={NSLocalizedDescription=Fetching value for attribute 5011 returned AX error -25205.}

Related discussion I found online: https://forums.developer.apple.com/thread/77445

I have uploaded my code online too if anyone is interested in looking at it.

I have already submitted a bug report to Apple regarding this. What I am asking is, does anyone know of a possible workaround I can use to adjust the UISlider values when the slider is nested in a UITableViewCell? Thanks!


Solution

  • You can use this as a workaround:

    func testSliderAdjustsInTableView() {
        let app = XCUIApplication()
    
        app.staticTexts["Slider in Table View UI Test"].tap()
    
        let cell = app.tables.element.cells["cell 0"]
        let button = cell.buttons["Test Button"]
        button.tap()
    
        let slider = cell.sliders["value slider"]
        XCTAssert(slider.exists)
    
        let fiftyPercent = slider.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
        let ninetyPercent = slider.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5))
    
        fiftyPercent.press(forDuration: 0.1, thenDragTo: ninetyPercent)
    
        XCTAssertEqual(slider.value as! String, "90 %")
    }