Tutorials Hut

  • Cypress tutorials




  • Basic Test case in Cypress and Execution

    In this tutorial we will understand how to start with writing test cases in cypress and some basic execution.Below topics will be covered in this section:

    Basic test case in cypress

    Mocha test framework in cypress

      • Cypress using Mocha as a testing framework.
      • Mocha is a feature-rich JavaScript test framework running on Node.js 
      • Framework runs in the browser, making asynchronous testing simple and fun
      • Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
      • In Mocha we group tests using the describe function and define tests using the it function.

    describe and it block of Mocha in cypress

    In Mocha we group tests using the describe function and define tests using the it function.

      • These two functions can be used to make your test suite complete, maintainable, and expressive
      • You can organize tests into nested groups that reflect the structure of your implementation code.

    SAMPLE CODE:

    
    describe('Navigate to URL of tutorials Hut', () => {
    
    it('my first test', () => {
    // visit is used to navigate to the URL
    cy.visit("https://tutorialshut.com/")
    cy.log("test 1 completed")
    })
    
    it('my second test', () => {
    cy.log("test 2 completed")
    })
    
    })
    
    

    Basic test case cypress

    Steps:

      1. In the IDE( we are using Visual studio code) , go to the integration folder and click on New File.
    cypress_integration folder

    2. Write the file name and .js . Javascript files are saved with .js extension.

    cypress_testcase

    3. Now we can start writing the code in this file.

    Note: command to navigate to any url is :

    cy.visit(“URL”)

    4. Copy the code written in the above topic and save.

    cypress_navigateToUrl

    5. Open the cypress using the cypress open command. For more details refer here.

    6. Execute the test case from test runner by clicking on the test case name or you can directly run it from the command line. To learn more on it refer here.

    7. Test case execution starts in the selected browser.

    execution on test runner_cypress

    Observe the logs that appear on the left side. You can time travel by navigating on it.


















  • Leave a Reply

    Your email address will not be published. Required fields are marked *