在Excel中测试块 - 量角器(DDT)

时间:2016-04-22 05:08:49

标签: excel gruntjs jasmine protractor data-driven-tests

我通过excel中的json解析数据(使用npm中的xlsx)。我的问题是:这是茉莉花框架的最佳实践示例吗?我的配置:量角器2.5.1 + Jasmine 2.3.2。

countRows = new req.ReadXLSX().nextTest(0, adspaceSheet);
var foo = countRows[0];
describe("Adspace", function() {

sumOfTests = new req.ReadXLSX().totalTests(adspaceSheet);

for(var i = 0; i < sumOfTests; i++) {
    foo2 = foo;
    it("Test no. " + i + " " + parsedData[adspaceSheet][foo2].descTest + "  " + parsedData[adspaceSheet][foo2].code  , function() {
        for(var t = countRows[0]; t <= countRows[1]+1 ;t++) {
            (function(testSpec) {
                ...
                PerformTest(testSpec);
                ...      
            })(parsedData[adspaceSheet][t]); 
            if (parsedData[adspaceSheet][t].block === "STOP" || parsedData[adspaceSheet][t].block.split(",")[1] === "STOP") {
                if(t === countRows[1]) {
                    countRows = new req.ReadXLSX().nextTest(t+1,adspaceSheet);
                    foo = t + 1;
                    console.log(foo);
                    break;
                }
            }
        }        
    });
    };
});

nextTest将按位置(从0开始)和按张数(在config.js中声明)加载新的测试。 countRows是一个具有测试开始和位置的数组。方法totalTests仅计算excel中的“start”块。 DDT Excel test

从第二行到第六行就像一个测试,第七行是一行测试。 我有问题动态更改it()函数的字符串。对于多行测试仍然是相同的(第一个)但在代码中(通过console.log它没关系)我想要它(列descTest),如创建,编辑,删除+代码(来自excel)或使用第一个一排测试。

ReadXLSX包含:

...
this.totalTests = function (numberOfSheet) {
    var count = 0;
    for (var i = 0; i <data[numberOfSheet].length; i++) {
        if(parsedData[numberOfSheet][i].block) {
            if(parsedData[numberOfSheet][i].block.split(",")[0] === "START")
                count++; 
        }
    }
    console.log("_--_Sum of tests: " + count);
    return count;
};

this.nextTest = function (last, numberOfSheet) {
    var positionStart = last , positionEnd;
    for (var i = last; i < parsedData[numberOfSheet].length; i++) {
        if(parsedData[numberOfSheet][i].block) {
            if(parsedData[numberOfSheet][i].block.split(",")[0] === "START") {
                positionStart = i;
                if(parsedData[numberOfSheet][i].block.split(",")[1] &&  parsedData[numberOfSheet][i].block.split(",")[1].trim() === "STOP") {
                    positionEnd = i;
                    break;
                }
            }
            if(parsedData[numberOfSheet][i].block.split(",")[0] === "STOP") {
                positionEnd = i;
                break;
            }
        }
    }
    if(positionEnd >= 0)
        console.log("________[Start]:" + positionStart + " [Stop]:"+ positionEnd + " lenght of test: " + (positionEnd - positionStart + 1));
    return [positionStart, positionEnd];
};

包含报告的片段现在看起来如何。

