From the course: End-to-End JavaScript Testing with Cypress.io
Unlock this course with a free trial
Join today to access over 24,100 courses taught by industry experts.
Using beforeEach
From the course: End-to-End JavaScript Testing with Cypress.io
Using beforeEach
- [Instructor] All right, so now that we've taken a look at a few details around writing simple tests with Cypress, the next thing that I want to show you is a key way that we can reduce duplication across our Cypress tests. So first of all, let's just create a new file here. We'll call this something like before each. You'll see why I'm calling it this in just a minute. Then what we're going to do is we're just going to go into our selecting.cy.js file. I'm just going to copy the code that's inside there and paste it and we'll just adjust the indentation, real quick here. All right, there we go. So let's say that we made this test a little bit easier to read and maintain by splitting this single it block up into multiple blocks. You'll see what I mean by this in just a second. Let's maybe copy and paste this a few times so that we now have three tests here. And maybe what we want to do is for each of these it blocks, instead of typing incrementally, which can be a little bit…
Contents
-
-
-
-
Installing and running Cypress2m 14s
-
Writing and running Cypress tests8m
-
(Locked)
Testing text inputs7m 53s
-
(Locked)
Selecting elements8m 20s
-
(Locked)
Element aliasing6m 39s
-
(Locked)
Working with command results5m 43s
-
(Locked)
Using beforeEach4m 57s
-
(Locked)
Setting a base URL3m 29s
-
(Locked)
Challenge 1: Writing your own tests1m 46s
-
(Locked)
Solution 1: Writing your own tests6m 38s
-
-
-
-