admin管理员组文章数量:1396448
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
- /en/link1/?param1
- /en/link2/?param1
- /en/link3/?param1
- checkCondition()
- /en/link1/?param2
- /en/link2/?param2
- /en/link3/?param2
- checkCondition()
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!
SOLUTION (kudos to @Alapan Das)
describe("My test", () => {
urls.forEach(url => {
params.forEach(param => {
it(`should check smthng`, () => {
cy.visit(url + param)
cy.checkCondition()
})
})
})
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
- /en/link1/?param1
- /en/link2/?param1
- /en/link3/?param1
- checkCondition()
- /en/link1/?param2
- /en/link2/?param2
- /en/link3/?param2
- checkCondition()
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!
SOLUTION (kudos to @Alapan Das)
describe("My test", () => {
urls.forEach(url => {
params.forEach(param => {
it(`should check smthng`, () => {
cy.visit(url + param)
cy.checkCondition()
})
})
})
Share
Improve this question
edited May 25, 2022 at 12:28
Prokrastinosaurus
asked May 25, 2022 at 10:56
ProkrastinosaurusProkrastinosaurus
891 silver badge6 bronze badges
1
- Instead of editing your question with the solution, you should mark Alapan's answer as the solution. – agoff Commented May 25, 2022 at 14:06
2 Answers
Reset to default 3You can use cy.request
version taking options as argument: https://docs.cypress.io/api/mands/request#Options
cy.request({
url: "/en/link1",
qs: {
"param2": "test"
}
})
You can use nested ForEach Loops to iterate over both arrays and make the binations 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:
本文标签: javascriptHow to add query param in Cypress (JS)Stack Overflow
版权声明:本文标题:javascript - How to add query param in Cypress (JS) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744794222a2625479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论