I have to ask for help here. I'm still learning Cypress and trying to add query param to each URL and validate that some modal appears on the page when query param is added. So the way it looks:
urls = [ "/en/link1/", "/en/link2/", "/en/link3/", ]
queryParam = [ "?param1", "?param2", "?param3", ]
I need to write code that would do for me
and so on...
Could you please advise me how to do this? I'd rly appreciate any advice/link to material. Thanks a lot and happy coding!
describe("My test", () => {
urls.forEach(url => {
params.forEach(param => {
it(`should check smthng`, () => {
cy.visit(url + param)
cy.checkCondition()
})
})
})
You can use cy.request version taking options as argument: https://docs.cypress.io/api/commands/request#Options
cy.request({
url: "/en/link1",
qs: {
"param2": "test"
}
})
You can use nested ForEach Loops to iterate over both arrays and make the combinations like this:
const urls = ['/en/link1/', '/en/link2/', '/en/link3/']
const params = ['?param1', '?param2', '?param3']
urls.forEach((url) => {
params.forEach((param) => {
console.log(url + param)
})
checkCondition()
})
Upon execution: