Search code examples
iosinstrumentsios-ui-automationxcode-instruments

Instruments Automation Tool: Script Ended Without Explicitly Closing This Test


I was playing around with the Automation tool in Instruments today but have had problems writing a working test. The following example will exit with Issue: Script ended without explicting closing this test. Yes, the message really does say expliciting. I assume this is a typo introduced in a recent version of Xcode. This is the first time I've tried using this tool. Setting cellCount to 6 results in a Pass but anything gives me the 'script ended' message. Am I doing it wrong or is there a bug with the Automation Tool.

UIALogger.logStart("Start Simple Test");
var target = UIATarget.localTarget();
var cellCount = 7;

UIALogger.logMessage("cell count: " + cellCount);

if (cellCount != 6) {
    UIALogger.logFail("Failed");
}

UIALogger.logPass("Passed");

Solution

  • I think what's happening is you are closing your log group incorrectly. When you say logStart(), you begin a log group in instruments and everything you log after that with logMessage() or logError() will be enclosed in that group.

    You close groups with either logFail() or logPass() which it looks like you tried to do, but you can only call one or the other. You need an else clause in there to call logPass() like so:

    if (cellCount != 6) {
        UIALogger.logFail("Failed");
    } else {
        UIALogger.logPass("Passed");
    }
    

    Strangely, when I pasted your code snippet into UI Automation, I didn't get the issue error you mentioned. It just printed two log groups to the trace log. Try using the else clause like I mentioned above and see if it works.