Cypress Automation Best Practices: The Ultimate Guide

Sdílet
Vložit
  • čas přidán 6. 07. 2024
  • Welcome to Test Automation Experience! In this episode hosted by Nikolay Advolodkin, get ready to dive into the world of Cypress test automation.
    Nikolay will guide you through these best practices: Organizing tests, programmatic login, and controlling state; selecting elements and writing resilient tests; and tackling anti-patterns, including avoiding the reliance on previous test states.
    Whether you're new to Cypress or a seasoned pro, this episode is a must-watch for enhancing your automation skills. Subscribe now and elevate your test automation expertise with Test Automation Experience!
    Cypress Best Practices for Test Automation (Official Documentation): docs.cypress.io/guides/refere...
    CONNECT WITH NIKOLAY ADVOLODKIN
    🌎 WEBSITE: ultimateqa.com
    🐦 TWITTER: intent/user?scree...
    💡 LINKEDIN (consider leaving a Recommendation): / nikolayadvolodkin
    ▶ CZcams: www.youtube.com/@UltimateQA?s...
    📸 NIKOLAY’S INSTA: / nikolay.advolodkin
    📧EMAIL: nikolay@saucelabs.com
    JOIN THE CONVERSATION!
    🎥 Subscribe to our CZcams channel now and get access to the latest exclusive shows, before anyone else! www.youtube.com/@test-automat...
    ▶ Sauce CZcams channel: / saucelabs
    ‍🤝‍ Community page: saucelabs.com/community
    💡 LinkedIn: / sauce-labs
    🏠 Home Page: saucelabs.com/
    🐦 TWITTER: / saucelabs
    💡 LINKEDIN: / sauce-labs
    🌎 SAUCE WEBSITE: saucelabs.com
    =============================
    👇👇 RESOURCES to Help You with Automation👇👇
    📚 Books
    ✅ The Complete Software Tester: Concepts, Skills, and Strategies for High-Quality Testing - amzn.to/3H5eR71
    ✅ Clean Code by Robert Martin: amzn.to/3Eg3E2B
    ✅ Clean Architecture: A Craftsman's Guide to Software Structure and Design by Robert Martin - amzn.to/3KgVoU4
    ✅ Hands-on Mobile App testing - amzn.to/3WKB14k
    ✅ Explore it! by Elisabeth Hendrickson - amzn.to/3lycK4j
    ✅ Accelerate: Building and Scaling High Performing Technology Organizations - amzn.to/3HuPpsJ
    ✅ Hands-On Selenium WebDriver with Java: A Deep Dive into the Development of End-to-End Tests: amzn.to/421y5TB
    ✅ Mastering Software Testing with JUnit 5: Comprehensive guide to develop high quality Java applications: amzn.to/3oNEDXE
    🔎 Blogs
    ✅ Page Factory Deprecated: ultimateqa.com/selenium-3-11-...
    ✅ Page Factory by Titus Fortner: titusfortner.com/2021/02/03/p...
    ✅ Websites to practice test automation: snip.ly/rnapio
    ✅ Books to learn test automation: snip.ly/d9c4np
    📊 Code
    ✅ Contact list app - thinking-tester-contact-list....
    ✅ Dummy Automation Site: bonigarcia.dev/selenium-webdr...
    ✅ Selenium WebDriver Repo: github.com/bonigarcia/seleniu...
    0:00 - Intro
    0:28 - Organizing tests, logging in, controlling state
    2:21 - Real World App (RWA)
    3:04 - Best practices for selecting elements
    5:34 - Anti-patterns you should know for better test automation
    7:38 - Creating “tiny” tests with a single assertion
    9:58 - Having tests rely on the outcome of previous tests
    14:09 - How to make sure your app is testable
    15:08 - Why you need to work closely with developers
    15:33 - Don’t rely on automated UI testing
    16:42 - Final remarks
  • Věda a technologie

