How to Start With Cypress

Rate this content
Bookmark

The web has evolved. Finally, testing has also. Cypress is a modern testing tool that answers the testing needs of modern web applications. It has been gaining a lot of traction in the last couple of years, gaining worldwide popularity. If you have been waiting to learn Cypress, wait no more! Filip Hric will guide you through the first steps on how to start using Cypress and set up a project on your own. The good news is, learning Cypress is incredibly easy. You'll write your first test in no time, and then you'll discover how to write a full end-to-end test for a modern web application. You'll learn the core concepts like retry-ability. Discover how to work and interact with your application and learn how to combine API and UI tests. Throughout this whole workshop, we will write code and do practical exercises. You will leave with a hands-on experience that you can translate to your own project.

This workshop has been presented at TestJS Summit 2022, check out the latest edition of this JavaScript Conference.

FAQ

The Cypress intercept command is used to monitor API calls made by the application during testing. It allows you to watch for specific requests and provides the ability to test those requests without sending them yourself, unlike the cy.request command which is used to manually send requests.

To handle asynchronous loading elements in tests, you can use the Cypress 'wait' command to delay assertions until certain API requests are completed. Additionally, you can use UI elements like loaders to detect when loading is in progress and ensure they disappear before proceeding with further assertions.

The 'then' command in Cypress is used for assertions and executing functions based on the command chain's yield without retrying, ideal for singular, non-changing values like API responses. In contrast, the 'should' command automatically retries the preceding command until the assertion passes or fails, useful for testing dynamic DOM elements.

Plugins can extend the capabilities of Cypress by integrating additional functionalities not provided by default. For example, plugins can enable native system events like hover, handle file downloads, or provide UIs for API testing, thereby accommodating more complex testing scenarios and requirements.

To manage setup states in Cypress, you can use API calls to set the application in the required state instead of repeating UI actions. This approach is efficient for bypassing repetitive login procedures or data setups. The cy.request or cy.intercept commands can be utilized to prepare the application state before tests are executed.

Filip Hric
Filip Hric
146 min
21 Nov, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The workshop is led by Filip Nits, a QA lead in Slido, who teaches testers about web development and developers about testing. The workshop focuses on using Cypress for end-to-end testing of the Trello app, covering topics such as installation, writing tests, automating Trello board and element selection, using plugins, and testing cart creation and deletion. It also explores concepts like chaining commands, writing assertions with Chai, sending HTTP requests, intercepting requests, and combining UI and API tests. The workshop provides practical challenges and encourages participants to code along.
Available in Español: Cómo empezar con Cypress

1. Introduction to the Workshop

Short description:

My name is Filip and I have been a QA lead or a QA test Automation lead in Slido for almost 7 years now. Today I like to teach testers about web development and teach developers about testing. You can find everything that I do on my webpage, filibris.com, where I put Cypress tips almost every week. I do workshops, presentations, webinars, and all that. This is a link to my page. So Filip Nits, that's my name,.com slash workshop, where you can find like the full version of what we are going to be experiencing today. If you want to experience the full thing, I have an upcoming workshop actually starting next week. If you are considering doing that, hit me on Discord with a DM. I will give you a promo code.

So, let's dive in. Short introduction. My name is Filip. I have been a QA lead or a QA test Automation lead in Slido for almost 7 years now. So, it's actually, this slide needs an updating. And what I do there is mostly, I do test automation. I do have a background in Psychology, which I guess sort of goes with the teaching, maybe? I don't know. But yeah, that's kind of my background.

Today I like to teach testers about web development and teach developers about testing. You can find everything that I do on my webpage, filibris.com, where I put Cypress tips almost every week. I had quite a big gap because I was doing lots of new courses. And I will be continuing with that. But yeah, the whole page is basically dedicated to Cypress and giving different tips. So if you want to, if you're searching for something, you can search also there. And yeah, so I do workshops, presentations, webinars, and all that. I think I said it all about myself. This is a link to my page. So Filip Nits, that's my name,.com slash workshop, where you can find like the full version of what we are going to be experiencing today. So this is, as I said, not everyone was here. This is sort of a smaller demo version of the workshop, if you will. And if you want to experience the full thing, I have an upcoming workshop actually starting next week. So if you want to sign up for that and get the full experience, you can. And if you are considering doing that, hit me on Discord with a DM. I will have, I'll give you a promo code, because it doesn't really make sense if you do some parts twice. So to get some value of that, I'm going to send you a promo code if you're interested in having the full experience.

