简体   繁体   English

赛普拉斯 - 使用带有 {scrollBehavior: 'center'} 的 select() 方法

[英]Cypress - using select() method with {scrollBehavior: 'center'}

Website i am testing uses fixed menu, so i need to use {scrollBehavior: 'center'} setting for click methods, to avoid getting error saying that element i want to interact with is covered by my menu.我正在测试的网站使用固定菜单,因此我需要为click方法使用{scrollBehavior: 'center'}设置,以避免出现错误提示我要与之交互的元素已被我的菜单覆盖。

Same problem occurs with <select> elements i want to interact with, but it seems that setting {scrollBehavior: 'center'} does not work for select() method.我想与之交互的<select>元素也会出现同样的问题,但似乎设置{scrollBehavior: 'center'}不适用于select()方法。 I checked docs and in this mettod options param there is indeed no scrollBehavior setting.我检查了文档,在这个 mettod 选项参数中确实没有scrollBehavior设置。 Is there any way to solve that problem?有没有办法解决这个问题?

I also tried using something like this, to scroll the page down, so element is no longer covered, but it had no effect.我也尝试使用类似这样的东西来向下滚动页面,因此元素不再被覆盖,但它没有效果。

cy.get('select')
    .scrollIntoView({offset: {top: 600, left: 0}})
    .select(someValue);

One way round the problem is to set the viewport very large at the start of the test, so that everything is in view already.解决这个问题的一种方法是在测试开始时将视口设置得非常大,以便一切都在视野中。 The default of 1000x600 is not very realistic IMO.默认的 1000x600 不是很现实的 IMO。

For example, to match the monitor例如,要匹配监视器

cy.viewport(3000,2000)

Also .scrollIntoView() is dependent of the element having a parent with a scrollable region.此外.scrollIntoView()取决于具有可滚动区域的父元素的元素。 It can also be blocked by flexbox CSS settings.它也可以被 flexbox CSS 设置阻止。

It turns out that there global scrollBehaviour setting that can be set in cypress.config.js file:事实证明,可以在cypress.config.js文件中设置全局scrollBehaviour设置:

module.exports = {
  e2e: {
    baseUrl: 'http://localhost/spoke9/spoke-and-chain-testing/web/',
    scrollBehavior: 'nearest'
  }
};

Setting it to nearest solved this problem.将其设置为nearest解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM