0

I parse data through json from excel (using xlsx from npm). My question is: is this example best practice with jasmine framework ? My config : 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 will load new test by position (starting at 0) and by number of sheet (declare in config.js). countRows is a array with start and position of test. Method totalTests only count of "start" blocks in excel. DDT Excel test

From second to sixth row is like one test, the seventh row is one test like one row. I have problem with dynamic changing the string of it() function. For multi-line test is still the same (the first) but in code (via console.log it's ok) I want to marge it (column descTest), like Creating, Editing, Deleting + code (from excel) or use the first row of test.

The ReadXLSX contain:

...
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];
};

Snippet containing report how looks now.

<!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>
Kex
  • 93
  • 1
  • 9

1 Answers1

0

The problem was in global variables:

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

These variables were set to all specs, that put only the last one. Then when moved it to at describe block and now works fine.

Kex
  • 93
  • 1
  • 9