I am currently developing an automation framework for a web application using WebDriver and Jasmine. The application functions as an online library, displaying various products with unique content. My automation script is designed to iterate through the different sections of each product and execute tests on them.
To test different products, I require an identifier as input. This identifier is used in the beforeAll function to fetch information about the specific product from a web service.
const identifier = process.argv[3];
describe('product check', function() {
var appData;
beforeAll(async function() {
// Retrieving data from async web service
appData = await getAppData(identifier);
})
}
The automation script should then loop over the appData structure and create expectations based on its contents.
In my understanding of implementing loops within Jasmine, expectations need to be placed inside a function and called repeatedly within the loop:
// Incorrect approach
for(var i = 0; i<appData.numInstances; i++) {
it('is within a for loop', async function() {
expect(...);
})
}
// Correct approach
function containsIt(i) {
it('is within a function', async function() {
expect(...);
})
}
for(var i = 0; i<appData.numInstances; i++) {
containsIt(i)
}
However, if the expectations are placed within a function as shown above, the automation script does not wait for the beforeAll function to complete before calling the function containing it(), resulting in an error:
TypeError: Cannot read property 'numInstances' of undefined
I have verified that getAppData() functions correctly and that appData is populated within the beforeAll() function.
While I could incorporate the loop over appData within an it() block, this would mean all my expect() statements would be grouped together in the same block, losing detailed reporting from it().
Is there a way to implement a loop where functions containing it() are called iteratively while still loading application data in the beforeAll function? If so, how can this be achieved?