如何为protractor-html-screenshot-reporter添加额外的列,例如每个“it”块的持续时间

时间:2015-08-28 08:01:53

标签: angularjs jasmine protractor

我正在尝试在HTML报告中添加一个额外的列。就像每个“它”块的持续时间一样。我在 jsonparser.js 文件中尝试了这个。

phssr.makeHTMLPage = function(tableHtml, reporterOptions){
    var styleTag = phssr.makeHardCodedStyleTag(reporterOptions);
    var scrpTag = phssr.makeScriptTag();

    var staticHTMLContentprefix = "<html><head><meta charset='utf-8'/>";

    //Add title if it was in config setup
    if (typeof (reporterOptions.docTitle) !== 'undefined' && _.isString(reporterOptions.docTitle) ){
        staticHTMLContentprefix += "<title>" + reporterOptions.docTitle + "</title>";
    } else {
        staticHTMLContentprefix += "<title></title>";
    }

    staticHTMLContentprefix +=  styleTag + scrpTag + " </head><body>";
    staticHTMLContentprefix +=  "<h1>" + reporterOptions.docHeader + "</h1><table class='header'>";
    staticHTMLContentprefix +=  "<tr><th class='desc-col'>Description</th><th class='status-col'>Passed</th>";
    staticHTMLContentprefix +=  "<th class='browser-col'>Browser</th>";
    staticHTMLContentprefix +=  "<th class='os-col'>OS</th><th class='msg-col'>Message</th>";
    staticHTMLContentprefix +=  "<th class='msg-col'>Duration</th>";
    staticHTMLContentprefix +=  "<th class='img-col'>Screenshot</th></tr></table>";

    var staticHTMLContentpostfix = "</body></html>";
    var htmlComplete = staticHTMLContentprefix + tableHtml + staticHTMLContentpostfix;

    return htmlComplete;
}

phssr.getTimestamp = function (date) {
            function pad(n) { return n < 10 ? '0' + n : n; }
            var currentDate = date !== undefined ? date : new Date(),
                month = currentDate.getMonth() + 1,
                day = currentDate.getDate();
            return (currentDate.getFullYear() + "-" + pad(month) + "-" + pad(day) + " " + pad(currentDate.getHours()) + ":" + pad(currentDate.getMinutes()) + ":" + pad(currentDate.getSeconds()));
}

var sTime = new Date();
var startTime = phssr.getTimestamp(sTime);
console.log("sTime***********************",startTime);

var passCount=0, failCount=0, loopCount=0;
function generateHTML(data){
    var eTime = new Date();
    var endTime = phssr.getTimestamp(eTime);
    console.log("eTime***********************",endTime);
    var diffTime = (eTime-sTime)/1000;

    console.log("dTime***********************",diffTime);

    data.passed? passCount++: failCount++;
    var str = '<table><tr>';
    str +=  '<td class="desc-col">' + data.desc + '</td>';
    var bgColor = data.passed? 'green': 'red';
    str +=  '<td class="status-col" style="color:#fff;background-color: '+ bgColor+'">' + data.passed + '</td>';
    str +=  '<td class="browser-col">' + data.browser.name+ ':' +data.browser.version + '</td>';
    str +=  '<td class="os-col">' + data.os + '</td>';
    var stackTraceInfo = data.passed? '': '<br/><a onclick="showTrace(event)" href="#trace-modal'+loopCount+'">View Stack Trace Info</a><br/> <div id="#trace-modal'+loopCount+'" class="traceinfo"><div><a href="#close" onclick="closeTraceModal(event)" title="Close" class="close">X</a>' + data.trace + '</div></div>';

    str +=  '<td class="msg-col">' + data.message+ stackTraceInfo+ '</td>';
    str +=  '<td class="msg-col">' + diffTime + '</td>';

    if(!(reporterOptions.takeScreenShotsOnlyForFailedSpecs && data.passed)) {
        str +=  '<td class="img-col"><a href="#" onclick="openModal(\'' + path.basename(data.screenShotFile)+ '\')">View </a></td>';
    }
    else{
        str +=  '<td class="img-col"></td>';
    }

    str += '</tr></table>';
    loopCount++;
    return str;

}

我可以在报告中看到额外的列。问题是它没有显示正确的时间。在控制台中,它就像这样打印

sTime*********************** 2015-08-28 13:26:44
Using the selenium server at http://localhost:4444/wd/hub
.eTime*********************** 2015-08-28 13:26:48
dTime*********************** 3.312
.eTime*********************** 2015-08-28 13:26:52
dTime*********************** 7.984
eTime*********************** 2015-08-28 13:26:52
dTime*********************** 7.984
.

Finished in 12.123 seconds
3 tests, 3 assertions, 0 failures

eTime*********************** 2015-08-28 13:26:57
dTime*********************** 12.325
eTime*********************** 2015-08-28 13:26:57
dTime*********************** 12.325
eTime*********************** 2015-08-28 13:26:57
dTime*********************** 12.325

在这里,我不知道它为什么要执行两次。在报告中,它显示所有块的12.325。我不知道我在哪里做错了。请帮帮我。

试验:

describe('Title', function() {
           it('TESTCASE-1 : Should have a title', function() {
             expect(browser.getTitle()).toContain('Test');
           });

             it('TESTCASE-2 : Should accept a valid email address and password', function() {

              element(by.id('email')).sendKeys('*********');
              element(by.id('password')).sendKeys('*********');
              element(by.css('.btn')).click();         
              expect(browser.getCurrentUrl()).toEqual('*********/app/#/home');
              });

         it('TESTCASE-4: Dashboard Selection.....', function(){ 
             var menubutton = element.all(by.css('.btn')).get(0);
             menubutton.click();
             expect(browser.getCurrentUrl()).toEqual('*************************/students/1');
         });
    });

0 个答案:

没有答案