课程: End-to-End JavaScript Testing with Cypress.io

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Element aliasing

Element aliasing

- [Instructor] All right, so at this point we've refactored our Cypress tests to use selectors that are much more robust than simply using an HTML tag or a CSS class. But especially when you look at things like this, you might find yourself longing for the somewhat more concise appearance of our old tag selectors. Right now our tests are pretty verbose and there are plenty of places where we're doing the exact same command over and over again, like with getting the characters left text doing something like this here, there's really no reason why we should have to type this over and over again. So the good news here is that Cypress provides us with a way of reducing the amount of code needed to perform these simple repetitive selections. And this concept is called aliasing in Cypress. So the way that aliasing works is like this. What we're going to do is we simply need to select something in our application. Usually this is going to be an element, but it doesn't necessarily have to be…

内容