Komentáře • 14

  • @Long_Le29
    @Long_Le29 Před 9 měsíci +2

    Your two tips at the end conclude all.
    Thank you Nikolay

  • @zain.sadaqat
    @zain.sadaqat Před 6 měsíci

    You said, it's considered a bad practice if the second test is dependent on the first test. But I've a condition of testing a CRUD functionality.
    First Test Block: Creating an Item
    Second Test Block: Searching that previously created item
    Third Test Block: Editing the previously created item
    Fourth Test Block: Deleting the previously edited item
    In this way, I'm testing the CRUD functionality but how can I improve it using the Best Practices?

    • @test-automation-experience
      @test-automation-experience  Před 6 měsíci

      Take a read and let me know if this helps - ultimateqa.com/automation-patterns-antipatterns#Best_Practice_Tests_Should_Be_Atomic

  • @jopadjr
    @jopadjr Před měsícem

    80th...Hi, just a quick question. I have installed an IDE ( Visual Studio Code) and Node JS. And installed cypress using the commands. We have done some proxy setup to install the cypress.
    npm config set proxy
    npm config set https-proxy
    When I used an external link (e.g. google, yahoo) the cy.visit() is working. It is not working when I tried running an internal URL/link. It says "Cypress could not verify that this server is running" Can you please advise on what to do here please or create a new video please if possible?

    • @test-automation-experience
      @test-automation-experience  Před měsícem +1

      I could create a video! But maybe the fastest way to your solution is to try ChatGPT? Or Google.com AI feature? Those should give you an answer more quickly

    • @jopadjr
      @jopadjr Před měsícem +1

      @@test-automation-experience Thanks for the reply. Only if you have time. Yes, we did ask both AI tools. We are trying to install in Ubuntu instead of Windows. We'll see if that works.

  • @powertester5596
    @powertester5596 Před 9 měsíci

    5:52 : I think this totally depends and is not an anti pattern to use afterEach or afterAll.
    I would even say that both before and after method serves complimentary purpose and are both equally necessary to use.
    Take for example, with junit5, I want to have a singleton instance of a database with a connection pool that I only want to start once for the whole test run in the beginning and close only once at the end of whole test execution. Using a thread locked class with an afterAll method is the only clean way to get it done. You cannot close something that was not opened before in a beforeEach or beforeAll method.
    Also the example to reset database in the beginning of each test makes little sense since that for sure 💯 percent will affect other tests using the same database.
    So maybe you want to rethink your position on this one?

    • @test-automation-experience
      @test-automation-experience  Před 8 měsíci

      These are Cypress best practices ;) JavaScript operates differently from Java

    • @powertester5596
      @powertester5596 Před 8 měsíci

      @@test-automation-experience that is true but the use case I mentioned is independent of Java or JavaScript.
      So for example in my tests, I had to not only create a database pool connection but a Kafka producer for the whole run.
      The use case remains the same that I want to create only one producer for the whole run and close it after the whole run.
      Trying to create one for each test would be super inefficient and not advisable.
      Also to avoid the test environment getting cluttered with automation test runs data, I often like to clean up the resource created as a part of test - in a afterEach method.
      For all these you need after methods to clean/close properly.
      I understand that setting assumptions before a test is better than assuming that some other test would have done it for us in an after each method but that is a completely different (and valid) use case of before methods and that’s why we need both.
      To say that generally using afterEach and afterAll is an anti pattern is bad advice.

    • @test-automation-experience
      @test-automation-experience  Před 8 měsíci

      @@powertester5596 okay, so then why do you need to wait until the end to close the database? Why can't you extract all the data that you want into an object and then close the DB? Also, for what purpose are you opening a database?

    • @powertester5596
      @powertester5596 Před 8 měsíci

      @@test-automation-experience : ofcourse the RS connection is closed after storing the result into a object but you wouldn’t close the connection pool after each test - right?
      Same applies for all the other use cases I mentioned (clean up test run data, Kafka producer etc).
      If not, where would you handle the above use cases?
      On your question of use case, there are legacy apps that does not have an API or a front end and only contains a black box third party engine and a database where the result lands.
      P.S: I hope you seriously don’t stop believing that there are no activities that you should only do after the test and not always before just based on recommendation from someone 🙏.

  • @sarosilucian579
    @sarosilucian579 Před 6 měsíci

    What is ironic is that after you install Cypress on your machine, the automation test examples provided by them are using id, classes, even but textElement from buttons using contains() command.
    From my point of view this topic approached by Cypress is nonsense. You can use id or classes and store them in the custom commands file where if some changes occur you will have to change 100 test i.e from only one file.