-->

什么是推荐的方式来调试工作灯应用程序?(What are the recommended ways

2019-08-22 03:15发布

我发现它非常缓慢修复特定于我的应用程序的iOS的部分问题。 我想知道内情的推荐方式调试工作灯的应用程序时,浏览器的调试器不可用。

特别是,我正在与WL.JSONStore只适用于iOS和Android的问题。 我无法使用浏览器的调试器,看看发生了什么事情。 当我做WL.Logger.debug()语句,什么都不显示了在Xcode的控制台,而iPad模拟器控制台(科尔多瓦)只显示了几行。 也有一些这个星期没有输出任何地方打印时间。

我已经下载并安装过Weinre,但是没有打印语句出现在它的控制台显示出来,并在一般我只是没有看到关于我所需要的区域的信息。

在此先感谢您的建议。

Answer 1:

一般工作灯5.0.6调试

  • 看看题为培训模块调试应用程序 。 ( 直接PDF链接 )

调试技巧JSONStore上工作灯5.0.6

  • 尝试console.log('message')WL.Logger.debug('message')的内部jsonstore.js和代码( [app-name].js等)。 输出应该在Xcode的控制台和Android的logcat中显示出来。
  • 重置模拟器或仿真器和/或呼叫WL.JSONStore.destroy()
  • 确保您在支持的环境中运行:
    • 的Android> = 2.2 ARM / x86模拟器或设备
    • 的iOS> = 5.0模拟器或设备
  • 尝试打开关闭加密功能(即不通过密码来WL.JSONStore.initWL.JSONStore.initCollection )。
  • 看看由JSONStore产生的SQLite数据库文件。 这仅是加密过的作品。

    • 安卓:

       $ adb shell $ cd /data/data/com.[app-name]/databases/wljsonstore $ sqlite3 jsonstore.sqlite 
    • iOS版

       $ cd ~/Library/Application Support/iPhone Simulator/6.1/Applications/[id]/Documents/wljsonstore $ sqlite3 jsonstore.sqlite 

    尝试寻找在与searchFields .schema ,并选择数据SELECT * FROM [collection-name]; 。 要退出sqlite3类型.exit 。 看看这个StackOverflow的问题的一个例子。

  • (仅限Android)启用详细JSONStore。

     adb shell setprop log.tag.jsonstore-core VERBOSE adb shell getprop log.tag.jsonstore-core 
  • (的iOS> = 6.0和Safari> = 6.0只)尝试使用JavaScript调试器 。 里面设置断点jsonstore.js 。 有用行:

    • 桥本机代码:

       cdv.exec(options.onSuccess, options.onFailure, pluginName, nativeFunction, args); 
    • 成功回调从本机代码返回:

       deferred.resolve(data, more); 
    • 失败回调从本机代码返回:

       deferred.reject(new ErrorObject(errorObject)); 
  • 写正确的测试(单元,功能齐全,集成 - 获得测试覆盖率)。 下面是一个使用一个模板QUnit和Sinon.js创建一个沙箱环境中,你可以测试JSONStore如何处理不同类型的数据/电话:

     <!DOCTYPE HTML> <html> <head> <title>JSONStore Test App</title> <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css"> <script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script> <script src="http://sinonjs.org/releases/sinon-1.6.0.js"></script> <script> //QUnit configuration flags, no need to change it. QUnit.config.requireExpects = true; </script> </head> <body id="content" style="display: none;"> <!-- Test results will be appended to the div below, no need to make changes here. --> <div id="qunit"></div> <script> //Start Worklight WL.Client.init({connectOnStartup : false}); //Hook into the deviceready event document.addEventListener("deviceready", onDeviceReady, false); //onDeviceReady will be called when JSONStore/Cordova is ready function onDeviceReady () { //Auto executing function that holds the test (function (jQuery) { //The variable jQuery is usable inside. //Mock WL.Client.invokeProcedure using a Stub. //This is only useful if you need to link a Worklight Adapter //to a JSONStore collection to reproduce your issue or bug. //API Doc: http://sinonjs.org/docs/#stubs var fakeAdapter = sinon.stub(WL.Client, "invokeProcedure", function (invocationData, options) { //DO NOT Create a real adapter, just mock the reponse here if it's relevant to the bug. var ADAPTER_RESPONSE = {invocationResult: {fakeKey: [{fn: 'carlos'}, {fn: 'mike'}]}}; options.onSuccess(ADAPTER_RESPONSE); }); //[**Explain your test here**] var EXPECTED_ASSERTIONS = 2; //every assertion is a deepEqual below. asyncTest('[**Meaningful title here**]', EXPECTED_ASSERTIONS, function () { //Destroy first to make sure we don't depend on state WL.JSONStore.destroy() .then(function () { //[**Start writting your test here**] //The test below is an example, it does the following: // - Initializes a collection linked to a fake adapter (see stub above). // - Checks if initialization worked by checking the collection name. // - Loads data from the fake adapter (see stub above). // - Checks if load worked by checking the number of documents loaded. var collections = { col1 : { searchFields : {fn: 'string'}, adapter : {name: 'fakeAdapter', load: { procedure: 'fakeProcedure', params: [], key: 'fakeKey' } } } }; return WL.JSONStore.init(collections); }) .then(function (response) { //Prep for your assertion var ACTUAL_VALUE = response.col1.name; var EXPECTED_VALUE = 'col1'; var COMMENT = 'Checking for the right collection name'; //Do your assertion using deepEqual //API Doc: http://api.qunitjs.com/deepEqual/ deepEqual(ACTUAL_VALUE, EXPECTED_VALUE, COMMENT); return WL.JSONStore.get('col1').load(); }) .then(function (response) { //Prep for your assertion var ACTUAL_VALUE = response; //load returns number of documents loaded var EXPECTED_VALUE = 2; //two documents are returned by the fake adapter (stub) var COMMENT = 'Checking if load worked'; //Do the assertion using deepEqual deepEqual(ACTUAL_VALUE, EXPECTED_VALUE, COMMENT); start();//call start() after you finish your test succesfully }) .fail(function (error) { deepEqual(false, true, 'Failure callback should not be called' + error.toString()); start();//call start() after you finish your test with a failure }); }); }(WLJQ)); //end auto executing function that holds the test } //end wlCommonInit </script> </body> </html> 

以上代码的预期输出:

边注:这是一个普通的文章有关的PhoneGap /科尔多瓦工作流程特定开发商。 有调试的一部分,只是虽然基于浏览器的。 其中一些适用于IBM工作灯发展了。



Answer 2:

cnandreu这里提供了很大的提示。 尽管如此,能见度相当差和这些方法并没有真正解决我的问题。 我想也有什么建议,我发现在我的项目(除了WL.Logger.debug()无处不在)最有用:

  • JSConsole已经不可或缺( http://jsconsole.com/ )。 在现实中,我实际上并不使用它,许多喜欢它的预期。 然而,我发现,它的启动警告信息做一些事WL.Logger.debug()(和执行console.log()),使报表实际打印到控制台上,所以我可以看到我在做什么。

  • 在iOS 6中的Safari在Mac上,您可以检查连接的设备的DOM。 这是一定的用处,特别是在iOS本机运行时,只有行为不端混合UI的问题。 我并不觉得超级有帮助的,否则。 多见于https://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/DebuggingSafarioniPhoneContent.html

  • 我一直在使用的一个最有用的技术已经写入状态消息的UI。 是的,这是应该做的事情丑陋的史前方式,但一切 - 包括80个年代的错误报表打印到控制台 - 非常失败。 这是我(使用道场和JavaScript的)这样做:

    var v = dom.byId('audio_status'); if (v) { v.innerHTML += "recording file ["+filename+"]"; }

audio_statusID显示的调试内容的DIV的。

这东西是丑陋的,但至少我们可以看到的东西



文章来源: What are the recommended ways to debug Worklight applications?