My current project setup: I am currently conducting dynamic tests on cypress where I receive a list of names from environment variables. The number of tests I run depends on the number of names in this list.
What I aim to achieve: My main goal is to manipulate the array containing the list in such a way that if it includes the word 'ALL' passed through the environment variable, I want to modify the array by adding all names obtained through an API call. This approach avoids the need to manually input each name individually.
The issue I am facing: Despite using beforeEach() before the test runs, the value within my array remains unchanged and still reflects the original value obtained from the environment variables. I suspect that the code outside it() and beforeeach(), but within describe(), executes first... However, even after the beforeEach() updates the array, the tests continue to use the outdated value sourced from the environment variable.
I intend to conditionally update my array based on the content passed in the environment variable "ALL" or specific names.
This excerpt shows my current code structure:
describe('[' + Cypress.env('TEAM') + ' - ' + Cypress.env('CLUSTER') + '] - ', () => {
let dataPoolsArray: string[] = Cypress.env('DATAPOOLS').split(',') // directly fetched from env variable
beforeEach(() => {
cy.defaultLogin()
if ( Cypress.env('DATAPOOLS') === 'ALL') { // Depending on the env variable, I want to modify the array value here
dataPoolsArray.length = 0
let i = 0
cy.Integration_DataPool_findAll().then((getDataPoolsResponse) => {
getDataPoolsResponse.body
.forEach((dataPool: any) => {
dataPoolsArray.push(dataPool.name)
cy.log('dataPoolsArray: ' + dataPoolsArray[i])
i ++
})
})
}
})
// Initial problem arises as only "ALL" is taken as the array value when running the test
dataPoolsArray.forEach((poolName) => {
it('Data Model for pool: ' + poolName, () => {
cy.log('Checking if datamodel loaded for the pool: ' + poolName)
cy.sendPqlQueryToAnalysisConnectedToPool(poolName)
})
})
})
Any assistance provided would be greatly appreciated.