0%

Get to grips with the Cypress framework and learn how to best implement end-to-end automation testing with JavaScript with the help of expert tips, best practices, and real-world testing examples

Key Features

  • Write your first end-to-end test and find out how to modernize your testing environment
  • Execute test-driven web development and cross-browser testing using Cypress
  • Discover the advantages of using Cypress over Selenium and refactor testing for modern web apps

Book Description

Cypress is a modern test automation framework for web-based frontend apps. Learning Cypress will help you overcome the shortcomings of conventional testing solutions such as dependency graph problems, the steep learning curve in setting up end-to-end testing packages, and difficulties in writing explicit time waits for your tests.

In End-to-End Web Testing with Cypress, you'll learn how to use different Cypress tools, including time travel, snapshots, errors, and console output, to write fail-safe and non-flaky tests. You'll discover techniques for performing test-driven development (TDD) with Cypress and write cross-browser tests for your web applications. As you advance, you'll implement tests for a sample application and work with a variety of tools and features within the Cypress ecosystem. Finally, this Cypress book will help you grasp advanced testing concepts such as visual testing and networking.

By the end of this book, you'll have the skills you need to be able to set up Cypress for any web app and understand how to use it to its full potential.

What you will learn

  • Get to grips with Cypress and understand its advantages over Selenium
  • Explore common Cypress commands, tools, and techniques for writing complete tests for web apps
  • Set up and configure Cypress for cross-browser testing
  • Understand how to work with elements and animation to write non-flaky tests
  • Discover techniques for implementing and handling navigation requests in tests
  • Implement visual regression tests with Applitools eyes

Who this book is for

This book is for automation testing professionals, software and web testers, and frontend web developers who have intermediate-level JavaScript and beginner-level test automation knowledge, as well as for complete beginners who are looking to get started with Cypress and learn how it works. You'll also find this book useful if you are a Selenium tester who wants to migrate to Cypress and leverage its capabilities. An intermediate-level understanding of JavaScript programming and beginner-level knowledge of web testing are required.

