locked
Getting console output from a HTML5/Javascript app

    Question

  • I have a HTML5/JavaScript app that we use for testing a javascript component.  We automated the installation and execution of this app with the advice found here http://blogs.msdn.com/b/windowsappdev/archive/2012/09/04/automating-the-testing-of-windows-8-apps.aspx.

    When the app starts up, it runs a suite of tests and writes a file indicating success. 

    The problem is that we have no way to get the javascript console output of the app while it is running.  This info is critical if an error is hit to help with diagnosing the problem. 

    Is there a simple way to get the information in the JavaScript console written while this app is not under a debugger? 

    Thursday, July 18, 2013 10:38 PM

Answers

  • Hello,

    To output information while app running, I would like to suggest you check the WinJS.log function at

    http://msdn.microsoft.com/en-us/library/windows/apps/jj150612.aspx

    How to use it, please refer the following sample

    function ClickEventHandler(eventInfo) {      
            WinJS.log && WinJS.log("error message", "sample", "status");
        }
    
        var lastError = "";
        var lastStatus = "";
        WinJS.log = function (message, tag, type) {
            var isError = (type === "error");
            var isStatus = (type === "status");
    
            if (isError || isStatus) {
                var statusDiv = /* @type(HTMLElement) */ document.getElementById("statusMessage");
                if (statusDiv) {
                    statusDiv.innerText = message;
                    if (isError) {
                        lastError = message;
                        statusDiv.style.color = "blue";
                    } else if (isStatus) {
                        lastStatus = message;
                        statusDiv.style.color = "green";
                    }
                }
            }
        };

    Hope this helps, thanks.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 22, 2013 9:04 AM
    Moderator