excel 中的测试块 - 量角器 (DDT)
Testing blocks in excel - Protractor (DDT)
我通过 json 从 excel 解析数据(使用 npm 的 xlsx)。我的问题是:这个例子是茉莉花框架的最佳实践吗?我的配置:Protractor 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 开始)和 sheet 的数量(在 config.js 中声明)加载新测试。 countRows 是一个包含测试开始和位置的数组。方法 totalTests 仅计算 excel 中的 "start" 个块。
从第二行到第六行是一题,第七行是一题。
我在动态更改 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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✓</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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✗</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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✗</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;">✓</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;">✗</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;">✗</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>
问题出在全局变量中:
countRows = new req.ReadXLSX().nextTest(0, adspaceSheet);
var foo = countRows[0];
这些变量被设置为所有规格,只放了最后一个。然后将其移动到 at describe 块,现在工作正常。
我通过 json 从 excel 解析数据(使用 npm 的 xlsx)。我的问题是:这个例子是茉莉花框架的最佳实践吗?我的配置:Protractor 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 开始)和 sheet 的数量(在 config.js 中声明)加载新测试。 countRows 是一个包含测试开始和位置的数组。方法 totalTests 仅计算 excel 中的 "start" 个块。
从第二行到第六行是一题,第七行是一题。 我在动态更改 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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✓</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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✗</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;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</span></li><li>Passed.<span style="padding:0 1em;color:green;">✓</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;">✗</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;">✓</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;">✗</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;">✗</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>
问题出在全局变量中:
countRows = new req.ReadXLSX().nextTest(0, adspaceSheet);
var foo = countRows[0];
这些变量被设置为所有规格,只放了最后一个。然后将其移动到 at describe 块,现在工作正常。