-2

I want to send slack notification for my test result.

here is my Array

TestCase Name : [Test 1,Test 2,Test 3r]

TestCase Status : [true,false,false]

How do i create this string using javascript.

Here is my JsonString i Want using javascript



{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "WebDriverIO Automation Status .\n\n *Following are details:*"
            }
        },
        {
            "type": "divider"
        },
        {
            "type": "context",
            "elements": [
                {
                    "type": "mrkdwn",
                    "text": "Test 1"
                },
                {
                    "type": "mrkdwn",
                    "text": " :negative_squared_cross_mark: "
                }
            ]
        },
        {
            "type": "context",
            "elements": [
                {
                    "type": "mrkdwn",
                    "text": "Test 2"
                },
                {
                    "type": "mrkdwn",
                    "text": " :x: "
                }
            ]
        },
        {
            "type": "context",
            "elements": [
                {
                    "type": "mrkdwn",
                    "text": "Test 3r"
                },
                {
                    "type": "mrkdwn",
                    "text": " :x: "
                }
            ]
        }
    ]
}

Slack Webhook:

axios.post(
            "hook url",
            {
                text: `${asJSON}`,
            }
        );
  • Does this answer your question? [Serializing an object to JSON](https://stackoverflow.com/questions/558518/serializing-an-object-to-json) – Besworks Jun 03 '22 at 20:18
  • I have tried this but its sending slack message as json format only with {} brackate. ```var obj = {}; for (var i = 0; i < testITArray.length; i++) { obj[testITArray[i]] = testITStatusArray[i]; } var asJSON = JSON.stringify(obj); axios.post( "Hook url", { text: `${asJSON}`, } );``` – user19089852 Jun 04 '22 at 04:03

0 Answers0