Handling Cookies

    Handling Cookies


    Article summary

    A critical aspect of API testing in Quality Modeller is the handling of cookies, which are indispensable in managing and maintaining session information. Recognizing this, Quality Modeller offers robust support for retrieving and using cookies in your testing models. Firstly, our tool provides the ability to return a singular cookie. This capability is instrumental in scenarios where a specific cookie, such as a session or an identity cookie, needs to be extracted from an API response. Once retrieved, this cookie can then be used for a range of purposes, from making assertions about its properties to utilizing its value in subsequent API calls.

    Expanding on this, Quality Modeller also supports the extraction and utilization of multiple cookie values. This function is particularly useful in situations where an API response may include several cookies, each serving different purposes. For instance, one cookie could be for session management, while another could pertain to user preferences. Quality Modeller allows you to extract each cookie and its corresponding value, facilitating their use in various test conditions. You can verify the properties of these cookies in assertions, or use the extracted cookie values to drive the behavior of chained API calls. This multiplicity not only adds a level of dynamism to your tests but also helps to mimic more closely the complexity of real-world user interactions.

    1. Returning a Cookie Value

    In this part of the tutorial, we cover returning a single cookie value.

    2. Returning Multiple Cookie Values

    In this part of the tutorial, we cover returning multiple cookie values.

    3. Passing Cookies between Requests

    Quality Modeller features a Cookie Store, designed to persist cookies, and by extension, manage the state between chained API calls. By default, the cookie store feature is enabled, but users have the freedom to enable, disable, or clear the cookie store according to their testing requirements.

    The cookie store in Quality Modeller is a virtual storage where cookies from API responses are stored. These stored cookies are used for subsequent API requests, hence providing continuity and state management across multiple API calls.

    3.1 Enabling / Disabling the Cookie Store

    The cookie store feature is enabled by default. However, users can choose to disable or re-enable it based on their needs. Disabling the cookie store will prevent the system from saving any cookies from the API responses.

    In the APIGeneralActions action pack, there are two functions 'Enable Cookie Store', and 'Disable Cookie Store'. These respectively enable and disable the cookie store.

    Please note that enabling or disabling the cookie store only affects how future API requests are handled; it doesn't affect the cookies currently stored.

    3.2 Clearing the Cookie Store

    In some scenarios, you might want to start fresh without any stored cookies. Quality Modeller provides an easy way to clear the cookie store.

    To clear the Cookie Store, use the 'Clear Cookie Store' action in the APIGeneralActions pack.

    This will erase all the cookies currently saved in the Cookie Store.