I run into issue with viewport issue and I didn't find the solution yet.
describe('Tests', function () {
beforeEach(function () {
});
viewports.forEach((viewport) => {
it.only(`Test: ${viewport}`, function () {
cy.viewportAdjust(viewport);
})})})
I used cy.viewportAdjust(viewport);in my test and it works, however I wish to move cy.viewportAdjust(viewport); to beforeEach section but for tests it uses last value of viewportsArray
I'm not entirely sure what cy.viewportAdjust() does, as that looks to be a custom function. If the function simply calls cy.viewport() or updates the viewport, the following will work. Additionally, with not knowing what the values in viewport are, I can't give an exact complete answer, but the general idea is that you can pass in your viewportWidth or viewportHeight in the it() block.
viewports.forEach((viewport) => {
it.only(`Test: ${viewport}`, { viewportWidth: viewport }, function () {
cy.viewportAdjust(viewport);
})
})
Im going to answer this question exactly how you asked. But I would not suggest doing it this way though without seeing everything that you are trying to do I don't have 100% confidence in this statement.
describe('Tests Viewports', () => {
const viewports = ['iphone-6', 'ipad-2', 'ipad-mini'] //insert viewport you wish to test here
let x = 0
beforeEach( () => {
cy.viewport(viewports[x])
//Do a thing
x += 1
})
viewports.forEach( (viewport) => {
it(`Tests: ${viewport}`, () => {
cy.log(viewport)
})
})
})
I would instead suggest removing the beforeEach block and putting your code within the it block.