3

I'm trying to automate parts of my UI testing using XCUITest. I wan't the test do automatically do parts of the test, and then wait for me to do some stuff manually. Is there a good way to do this?

Right now I'm just doing this:

class QDBUITestHost: XCTestCase {

  override func setUp() {
    continueAfterFailure = false
    XCUIApplication().launch()
  }

  override func tearDown() {}

  func testHosting() {
    let app = XCUIApplication()
    app.buttons["Select Group"].tap()
    app.sheets.buttons["com-mist-qdb-1"].tap()
    app.buttons["Host"].tap()
    sleep(600) // This is an ugly hack
  }

}

So, is there a better way to do this, rather than to just sleep(600)?

eivindml
  • 2,197
  • 7
  • 36
  • 68
  • 2
    Add breakpoints in the XCUITest... – emreoktem Nov 11 '18 at 23:43
  • 1
    The whole point of UITests is to automate UI testing. If you need to interfere with it, you either didn't set them up fully or it's work in progress and might as well test manually. As others said, you can use breakpoints but if you need 10 minutes wait, I suspect you're running a few changes while putting the test in standby, so manual testing and once you know what you're trying to achieve set up your accessibilityIdentifiers on all the components? – Alex Ioja-Yang Nov 21 '18 at 10:35
  • 2
    I second Alex's notion in general, but want to point something out in addition. Whether by a `sleep(x)` or a breakpoint, you completely halt the test process, which is probably not a good idea (as it contains some behind-the-scenes stuff to track the app that's being tested, e.g. it checks for the app to become idle, as indicated by the logs). That might make the entire process not just a bad approach, but also fickle. Maybe you want to edit the question to explain why you want to do that? Perhaps this gives you a better way out of a, perhaps only perceived, problem you try to solve. – Gero Nov 21 '18 at 10:50
  • This feels like an XY problem, that might be sovled in a better way if you could give more details as to what exactly you need this pause for. This could be useful to reach a point where your whole suite is automated, which would be kinda required if you want to have your code regularly and automatically tested (on a CI server for example). – JBL Nov 26 '18 at 14:02

1 Answers1

0

There is a xctwaiter framework.

You can use expectations to wait the results. They are very flexible.

let result = XCTWaiter().wait(for:[expectation], timeout: 10)

How to use an expectation you can see in the documentation. An example.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194