0

I have a page control that spans the whole width of the screen. When tapping on the left side, the valueChanged function is called, and pageControl.currentPage is less one less. When tapping on the right side, the opposite happens. How do I simulate the tap to the left or right in UI Test?

let pc = XCUIApplication().pageIndicators["pageControl"]
pc.tap() // cannot specify left or right hand tap
matchifang
  • 5,190
  • 12
  • 47
  • 76

1 Answers1

0

You should change the X offset of the tap. The easiest way to get the right half of a standard UIPageControl is getting its width and subtracting 1 from it.

func tapPageControl(isRightTap: Bool) {
    let pageControl = XCUIApplication().pageIndicators["pageControl"]
    let xOffset = isRightTap ? pageControl.frame.width - 1 : 0
    let coordinate = pageControl.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: xOffset, dy: 0))
    coordinate.tap()
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223