---
title: "Test an advanced condition"
slug: "test-an-advanced-condition"
abstract: "Explains how to test an advanced condition that uses a header or parameter in the experiment or experience request."
---
# Test an advanced condition

Sitecore Personalize enables you to [test a condition](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/test-a-condition.html "Test a condition") by running it against a selected guest. This topic describes how to test an advanced condition that includes a header or parameter in the experiment or experience request.

When you test a condition, Sitecore Personalize tests the JavaScript on the server-side. This ensures that the JavaScript is validated within the context it will be executed in.

Team members with a *User*, *Developer*, or *Admin* role in Sitecore Cloud Portal can test an advanced condition.

To test an advanced condition:

1. Open the condition and click **Test**.

    ![Testing a condition](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_testcond.png)

2. In the **Test Condition** dialog, you must test the condition against a guest. You can test against the default guest's attributes, or click in the search box and choose **Recent** to select from a list of recently active guests or **Bookmarks** to select from a list of bookmarked guests. The system selects a guest who was recently active. You can search for a guest using, for example, an email address, other unique identifier or browser ID.

    > [!note]
    > If there is a guest whose data you often use when configuring or testing code, just click the **star** icon to bookmark the guest so you no longer have to search for them.

3. Click the **Experience request** option to include headers and parameters for an experiment or experience in the test. To do this, call the `request` context in the JavaScript code editor:

    ```csharp
    (function () {
            return { request: request };
    })();
    ```

4. To add a header to the experience request, you must include the header in the JavaScript in the code editor. For example, the out-of-the-box **Device** condition includes the `User-Agent` header in the JavaScript, as shown here:

    ```csharp
    (function () {
        load("classpath:ua-parser.js");
        var comparator = "[[is | enum(is, is not) | is | { required: true, placeholder: is/is not }]]";
        var deviceTypes = "[[device type(s) | multienum(mobile, tablet, desktop, other) |  | { required: true, placeholder: device type(s) }]]";
        var deviceTypesArray = deviceTypes.toLowerCase().split(',');
        var desktopOSTypes = ['Mac OS', 'Windows', 'Ubuntu', 'Unix', 'Linux', 'Chromium OS'];
        var deviceMatch = false;

        if (request && request.requestDetails && request.requestDetails.headers && request.requestDetails.headers['User-Agent']) {
            var parser = new UAParser();
            parser.setUA(request.requestDetails.headers['User-Agent']);
            var uaParsed = parser.getResult();
            if (uaParsed.device.type) {
                var deviceType = uaParsed.device.type.toLowerCase();
                if (deviceType !== 'mobile' && deviceType !== 'tablet') {
                    deviceMatch = deviceTypesArray.indexOf('other') >= 0;
                } else {
                    for (var k = 0; k < deviceTypesArray.length; k++) {
                        if (deviceType === deviceTypesArray[k].toLowerCase()) {
                            deviceMatch = true;
                            break;
                        }
                    }
                }
            } else {
                var device = 'other';
                if (uaParsed.os.name) {
                    for (var i = 0; i < desktopOSTypes.length; i++) {
                        if (uaParsed.os.name.toLowerCase() === desktopOSTypes[i].toLowerCase()) {
                            device = 'desktop';
                            break;
                        }
                    }
                }
                deviceMatch = deviceTypesArray.indexOf(device) >= 0;
            }
        }

        return (comparator === "is") && deviceMatch || (comparator === "is not") && !deviceMatch;
    })();
    ```

5. From the **Test Scenario** option, click **Add Header**.
6. You can include objects as keys using this format: `objects.keys`. For example, `User_Agent` is the key and `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.58` is the value as shown here:

    ![pers_header.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_header.png)

7. Click **Test**. The parameters and values you added to the test scenario are included in the response.
8. To add a parameter to the experience request, you must include the full path to the parameter in the JavaScript code editor, as shown here:

    ```csharp
    (function () {
            return { request: request.params.utm.campaign === "summer_sale"};
    })();
    ```

9. From the **Test Scenario** option, click **Add Parameters**.
10. You can include objects as keys using this format: `objects.keys`. For example, `utm_campaign` is the key and `summer_sale` is the value as shown here:

    ![Add parameters to test conditions](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_addparam.png)

11. Click **Test**. The parameters and values you added to the test scenario are included in the response, as shown here:

    ![Parameters in the test response](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_paramresponse.png)