<!DOCTYPE html><html><head lang=en><meta charset=UTF-8><title></title><style>body{font-family:"open_sans",sans-serif}.suite{width:100%;overflow:auto}.suite .stats{margin:0;width:90%;padding:0}.suite .stats li{display:inline;list-style-type:none;padding-right:20px}.suite h2{margin:0}.suite header{margin:0;padding:5px 0 5px 5px;background:#003d57;color:white}.spec{width:100%;overflow:auto;border-bottom:1px solid #e5e5e5}.spec:hover{background:#e8f3fb}.spec h3{margin:5px 0}.spec .description{margin:1% 2%;width:65%;float:left}.spec .resume{width:29%;margin:1%;float:left;text-align:center}</style></head><body><section><article class="suite"><header><h2>Addon - 265.692s</h2><ul class="stats"><li>Tests: <strong>10</strong></li><li>Skipped: <strong>0</strong></li><li>Failures: <strong>4</strong></li></ul> </header><div class="spec"><div class="description"><h3>Test no. 0 Creating  ABC24 - 32.667s</h3><ul><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li></ul></div><div class="resume"><br /><span>Tests passed: 100.00%</span><br /><progress max="100" value="100"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 1 Creating  ABC24 - 31.893s</h3><ul><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li></ul></div><div class="resume"><br /><span>Tests passed: 100.00%</span><br /><progress max="100" value="100"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 2 Creating  ABC24 - 26.135s</h3><ul><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li></ul></div><div class="resume"><br /><span>Tests passed: 100.00%</span><br /><progress max="100" value="100"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 3 Creating  ABC24 - 25.95s</h3><ul><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li></ul></div><div class="resume"><br /><span>Tests passed: 100.00%</span><br /><progress max="100" value="100"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 4 Creating  ABC24 - 23.539s</h3><ul><li>Expected [ 'ATON ATON AT ADDON for Life Moms 25% ADDONCAT   ' ] to contain 'ATON'.<span style="padding:0 1em;color:red;">&#10007;</span></li></ul></div><div class="resume"><a href="images//4901b9cfeb3c8d12a69f782bf83682e8.png"><img src="images//4901b9cfeb3c8d12a69f782bf83682e8.png" width="100" height="100" /></a><br /><span>Tests passed: 0.00%</span><br /><progress max="100" value="0"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 5 Creating  ABC24 - 28.059s</h3><ul><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li></ul></div><div class="resume"><br /><span>Tests passed: 100.00%</span><br /><progress max="100" value="100"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 6 Creating  ABC24 - 24.394s</h3><ul><li>Failed: invalid element state: Element is not currently interactable and may not be manipulated
  (Session info: chrome=49.0.2623.112)
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)<span style="padding:0 1em;color:red;">&#10007;</span></li></ul></div><div class="resume"><a href="images//810c45b99a64b9a7897cc7b3ec6a4fd5.png"><img src="images//810c45b99a64b9a7897cc7b3ec6a4fd5.png" width="100" height="100" /></a><br /><span>Tests passed: 0.00%</span><br /><progress max="100" value="0"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 7 Creating  ABC24 - 25.667s</h3><ul><li>Passed.<span style="padding:0 1em;color:green;">&#10003;</span></li></ul></div><div class="resume"><br /><span>Tests passed: 100.00%</span><br /><progress max="100" value="100"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 8 Creating  ABC24 - 21.2s</h3><ul><li>Failed: invalid element state: Element is not currently interactable and may not be manipulated
  (Session info: chrome=49.0.2623.112)
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)<span style="padding:0 1em;color:red;">&#10007;</span></li></ul></div><div class="resume"><a href="images//a7497aac5587fb0045b925ec02eec363.png"><img src="images//a7497aac5587fb0045b925ec02eec363.png" width="100" height="100" /></a><br /><span>Tests passed: 0.00%</span><br /><progress max="100" value="0"></progress></div></div><div class="spec"><div class="description"><h3>Test no. 9 Creating  ABC24 - 26.182s</h3><ul><li>Expected [ 'ADDON AT ADDON AT ADDON for Life Moms 25% ADDONCAT   ', 'ATON ATON AT ADDON for Life Moms 25% ADDONCAT   ', 'AT ats Moms 25% ADDONCAT   ' ] to contain 'ADDONCAT'.<span style="padding:0 1em;color:red;">&#10007;</span></li></ul></div><div class="resume"><a href="images//1b5d07ac53bc780111cfa15a29acbf4b.png"><img src="images//1b5d07ac53bc780111cfa15a29acbf4b.png" width="100" height="100" /></a><br /><span>Tests passed: 0.00%</span><br /><progress max="100" value="0"></progress></div></div>
 </article>
</section></body></html>

1 个答案:

答案 0 :(得分:0)

问题出在全局变量中:

countRows = new req.ReadXLSX().nextTest(0, adspaceSheet);
var foo = countRows[0];

这些变量设置为所有规格,只放置最后一个。然后当它移动到描述块时,现在工作正常。