问题
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");
回答1:
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.
回答2:
I found out the real issue here. It is basically saying that your app is not in usable mode to test further at specified point. So please either pass/fail or add appropriate delay at this place.
So easiest solution to avoid this is to have one delay function of 2 sec after each page navigation. That will load data in each page after fetching and displaying data on pano. And script will run smoothly.
//Step:1 Navigating/tapping
UIATarget.localTarget().delay(2);
//verification
//Step: 2 Navigating/tapping
UIATarget.localTarget().delay(2);
//verification
回答3:
How odd. I'm experiencing this same issue precisely as described above and I am also using the else
clause.
Also, I tried the double logging method as mentioned above like so, just before my if
statement to log pass or fail:
UIALogger.logMessage("My Story Title: " + titleDisplayed);
UIALogger.logMessage("Innocuous Message.");
And got a FAIL, which is fine--I wanted anything other than the "Issue
" result and the "script ended without expliciting
" message. So, I then commented //
the second logMessage
statement and re-ran the test and this time got the "Issue
" and "script ended without explicating
" again.
So, his above tip has been verified as real.
I'm running Xcode and Instruments version 4.6 with the iPhone Emulator running as a 6.1 project.
---Update--
I cannot get pass/fail to work properly no matter what I do. On one run I get the enraging "Issue: Script ended without explicating
" message in my log, and then if I make any changes to the script--even if it's just to add an extra whitespace, and save it and then run again--I'll get a good pass or fail result.
But if I then immediately run the test again without any changes at all I'll get the "Issue: Script ended without explicating
" message and this will not go away until I make a meaningless change in the script and save and then run again and then MAYBE at this point I might get a decent pass/fail result (doesn't always happen), but if I run the script again I will get "Issue: Script ended without explicating
" again.
What the heck? I've actually taken the time to reinstall Xcode 4.6 but no luck in getting the behavior to change. I'm profoundly frustrated. This appears to be a bug in Instruments. Is there a way to report this to Apple?
回答4:
I had this issue too. You have to have the string you put on your logStart method in the logPass or logFail method too - that's all! Which would mean for example:
UIALogger.logStart("Add to Whishlist");
//here comes your automation code
UIALogger.logPass("Add to Whishlist");
You can open then another test with the logStart()
and close it either with logPass()
methods
回答5:
I found out, that if you place delays between the different messages, they actually show up and evaluate the problems. The issue I started with was, that two successive logMessages did not show up correctly (the last one being dropped)
UIALogger.logMessage("This is some text");
UIALogger.logMessage("This is some text");
//UIATarget.localTarget().delay(1);
only showed one output line. Uncommenting shows two... This seems somewhat... inconsistent - and there is more: (This goes to Wulf)
UIALogger.logStart("Add to Whishlist");
UIALogger.logMessage("My Story Title: ");
//UIATarget.localTarget().delay(1);
UIALogger.logMessage("Innocuous Message.");
//UIATarget.localTarget().delay(1);
if (true)
UIALogger.logPass("Add to Whishlist");
else
UIALogger.logFail("Add to Whishlist");
Here I got an "issue". Uncommenting helped to solve this. I know, this is no solution. But it worked as a workaround for me.
The "string" in the logStart, logFail or logPass did not matter for me actually.
来源:https://stackoverflow.com/questions/14865999/instruments-automation-tool-script-ended-without-explicitly-closing-this-test