English 中文(简体)
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.

Same problem occurs with <select> elements i want to interact with, but it seems that setting {scrollBehavior: center } does not work for select() method. I checked docs and in this mettod options param there is indeed no scrollBehavior setting. 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);
最佳回答

It turns out that there global scrollBehaviour setting that can be set in cypress.config.js file:

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

Setting it to nearest solved this problem.

问题回答

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.

For example, to match the monitor

cy.viewport(3000,2000)

Also .scrollIntoView() is dependent of the element having a parent with a scrollable region. It can also be blocked by flexbox CSS settings.





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签