Table of Contents

  1. End-to-End Web Testing with Cypress
  2. Why subscribe?
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Reviews
  8. Section 1: Cypress as an End-to-End Testing Solution for Frontend Applications
  9. Chapter 1: Installing and Setting Up Cypress
    1. Technical requirements
    2. Installing Cypress on Windows
    3. Downloading and installing Node.js
    4. Initializing the project
    5. Installing Cypress on Windows
    6. Recap – Installing Cypress on Windows
    7. Installing Cypress on MacOS
    8. Installing Node.js
    9. Initializing the project
    10. Installing Cypress on Mac
    11. Installing Cypress using Yarn
    12. Installing Cypress via direct download
    13. Recap – Installing Cypress on macOS
    14. Opening Cypress
    15. Running with Npx
    16. Running with Yarn
    17. Running with the node modules path
    18. Desktop application launch
    19. Recap – Opening Cypress
    20. Switching browsers
    21. Exercise
    22. Recap – Switching browsers
    23. Adding npm scripts
    24. Opening a Cypress command script
    25. Recap – Adding npm scripts
    26. Running Cypress tests
    27. Combining Cypress commands using scripts
    28. Recap – Running Cypress tests
    29. Summary
  10. Chapter 2: Differences between Selenium WebDriver and Cypress
    1. Why choose Cypress?
    2. Recap – why choose Cypress?
    3. Comparing Cypress and Selenium WebDriver
    4. Browser driver
    5. Retries and waits
    6. Target usage
    7. Architecture
    8. Cross-browser compatibility
    9. Cypress trade-offs
    10. Summarizing the differences
    11. Recap – comparing Cypress and Selenium WebDriver
    12. Cypress for frontend applications
    13. Test Runner
    14. Setup process
    15. Implementation and debugging
    16. Exhaustive testing capabilities
    17. Recap – Cypress for frontend applications
    18. Summary
  11. Chapter 3: Working with Cypress Command-Line Tools
    1. Technical requirements
    2. Running Cypress commands
    3. Global and local commands
    4. Recap – running Cypress commands
    5. Understanding basic Cypress commands
    6. cypress run
    7. cypress open
    8. Using the cypress info command
    9. Using the cypress version command
    10. Optional exercise for Cypress command usage
    11. Recap – understanding basic Cypress commands
    12. Cypress debugging on the command line
    13. Optional exercise for Cypress debugging
    14. Recap – Cypress debugging on the command line
    15. Summary
  12. Chapter 4: Writing Your First Test
    1. Technical requirements
    2. Creating test files
    3. Testfiles location
    4. Testfiles extensions
    5. Testfile structure
    6. Creating our test file
    7. Recap – creating test files
    8. Writing your first test
    9. Example test
    10. Test classification
    11. Exercise on tests classification
    12. Recap – writing your first test
    13. Writing practical tests
    14. Visiting the Todo application page
    15. Searching for an element
    16. Interacting with the Todo input element
    17. Asserting the application state
    18. Exercise on practical testing
    19. Recap – writing practical tests
    20. Cypress' auto-reload feature
    21. Recap – Cypress' auto-reload feature
    22. Cypress assertions
    23. Implicit subjects
    24. Explicit subjects
    25. Exercise–implicit and explicit subjects
    26. Recap – Cypress assertions
    27. Summary
  13. Chapter 5: Debugging Cypress Tests
    1. Technical requirements
    2. Understanding page events
    3. Recap – understanding page events
    4. Understanding errors on a test runner
    5. Error name
    6. Error message
    7. Code frame file
    8. Code frame
    9. Stack trace
    10. Print to console
    11. Learn more
    12. Recap – understanding errors on a test runner
    13. Understanding time travel on executed tests
    14. Recap – understanding time travel on executed tests
    15. Understanding test snapshots
    16. Recap – understanding test snapshots
    17. Understanding the console debug output
    18. macOS
    19. Windows/Linux OS
    20. Recap – understanding the console debug output
    21. Special debugging commands
    22. cy.debug
    23. cy.pause
    24. Recap – special debugging commands
    25. Summary
  14. Section 2: Automated Tests with the TDD Approach
  15. Chapter 6: Writing Cypress Tests Using the TDD approach
    1. Technical requirements
    2. Understanding TDD
    3. Advantages of TDD
    4. Disadvantages of TDD
    5. Recap – understanding TDD
    6. Writing TDD tests in Cypress
    7. Setting up the application
    8. Adding new todo items
    9. Deleting a Todo item
    10. Viewing a count of the added todo items
    11. Recap – setting up the application
    12. Modifying TDD tests
    13. Adding new todo items
    14. Deleting a todo item
    15. Viewing added todo items
    16. Viewing the count of added todo items
    17. Recap – modifying TDD tests
    18. Summary
  16. Chapter 7: Understanding Element Interaction in Cypress
    1. Technical requirements
    2. Understanding actionability
    3. Visibility
    4. Disability
    5. Detached
    6. Readonly
    7. Animations
    8. Covering
    9. Scrolling
    10. Coordinates
    11. Recap – understanding actionability
    12. Forcing actionability
    13. Overriding Cypress actionability checks
    14. Recap – forcing actionability
    15. Summary
  17. Chapter 8: Understanding Variables and Aliases in Cypress
    1. Technical requirements
    2. Understanding Cypress variables
    3. Closures
    4. Recap – Understanding Cypress variables
    5. Understanding Cypress aliases
    6. Sharing contexts between test hooks and tests
    7. Accessing element references
    8. Accessing route references
    9. Accessing request references
    10. Recap – Understanding Cypress aliases
    11. Summary
  18. Chapter 9: Advanced Uses of Cypress Test Runner
    1. Technical requirements
    2. Understanding the instrument panel
    3. Intercepts
    4. Stubs
    5. Spies
    6. Recap – understanding the instrument panel
    7. Understanding the Selector Playground
    8. Selecting unique elements
    9. Editing selector elements
    10. Recap – understanding the Selector Playground
    11. Test Runner keyboard shortcuts
    12. Recap – Test Runner keyboard shortcuts
    13. Summary
  19. Section 3: Automated Testing for Your Web Application
  20. Chapter 10: Exercise – Navigation and Network Requests
    1. Technical requirements
    2. Implementing navigation requests
    3. cy.visit()
    4. Exercise 1
    5. cy.go()
    6. Exercise 2
    7. cy.reload()
    8. Exercise 3
    9. Recap – implementing navigation requests
    10. Implementing network requests
    11. cy.request()
    12. Exercise 4
    13. cy.intercept()
    14. Exercise 5
    15. Recap – implementing network requests
    16. Advanced navigation request configuration
    17. cy.visit() configuration options
    18. Recap – advanced navigation request configuration
    19. Summary
  21. Chapter 11: Exercise – Stubbing and Spying XHR Requests
    1. Technical requirements
    2. Understanding XHR requests
    3. Utilizing XHR requests in tests
    4. Recap – utilizing XHR requests in tests
    5. Understanding how to stub requests
    6. Stubbing XHR requests
    7. Exercise 1
    8. Recap – understanding how to stub requests
    9. Understanding how to spy on methods in a test
    10. Why spy?
    11. Exercise 2
    12. Recap – understanding how to spy on methods in a test
    13. Summary
  22. Chapter 12: Visual Testing in Cypress
    1. Technical requirements
    2. Visual testing
    3. Why visual testing?
    4. Recap – visual testing
    5. Understanding viewports
    6. Viewports and testing
    7. Viewports and automated visual testing
    8. Recap – viewports
    9. Automated visual testing tools
    10. Percy
    11. Applitools
    12. Recap – automated visual testing tools
    13. Summary
  23. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
3.239.9.151