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

免费学习该课程!

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

Selecting elements

Selecting elements

- [Instructor] So now that we have some tests written and passing, it's time to talk about a very important topic in Cypress. And to be specific, we need to take a good hard look at what the best way is to select different elements in our tests, right? So far, for simplicity, we've just been using the HTML tag of whatever element we want to select, and I want to make it very clear that in the vast majority of cases, this is just the wrong way to do it, right? You see the problem here is that using the HTML tag like this is extremely dependent on the current state of our app. So to show you what I mean, let's navigate to example three. And what you'll see here is that we have two text inputs instead of one. Now, if we go back to our application and test this thing, what I'm actually going to do is duplicate this file. I'm just going to copy it and paste it here, and we'll change this to something like selecting.cy.js. Well, let's see what happens if all we change is going to the…

内容