After previously posting a similar question, I wanted to clarify and focus my query further. That's why I am reposting here (should I continue editing the previous post instead?)
I'm currently working on writing end-to-end test specs for AngularJS using Protractor.
Within the Protractor spec, I am incorporating JavaScript as well.
The issue I am facing is that the JavaScript counter variables are not functioning as expected.
Let me share the relevant code snippet below:
// The code within this describe block has been perplexing :( Let's refer to it as 'sample 1'
//'use strict';
describe('list page ', function () {
it('should list page', function () {
browser.get('/list');
var counterA = 0;
element.all(by.repeater('page in pages')).each(function (page) {
counterA++;
//console.log(counterA);
})
//console.log(counterA);
// This expectation needs to hold true :(
expect(counterA).toBeGreaterThan(0);
})
});
// Testing against a Protractor spec; written within the same js file. We'll call this 'sample 2'
bigitems = [["somevalue", "t", "y"], ["somevalue", "somevalue", "y"]];
counterB = 0;
for (smallitems in bigitems) {
for (item in bigitems[smallitems]) {
if (bigitems[smallitems][item] == "somevalue") { counterB++; }
}
}
console.log(counterB)
One observation is that 'sample 2' with counterB is functioning correctly and returns '3' to the console. However, 'sample 1' returns 0 for counterA outside the .each{} block.
Below is the console output.
Using the selenium server at http://localhost:4444/wd/hub
3
0
1
2
3
4
5
6
.
Finished in 11.877 seconds
1 test, 1 assertion, 0 failures