如何使用IT测试和之前的ViveWports迭代数组

发布于 2025-02-07 05:32:59 字数 409 浏览 0 评论 0原文

我遇到了视口问题,但我还没有找到解决方案。

describe('Tests', function () {
beforeEach(function () {
});

viewports.forEach((viewport) => {
    it.only(`Test: ${viewport}`, function () {
        cy.viewportAdjust(viewport);
    })})})

我在测试中使用了cy.viewportadjust(fiewport);它有效,但是我希望将cy.viewportadjust(viewport);移动到之前部分,但对于测试,它使用了fiewportsarray的最后值

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒冷纷飞旳雪 2025-02-14 05:32:59

我不完全确定cy.viewportadjust()是什么,因为这看起来是自定义功能。如果该函数只需调用cy.viewport()或更新视口,则以下功能将起作用。此外,由于不知道viewport中的值是什么,我不能给出一个完整的答案,但是总体想法是您可以在> IT中传递evientportwidth或ViewPortheight( )块。

viewports.forEach((viewport) => {
    it.only(`Test: ${viewport}`, { viewportWidth: viewport }, function () {
        cy.viewportAdjust(viewport);
    })
})

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);
    })
})
隐诗 2025-02-14 05:32:59

我将准确地回答这个问题。但是我不建议这样做,尽管没有看到您要做的一切,但我对此声明没有100%的信心。

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)
    })
  })
})

相反,我建议您删除前面的块并将您的代码放在IT块中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文