API Automation Using Cypress Test Cases

Modified on Tue, 23 Apr 2024 at 08:24 PM

Cypress is an advanced end-to-end testing framework built with JavaScript, allowing developers to create and execute tests directly within the browser environment.


Prerequisites


For detailed prerequisites, refer to Configuring Node.Js Version and Cypress article.


Automation procedure for performing user actions API collection using algoQA

Consider an example of performing user actions using HTTP methods. The HTTP methods indicate the type of operation you want to perform on a specified user.

User actions and HTTP Methods:  


APIHTTP Methods to call API 
LoginPOST
Create a profilePOST
Access the profile GET


  1. Create a project: 
    • Name: User Actions API
    • Select API Automation
    • Click Create

  2. Upload an API collection:

    In the Main Canvas, click the arrow in the lower-right corner to view the side panel to upload the API collection.
    Note: Ensure the API collection is in JSON format. If you wish to create API collection using algoQA  Forms, click here.
  3. Execute the API automation
    • Let us validate the HTTP method details to log in a user using the POST method, save it and click Send to execute it.
      You can confirm the execution status in the status bar as shown:

    • In the previous example:
      • Endpoint: /api/login is the endpoint or URL where the login functionality is implemented.
      • HTTP Method: POST is used to submit user credentials.

      • Request Body: The username and password are included in the JSON file that is part of the request body.

    • Similarly, you can validate POST and GET methods for user actions, such as creating and accessing a profile and  executing it, confirming the execution status.
  4. Generate scripts 
    1. In the left panel, select the appropriate folder to view the sequence. Select the user actions and click Generate Scripts.


    2. If needed, you can rearrange the sequence with drag-and-drop functionality and click the Update Sequence button.
      In the left pane, click down arrow corresponding to User Management API >Project Directory pane > navigate to the Test Cases folder to access the Feature File.

      A sample Feature File is as follows:
  5. Download the script 
    • Right-click on the Script Generated folder and select Download option to download the script and save it to your local folder.


Executing the script using Cypress UI

  1. Navigate to the folder where you downloaded the scripts to open the command prompt from the same folder.
    Make sure Cypress is configured on your system. Refer to the prerequisite

  2. Run the following command to launch the Cypress UI.
    npx cypress open
    
  3. Cypress UI screen appears with Cypress configured. as shown. In this screen, select E2E testing option.



  4. Choose a browser screen appears. In this screen, select Chrome and Click Start E2E Testing in Electron button.


  5. Feature File will be displayed as follows. Click the Feature File to start the execution.
  6. Execution screen will be displayed as follows:


Execution of the scripts in the headless mode

With headless mode, tests run quickly without displaying the browser window. This means you can get test results faster, speeding up your testing process. You can also view the report generated. Make sure Cypress is configured on your system.

Perform the following: 

  1. Navigate to the same folder where you saved your algoQA generated scripts. Type 'cmd' on the navigation bar to open the command prompt.

  2. Run the following command to execute the scripts:
    npx cypress run --headless
    
    
  3. Following is a sample report:














Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article