Now, I'm testing the to-do MVC project, and so I can switch between various implementations. In this case, I'm looking at the AngularJS version. I go grab the site names, so I can put it in my described block in a really elegant way, and then before each test, I'm going to go visit that site.
Now, I do this just to validate it so that I don't have to do this CY.visit at the beginning of each test, but I definitely could if I wanted to. Now, let's do a hello world test, where we just go grab the URL, and it should equal that site URL. Now, this was really helpful. When I originally wrote this talk, this site was HTTP, not HTTPS, and so it was really helpful for me to notice that I wasn't testing what I expected. If you refactor your website, it could be nice to know if this content is 301 or 302 to a new page that you're not testing what you expect.
Now, next, let's take a look at the to-do list. We haven't entered any to-do's, so this to-do list should not exist. Perfect. Now, depending on this SPAT implementation, it might exist but be blank, but ultimately, we're looking for the li items within the list, so this might be a safe assumption. Next, let's level up and start interacting with the page. I've got some content and I want to type that in the to-do box. So, let's go select the new to-do box and type that content and push enter. Notice that there's a dollar sign here and not here. This curly brace enter curly brace is so we can enter unique commands. Shift, option, control, F keys, anything we can type in this way. So, once I've done that, I'll go grab the to-do list and validate that it contains my new to-do. Notice that there's no awaits here. As soon as we finish typing that content, it will wait for all of the browser events to finish before Cypress gets onto the next line. So, let's go validate that our to-do box is now blank, and now we've added a to-do. That's perfect! Let's mark a to-do as completed. So, I'll start by creating this irrelevant to-do, because I want to make sure that I'm completing the correct one. Then I'll mark my new to-do that I want to do, and validate that I can get there. So, let's go grab that view that matches this new to-do, and go grab the children the toggle button. Now I'll click that toggle button, and that will mark that task as finished. So, what does it mean to be finished? Well, it should have this class of completed, and I'll go validate that by selecting that to-do item. Perfect. Now we've been able to start to interact with the page in a really elegant way.
Comments