# Need help with writing a test in postman

**URL:** <https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [November 15, 2022, 9:48am UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116 "2022-11-15T09:48:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliakharlan](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@juliakharlan](https://community.postman.com/u/juliakharlan)\
**Post date:** [November 15, 2022, 9:48am UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/1 "2022-11-15T09:48:03Z")

</div>

Hello everyone!  
Need your help with solving the following task.  
I need to create a TEST which performs a check that the number of characters “\” (backslashes) in the body of the response does not exceed (less or equal to) 700.  
If there are no such characters in the response body, we should look for “/” (slashes)

I’ve already tried:

```auto
var stringsearch = "\\", str = pm.response.text();
for(var i=count=0; i<str.length; count+=+(stringsearch===str[i++]));
console.log(count);

if (count <= 700) {
    var stringsearch = "/", str = pm.response.text();
    for(var i=count=0; i<str.length; count+=+(stringsearch===str[i++]));
    console.log(count);
}

```

But! I need I can see the result of the test in Test Results but not in the console. Could you help to do this?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 15, 2022, 12:31pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/2 "2022-11-15T12:31:54Z")

</div>

Hey @juliakharlan 👋

Do you have an example of the response body? It makes it easier for folks to try and create a solution from it.

---

<div class="post-metadata">

**Author:** ![juliakharlan](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@juliakharlan](https://community.postman.com/u/juliakharlan)\
**Post date:** [November 15, 2022, 12:53pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/3 "2022-11-15T12:53:52Z")

</div>

Hey @danny-dainton 🙂  
Yes, that is it

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/9/9ec1bc00c99215f83aab49adab5d580204f04fd2.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 15, 2022, 1:26pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/4 "2022-11-15T13:26:42Z")

</div>

Could you copy and paste a snippet of the raw response, so no one has to type that all out from the picture 😅

What’s the significance of the slashes? Are you just looking to see if there are a specific number of URLs?

---

<div class="post-metadata">

**Author:** ![juliakharlan](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@juliakharlan](https://community.postman.com/u/juliakharlan)\
**Post date:** [November 15, 2022, 1:55pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/5 "2022-11-15T13:55:37Z")

</div>

So, here is it 🥲  
There is no significance, just need to count all the backslashes or slashes in the response, without any specific purpose 😃

```auto
{
    "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
    "id": "2309956",
    "self": "https://jira.a1qa.com/rest/api/2/issue/2309956",
    "key": "RFXIRFXBDQ-469",
    "fields": {
        "customfield_18474": null,
        "customfield_10071": null,
        "customfield_10470": "9223372036854775807",
        "customfield_10350": null,
        "fixVersions": [],
        "customfield_13500": null,
        "resolution": null,
        "customfield_10234": null,
        "lastViewed": null,
        "customfield_19670": null,
        "customfield_19671": null,
        "customfield_11670": null,
        "customfield_10221": null,
        "priority": {
            "self": "https://jira.a1qa.com/rest/api/2/priority/3",
            "iconUrl": "https://jira.a1qa.com/images/icons/priorities/major.svg",
            "name": "Major",
            "id": "3"
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 15, 2022, 2:32pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/6 "2022-11-15T14:32:25Z")

</div>

Could be something like:

```javascript
let count = pm.response.text().split("\\").length - 1
console.log(count);

if (count <= 700) {
    let count = pm.response.text().split("/").length - 1
    console.log(count);
}

```

I’d need more context to provide a better answer.

---

<div class="post-metadata">

**Author:** ![juliakharlan](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@juliakharlan](https://community.postman.com/u/juliakharlan)\
**Post date:** [November 15, 2022, 2:54pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/7 "2022-11-15T14:54:10Z")

</div>

Thank you for your help! 🥹  
But could it be written as for tests? I mean is it possible to view the result in “Test results” but not in the Console?  
I need to get a text as a result something like “There are less than 700 backslashes”.  
I suppose it shold be started as:

pm.test (“There are less than 700 backslashes”, function () {  
let count = pm.response.text().split(" \\ ").length - 1  
…

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 15, 2022, 6:06pm UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/8 "2022-11-15T18:06:00Z")

</div>

```auto
const backSlashCount = pm.response.text().split("\\").length - 1

if (backSlashCount <= 700) {
    pm.test('Less than 700 backslashes', () => {
        forwardSlashCount = pm.response.text().split("/").length - 1
        pm.expect(forwardSlashCount).to.be.below(backSlashCount);
    })
} else {
    pm.test('More than 700 backslashes', () => {
        pm.expect(backSlashCount).to.be.above(700);
    })
}

```

---

<div class="post-metadata">

**Author:** ![juliakharlan](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@juliakharlan](https://community.postman.com/u/juliakharlan)\
**Post date:** [November 17, 2022, 6:42am UTC](https://community.postman.com/t/need-help-with-writing-a-test-in-postman/41116/9 "2022-11-17T06:42:26Z")

</div>

Thank you, Danny, so much for your help!!
