Logging value of a variable in MonkeyTalk IDE Javascript file

孤人 提交于 2019-12-11 03:43:04

问题


I'm using MonkeyTalk IDE Beta2 for testing iPad application. I exported the javascript from the MonkeyTalk IDE and got a new .js file. I am storing the Boolean value of a Verify command in a var and want to see what is its value, and accordingly do custom logic. I tried document.write, console.log and alert used in javascript but got an error that they are not defined. Please help me with this.

Also, is it possible to output the result of a test as XML (as in FoneMonkey) or as an Excel spreadsheet or something like that?

Thank you in advance.


回答1:


Believe it or not*, but to date there is no way direct way to cause MonkeyTalk to log messages to the console. What you can do, however, is abuse a command like verifyNot which will result in a log message. In a MonkeyTalk .mt this would be done like:

View * VerifyNot Message

I created the following helper script called log.js for this purpose. Timestamps are automatically added by Eclipse, but not elsewhere so I have prepended the time.

load("libs/Executor.js");

function getTimeStamp() {
    var now = new Date();
    return now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
}

EXECUTOR.defineScript("Log", function(msg) {
    this.app.view().verifyNot(getTimeStamp() + ": " + msg);
});

Finally, you don't need the executor boilerplate (only the verifyNot line), but we use that with scripts by Doba in order to be able to organize files in different directories (Doba.js renamed to Executor.js) -- another feature not available out of the box.

* It's almost like GorillaLogic doesn't want you to be able to resolve your own problems. ;)



来源:https://stackoverflow.com/questions/10311084/logging-value-of-a-variable-in-monkeytalk-ide-javascript-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!