2. Workshop Format and Overview

Short description:

The workshop will consist of a chapter overview, a demo, and practical challenges. During the demo, it is recommended to watch rather than code along to avoid missing important points. The demo will be available in the demo start and demo end files, with additional information in the notes folder. The practical challenges will provide instructions in the challenge.cy.js file and solutions in the challenge solution file. It is not necessary to complete all the challenges, as the goal is to keep participants engaged even after the workshop.

So the workshop form will go like this. You can, by the way, scan this QR code, because we will be using that. But the workshop form goes like this. I'm going to do a chapter overview, basically tell you what you will be learning in that chapter. And then we will go through a demo. Or rather, I will be going through the demo, basically show you something, how everything works. And then we have a practical challenge. So I will be silent and you will be doing the coding work. So feel free to do that.

And for the Q&A, we can absolutely do that continually. In fact, we are a fairly small group. We just have like 15 participants. That includes me and Alex who is on the Zoom call as well, from TestJS crew. So I think we can safely go with just unmuting Mike and asking a question. Feel free to do that. To get some additional value from this. But we can also use Slido. That's where I'm from. It's a great tool for having an interaction. If you are shy or if you feel like you have a stupid question, you don't. But if you feel that way, you can use Slido to ask anonymously. And I'll probably say that's not a stupid question, that's a great question. And I'll answer that. But I also have a question for you. And that's why I wanted you to scan that QR code. So let me jump into that. And my question is how well do you know Cypress? I would like to know where you are at currently with your knowledge. And so one star means that you are just starting. You don't know much or you don't know anything. And six stars would be that you use it daily, you already know your way around, and basically you're here for improving your knowledge. Maybe find some extra tips. Alright, we are very well spread here. Oh we got 1 sixth, that's great. So we are spread on both sides, mostly in the middle. Oh, that's good. That's good. By the way, don't worry if you are too much on the right side or too much on the left side. Normally when I do this I do breakout rooms to break out this meeting into smaller ones. Not sure if we'll be able to do that today, but we'll see. We'll see how we handle that. Maybe we'll stay in the same room. All right. All right. So we got 3.6 the score. We got some beginners, some people that are in the middle, some are more advanced. That's awesome. Thank you. Thank you for answering that question. That really helps to sort of get me to get an idea.

Let me continue with explaining how this workshop is going to work. I already kind of said a little bit about this, but for the demo, I will be doing a short presentation. So during that, don't try to code along. In fact, it's better if you don't because I tend to go a little bit fast. And if you are switching between coding and watching, you might miss some points. So it's better for you to just watch. In order for you to not get lost, you can see everything that I did in the demo end file and I will be starting at the demo start. So that's demo start, demo end. In the project folder, you'll have the name of the chapter. Oops, that was not underlining, but crossing. So you have the name of the chapter we will be in and then I will be always starting from demo start and finished state will be at demo end. So you will get an insight into everything. Plus, everything I plan on seeing is inside the notes folder, but I tend to improvise so you will not find everything, but hopefully you'll find most of the information that you need.

After we do the demo, I'm going to go to the Practical challenges and again, I'm showing you here the folder structure. So in there what you will be doing during the practical challenges is take a look into the challenge.cy.js. Inside there you will find instructions on what you should do and inside the challenge solution you will find the solution for that particular example. Don't feel bad if you look into that. In fact I would encourage you to take a look into that, maximize your learning by getting as much information as you can, don't try to figure it out from memory or something. Use the documentation, use the solution file, do everything you can to gather knowledge. Important note on the practical challenges, you don't need to finish them all. In fact my goal is to keep you active even after the workshop so if you don't finish them all and you're feeling uncomfortable with them not being finished all, that's actually a good thing, I like that, because that will probably force you to open that repository again and play with Cypress a little more.

QnA