I am a beginner in Cypress. I use Cypress with javascript to perform automation testing.
Question: How can I iterate all it blocks n times?
Description: In a JSON file, one key has an array including names of different profiles. I have one spec file, in which I have multiple it()
blocks. Now I want to run my spec file for all profiles available in a key.
For that, I tried below solution:
TestData.JSON
{
"test": {
"customerAccountName": "RD test R97 01 new",
"userRole": "Customer Admin",
"profiles": ["Generic SIP Service", "Genesys PureCloud"],
"profile": "",
"serviceCarrier": "",
"isCarriage": "",
"type": "",
"blockSize": ""
}
"stage": {
"customerAccountName": "RD test R97 01 new",
"userRole": "Customer Admin",
"profiles": ["Generic SIP Service", "Genesys PureCloud"],
"profile": "",
"serviceCarrier": "",
"isCarriage": "",
"type": "",
"blockSize": ""
}
TestSpec.js
describe("Create, edit, pause, resume and delete Generic SIP Service", function () {
let siteTestData, credentials, SIPServiceTestData, profiles;
before(function () {
cy.fixture('credentials').then(function (testdata) {
credentials = testdata[window.environment]
//Login to a portal if require
if (isLoginRequire(credentials.sausername, credentials.sapassword)) {
cy.loginAs(credentials.url, credentials.sausername, credentials.sapassword)
}
})
//Get test data from 'genericSIPServiceTestData' file
cy.fixture('SIPServiceTestData').then((testData) => {
SIPServiceTestData = testData[window.environment]
profiles = SIPServiceTestData.profiles
})
//Get test data from 'siteTestData' file
cy.fixture('siteTestData').then(function (testdata) {
siteTestData = testdata[window.environment]
//If siteName is empty, add site name
if (siteTestData.siteName == '') {
siteTestData.siteName = 'Automation site ' + getUTCTime()
}
//If siteEmail is empty, add site email
if (siteTestData.siteEmail == '') {
siteTestData.siteEmail = 'automationtestsite' + getUTCTime() + '@gmail.com'
}
//If updateSiteName is empty, add site name to update
if (siteTestData.updateSiteName == '') {
siteTestData.updateSiteName = 'Update ' + siteTestData.siteName
}
})
})
it(“Load test profiles”, function () {
Array.from(profiles).forEach($profile => {
describe('test json loop', function () {
beforeEach(() => {
SIPServiceTestData.profile = $profile
})
after(() => {
console.log('inside after')
// Only log out if require
if (isLoginRequire(credentials.sausername, credentials.sapassword)) {
cy.logout();
}
});
it("Navigate to Customer account", function () {
//Navigate to customer account
clickCustomer(SIPServiceTestData.customerAccountName)
//Verify services header on services page
verifyServicesHeader()
})
it("Verify either account is existing or new", function () {
isAccountNew(siteTestData)
})
it("Click on 'Add new service' button, select SIP service and Navigate to 'Select numbers' page", function () {
//Click on services tab
clickServicesTab();
//Add service button should be enable on services page
getAddServiceButton().should('be.visible').and('be.enabled').and('have.text', 'Add New Service').click();
//Select profile and carrier, and navigate to select numbers page
selectProfileAndCarrier(SIPServiceTestData);
//Verify sub header
getAccountName().should('be.visible').and('have.text', SIPServiceTestData.customerAccountName)
//Verify header section and search field on select numbers page
verifyHeaderOnSelectNumberPage(SIPServiceTestData)
//Verify tooltip text on hover of inventory number on select number page
verifyTooltipOnSelectNumberPage()
//Select number
selectNumberForServices()
//Set details of selected number into json
setSelectedNumberDetails(SIPServiceTestData)
})
})
})
});
})
When I run above code it works fine. But Cypress chrome window doesn’t show all it blocks in it’s UI.
Is there any solution for this issue? If not…
Is there any other solution to iterate it block multiple times and it works normally?