How to write Cypress Tests
On This Page Setting up Cypress for your projectApril 07, 2026 · 9 min read · Tool Comparison
Writing Cypress tests is a more effective and flying option for debugging E2E testing and execute them parallel to any pull request as portion of Uninterrupted Integration. What is Cypress? Cypress is a JavaScript-based front-end examination framework catering to web application. It lets developer and testers pen exam like unit trial, integration trial and end-to-end tests for different development stages. Why Write and Run Tests on Cypress? This article walks you through the fundamentals of indite Cypress tests, including setting up your exam environment, publish test codification, and running and debugging your tests in the. Before write your 1st test, you must first. Enter the following bid in CMD: Once Cypress has been set up, you can launch it by using: After installing Cypress, you can use the IDE to make a project and commence creating Cypress trial. The directory cypress/integration/ contains all of the tests. Also Read: The BDD syntax from Mocha, which is idealistic for both desegregation and unit testing, has been borrow by Cypress. Every test you & # 8217; ll be indite rests on the basic harness that Mocha volunteer, namely: Cypress dictationprovide you with the option to create custom functionality and still replace preexist commands. Making a custom dictation is typically a voguish thought when you start to truly understand that you are repeatedly writing the same functionality across several tests, or reiterate yourself. This command could guide the form of a click, website navigation, or still finding an ingredient. As a result, you will include commands as one of the key components in our test. Also Read: Consequently, the 1st command you will execute will be to open the website bstackdemo.com. ‘ Visit ’ is the dictation & # 8217; s name. You must have heard the frequently apply bidding. It & # 8217; s known as ‘get’: This command returns an element based on the selector it use. In order to locate the components to interact with, you would execute this command. Also Read: Typically, you would utilize it to initiate a series of instructions. The statements in the tests, or commands, can be organized in a chain (or chain, in early words). This entail that, as you cognize from many examination framework, commands can pass on a subject (or return value) of one command to the subsequent command. You will utilize bid to mimic the actions a user would take. Execute the machine-driven Cypress end-to-end trial after that, then record and study the termination. Cypress tests may be executed using the Cypress Runner or Cypress CLI. To get, you will create a new file in the integration folder. author.spec.js is what you will call it. The suffix .spec stands for “ specification ”. These are the technical necessary that your application must meet to pass a test for a particular feature or application. For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. You will begin by giving the test suite construction such that this clean JavaScript file may house a test. You are going to use the ‘ describe ’ Hook. The tests are contained and arranged using circumstance () or describe (). In other words, our examination are frame by this strategy. Thus, our test file will appear as follow: What is describe, it, and expect? These all originate from bundle libraries that Cypress has broil in. Also Read: Making the real test is the next stage. The method it (), or specify (), symbolize the genuine test. As you can see, yo can capture various tests in a individual file, giving us a variety of fantastic structuring options. If you use Cypress to execute our test, you will see that Cypress launches a browser to carry out the test. Refer to our to execute your 1st Cypress test utilise BrowserStack. The username and admittance key for BrowserStack is site in your. A reliable test typically includes three level: Now the concept would be that you firstly set the covering in a certain state, then you do something in the coating that change it, and then you verify the new state of the application. An in-depth look: Or Let us get: Writing the examination playscript for the is the next step after determining the test flow, as shown in the picture and codification below. You will now go over the commands use in the aforesaid icon. Also Read: When Cypress is first started in your codebase, it already has a top-level cypress booklet with a suggested structure. Included in this are additional directory like integration for your spec files, fixtures for JSON datum files, plugins for your cy.task (& # 8230;) office and early configurations, and a support pamphlet for your custom commands and types. When you run Cypress tests on BrowserStack, if your spec file has errors, the test session keeps running and eventually blocks a parallel that could have be used by another spec. You can get elaborate instructions on how to organise your test runs and trial for better test coverage. Learn how to Here are a few best practices to follow while writing Cypress tests to structure and maintain your exam seamlessly: Here are some common erroneousness to avoid while writing Cypress tests: Writing tests on Cypress get with several benefits, which is why it is rather democratic among the test community: BrowserStack is a cloud-based testing platform that lets you run Cypress tests expeditiously across multiple device-OS-browser combinations. Here are a few reasons why you should choose BrowserStack: Cypress is a powerful weapon for end-to-end examination. Thanks to its user-friendly interface and full-bodied features, you can write, run, and debug tests seamlessly to validate the functioning of your apps. To further enhance your testing, you can run Your Cypress Tests on BrowserStack. To speed up the testing procedure, you may use with simultaneously on various browser-device combination using BrowserStack. Understanding Cypress Use Cases Tool Comparisons On This Page # Ask-and-Contributeabout this issue with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How to write Cypress Tests
Overview
Setting up Cypress for your undertaking
npm install cypress -- save-dev
npx cypress open
Understanding Cypress Syntax and Commands
Cypress Commands
cy.get ('selector ');it ('BstackDemo ', () = & gt; {cy.visit ('https: //bstackdemo.com/ ') cy.get (`` # signin '') .click (); cy.get (`` # username '') .click (); cy.xpath (`` //div [text () ='demouser '] '') .click (); cy.get (`` # password '') .click (); cy.xpath (`` //div [text () ='testingfun23 '] '') .click (); cy.get (`` # login-btn '') .click (); cy.get (`` # logout '') .should ('have.text ', 'Logout ') cy.get (`` # logout '') .click (); cy.get (`` # signin '') .should ('have.text ', 'Sign In ')})Writing your first Cypress test
// find-author.spec.js describe ('Find writer at browserstack ', () = & gt; {// ...});// author.spec.js describe ('Find source at browserstack ', () = & gt; {it ('Find the author Hamid Akhtar ', () = & gt; {cy.log ('This is our maiden test ');});});Create a real test
Organizing your Cypress tests
Tips for structure your exam and create them maintainable
Common mistake while launching Cypress
Benefits of Writing Tests on Cypress
Why Choose BrowserStack for Cypress Testing
Conclusion
Useful Resources for Cypress
Related Guides
Automate This With SUSA
Test Your App Autonomously