Full-Circle Testing With Cypress

Rate this content
Bookmark

Cypress has taken the world by storm by brining an easy to use tool for end to end testing. It’s capabilities have proven to be be useful for creating stable tests for frontend applications. But end to end testing is just a small part of testing efforts. What about your API? What about your components? Well, in my talk I would like to show you how we can start with end-to-end tests, go deeper with component testing and then move up to testing our API, circ

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

FAQ

The speaker is Filip, a tester with some developer skills and a Cypress Ambassador.

The main topic of the talk is full circle testing with Cypress.

Cypress is known for end-to-end testing and API testing.

An end-to-end test in Cypress involves visiting an application, selecting an element, typing into it, hitting enter, and performing actions like clicking and typing.

When a test error occurs, Cypress automatically retries searching for the selector for 4,000 milliseconds and provides a detailed assertion error.

Some advantages include instant feedback, the ability to interact with the browser's console, and examining the application state and network requests.

Cypress facilitates API testing using the request command to send API requests and verify responses.

Component testing in Cypress involves rendering components inside a real browser and testing different states and interactions.

The intercept command in Cypress is used to observe and manipulate API requests, allowing testers to test edge cases and server responses.

You can learn more by attending Filip's workshops at test.js summit or checking his website for upcoming workshops.

Filip Hric
Filip Hric
27 min
03 Nov, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Cypress is a powerful tool for end-to-end testing and API testing. It provides instant feedback on test errors and allows tests to be run inside the browser. Cypress enables testing at both the application and network layers, making it easier to reach different edge cases. With features like AppActions and component testing, Cypress allows for comprehensive testing of individual components and the entire application. Join the workshops to learn more about full circle testing with Cypress.

1. Introduction to Full Circle Testing with Cypress

Short description:

Hey everyone, I'm a tester with maybe some developer skills or developer with testing skills. I'm also a Cypress Ambassador, and today I'll be talking about full circle testing with Cypress. Let's take a look at what that means. Cypress shines in end-to-end testing, and if you've never used it, I recommend checking out the workshop. There's also a workshop coming up at test.js summit. Let's dive into Cypress and how to write a test with it.

Hey everyone, I'm glad to be here. My name is Filip and I'm a tester with maybe some developer skills or developer with testing skills. I don't know. It depends how you look at it. I'm also a Cypress Ambassador, which means I like to talk about Cypress and I love to teach people how to use this amazing tool. So that's what I'll be doing today.

The topic of today's talk is full circle testing with Cypress. So what that means. Well, it's a completely made up term. I made it up to make this talk a little interesting and hope that you will take a look at it. But I do have an idea that's behind it that I would like to share with you. So let me draw a circle or a ring. But don't worry, you're not going to die when you look at it, hopefully. But hopefully you'll learn something new. And yeah, let's let's take a look.

So as you know, there's something that's called testing pyramid, which I'm not going to draw here because everyone knows what it is. It also contains something that might be at the top of the pyramid, and which is something that I'm going to start today's talk with. And that's end-to-end testing. So when talking about Cypress, this is where Cypress shines the most and this is what Cypress is mostly known for. So if you have never used Cypress, I recommend you to check out the workshop. I have a link at the bottom of this slide. But also there is going to be a workshop on test.js summit in just a couple of days. So make sure you check it out if you still can, hopefully you can. And we can meet there and you can learn to work with Cypress with me. So if you can make it to that one, make sure to check out my website, and you will find one at the end of November.

So let's take a look into Cypress and how you can actually write a test with Cypress. So on the right side I have my Cypress running in graphic user interface mode, so that would be the one you run with npx-cypress-open in your terminal. And on the left, I have a test which I'm going to show you later. I want to show you this one right now, the end-to-end test. So, inside this test, I'm doing a simple flow.

2. Full Circle Testing and API Testing in Cypress

Short description:

I'm visiting an application and performing various actions like selecting elements, typing, and interacting with the page. The flow automates going to the homepage, creating a new board, list, and card. Cypress provides instant feedback on test errors and allows us to run tests inside the browser, taking advantage of browser features like the console. We can also examine the application as it appeared during test execution, making it easier to find hard-to-locate elements. Cypress encourages API testing using the 'request' command.

I'm visiting an application, and then I'm selecting an element, typing into it, hitting enter, and then doing some actions again. Getting an element, clicking, typing, interacting with my page. Basically, what I want to do is to go to my homepage, create a new board, then create a new list, and inside it, create a new card. And this is what the flow automates.

So, whenever I make an error, for example, I change my selector to not be found, and when I save my test, it will automatically rerun. If I make an error during my test, I get this really nice assertion error explaining to me what actually happened. So in this case, what actually happened is that it couldn't find the selector because I made a typo on it and it was nowhere to be found. Cypress is actually going to retry searching for that selector for 4,000 milliseconds, so for four seconds.

Now, this means that Cypress works really great for the applications that are all the time re-rendering and doing some sort of fetching from API, etc. as modern applications do. So when you are testing, you get this instant feedback into what your test has done. But also, the important thing here is that we are running inside the browser. So while we are doing that, we get all of the advantages that the browser will provide us. So for example, we can open up a console and take a look into what's happening inside the console. So I'm getting a couple of warnings here, but these are not that important. Cypress actually takes a great advantage of the console and of the fact that we are running inside the browser. So when I click on any of my commands, for example this visit command, Cypress will print out information into the console with the details of that command. It will also print out information for every HTTP request that is being done with the application. So let's maybe fix the test, save it to make it pass. And also, what Cypress enables us, as you can see, is to travel back in time and examine the application as it was looking while the test was being executed. This is pretty neat, this gives you an insight, especially if you're looking for a selector that is kind of hard to find because the element appears and then it disappears. This is a really, really helpful tool. So you can see different API calls, and Cypress sort of invites you to get into the application and examine the application and get to know its nuts and bolts. So a great area to start examining your application a little bit more is to do API testing, and this is actually a second part of our circle of tests.

So when we are doing API testing in Cypress, we can use a command called request, so let me show you that one. And let's change it because I'm going to show you the API command in just a second. So let me save my test and let me open that in my Cypress runner. Oops, sorry, that was not the correct test. We want to run the API testing. So now we have it.