Last active
February 8, 2021 19:44
-
-
Save samaybar/64db10724e6cfb01ff15aa67cd2001a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "1.0", | |
"name": "Runscope to Mock Service", | |
"description": "", | |
"steps": [ | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Get Test Result from Runscope", | |
"headers": {}, | |
"url": "https://api.runscope.com/buckets/{{runscopeBucketKey}}/tests/{{runscopeTestId}}/results/{{runscopeTestRunId}}", | |
"args": {}, | |
"auth": {}, | |
"multipart_form": [], | |
"fragment": "", | |
"method": "GET", | |
"data": "", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [ | |
{ | |
"source": "response_json", | |
"name": "test_run_url", | |
"property": "data.test_run_url" | |
} | |
], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Bearer REDACTED\";\n\n//get UUID of specified step\nvar data = JSON.parse(response.body);\nvar step = parseInt(variables.get(\"runscopeStepToMock\"));\n//note that the step you specify will include skipped steps in the result\nvar step_uuid = data.data.requests[step].uuid;\nlog(step_uuid);\nvariables.set(\"step_uuid\",step_uuid);" | |
], | |
"before_scripts": [ | |
"//replace blazemeter api token with runscope token\nvar runscopeToken = variables.get(\"runscopeToken\");\nrequest.headers.Authorization = \"Bearer \" + runscopeToken;" | |
] | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Get Body from Runscope", | |
"url": "{{test_run_url}}/steps/{{step_uuid}}", | |
"auth": {}, | |
"fragment": "", | |
"headers": {}, | |
"multipart_form": [], | |
"method": "GET", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [ | |
{ | |
"source": "response_json", | |
"name": "mockBody", | |
"property": "" | |
} | |
], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Bearer REDACTED\";\n\n//get body of response to mock\nvar data = JSON.parse(response.body);\nvar bodyToMock = data.data.response.body;\n//convert body to base64 and save to variable\nvariables.set(\"bodyToMock\",btoa(bodyToMock));\n\n//get headers from response to mock\nvar stepHeaders = response.headers;\nvar headersToMock = [];\nfor (var property in stepHeaders) {\n //including content-length header can lead to problems so exclude it; could exclude others by similar method\n if(property != \"Content-Length\"){\n var thisHeader = {\"name\":property,\"value\":stepHeaders[property][0]};\n headersToMock.push(thisHeader);\n }\n}\n\n//convert headers to base64 and save to variable\nvariables.set(\"headersToMock\",JSON.stringify(headersToMock));" | |
], | |
"before_scripts": [ | |
"//replace blazemeter api token with runscope token\nvar runscopeToken = variables.get(\"runscopeToken\");\nrequest.headers.Authorization = \"Bearer \" + runscopeToken;" | |
] | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Create Service", | |
"body": "{ \r\n \"description\": \"runscope-to-mock-demo\", \r\n \"name\": \"runscope-to-mock-demo\",\r\n \"workspaceId\": \"{{workspaceId}}\"\r\n}", | |
"form": {}, | |
"url": "https://mock.blazemeter.com/api/v1/workspaces/{{workspaceId}}/services", | |
"multipart_form": [], | |
"headers": { | |
"Content-Type": [ | |
"application/json" | |
] | |
}, | |
"fragment": "", | |
"method": "POST", | |
"assertions": [ | |
{ | |
"comparison": "is_greater_than_or_equal", | |
"source": "response_status", | |
"value": "200" | |
}, | |
{ | |
"comparison": "is_less_than_or_equal", | |
"source": "response_status", | |
"value": "201" | |
} | |
], | |
"variables": [ | |
{ | |
"source": "response_json", | |
"name": "serviceId", | |
"property": "result.id" | |
} | |
], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Basic REDACTED\";" | |
], | |
"before_scripts": [] | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Add mock transaction", | |
"body": "{\r\n \"transactions\": [\r\n {\r\n \"name\": \"Transaction from Runscpope API {{count}}\",\r\n \"description\": \"Transaction created from Runscope API {{count}}\",\r\n \"tags\": [\r\n \"runscope\"\r\n ],\r\n \"dsl\": {\r\n \"priority\": 0,\r\n \"requestDsl\": {\r\n \"method\": \"GET\",\r\n \"url\": {\r\n \"key\": \"url\",\r\n \"matcherName\": \"equals_url\",\r\n \"matchingValue\": \"http://www.example.com\"\r\n },\r\n \"headers\": [\r\n ],\r\n \"queryParams\": [\r\n ],\r\n \"cookies\": [\r\n ],\r\n \"body\": [\r\n ]\r\n },\r\n \"responseDsl\": {\r\n \"status\": 200,\r\n \"statusMessage\": \"HTTP/1.1 200 OK\",\r\n \"headers\": {{headersToMock}},\r\n \"binary\": false,\r\n \"content\": \"{{bodyToMock}}\",\r\n \"charset\": \"UTF-8\"\r\n }\r\n }\r\n }\r\n ]\r\n}", | |
"form": {}, | |
"url": "https://mock.blazemeter.com/api/v1/workspaces/{{workspaceId}}/transactions?serviceId={{serviceId}}", | |
"multipart_form": [], | |
"auth": {}, | |
"headers": { | |
"Content-Type": [ | |
"application/json" | |
], | |
"accept": [ | |
"*/*" | |
] | |
}, | |
"fragment": "", | |
"method": "POST", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [ | |
{ | |
"source": "response_json", | |
"name": "transactionId", | |
"property": "result[0].id" | |
}, | |
{ | |
"source": "response_json", | |
"name": "transactionPriority", | |
"property": "result[0].dsl.priority" | |
} | |
], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Basic REDACTED\";" | |
], | |
"before_scripts": [] | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Create Mock Service", | |
"body": "{ \"description\": \"{{mockName}}\", \"endpointPreference\": \"HTTPS\", \"harborId\": \"{{harborId}}\", \"id\": 0, \"type\": \"TRANSACTIONAL\", \"liveSystemHost\": \"string\", \"liveSystemPort\": 0, \"name\": \"{{mockName}}\", \"noMatchingRequestPreference\": \"string\", \"noMatchingRequestTxnId\": 0, \"serviceId\":{{serviceId}}, \"shipId\": \"{{shipId}}\", \"thinkTime\": 100, \"mockServiceTransactions\": [ {\"txnId\":{{transactionId}}, \"priority\":9} ]}", | |
"form": {}, | |
"url": "https://mock.blazemeter.com/api/v1/workspaces/{{workspaceId}}/service-mocks", | |
"auth": {}, | |
"fragment": "", | |
"headers": { | |
"Content-Type": [ | |
"application/json" | |
], | |
"accept": [ | |
"application/json;charset=UTF-8" | |
] | |
}, | |
"multipart_form": [], | |
"method": "POST", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [ | |
{ | |
"source": "response_json", | |
"name": "mockServiceId", | |
"property": "result.id" | |
} | |
], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Basic REDACTED\";" | |
], | |
"before_scripts": [] | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Run Mock Service", | |
"url": "https://mock.blazemeter.com/api/v1/workspaces/{{workspaceId}}/service-mocks/{{mockServiceId}}/deploy", | |
"auth": {}, | |
"fragment": "", | |
"headers": { | |
"accept": [ | |
"application/json;charset=UTF-8" | |
] | |
}, | |
"multipart_form": [], | |
"method": "GET", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Basic REDACTED\";" | |
], | |
"before_scripts": [] | |
}, | |
{ | |
"step_type": "pause", | |
"skipped": false, | |
"duration": 60 | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Get Mock Service", | |
"url": "https://mock.blazemeter.com/api/v1/workspaces/{{workspaceId}}/service-mocks/{{mockServiceId}}", | |
"auth": {}, | |
"fragment": "", | |
"headers": { | |
"accept": [ | |
"application/json;charset=UTF-8" | |
] | |
}, | |
"multipart_form": [], | |
"method": "GET", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [ | |
{ | |
"source": "response_json", | |
"name": "mockEndpoint", | |
"property": "result.httpsEndpoint" | |
}, | |
{ | |
"source": "response_json", | |
"name": "mockStatus", | |
"property": "result.status" | |
} | |
], | |
"scripts": [ | |
"//remove Runscope authorization header from output of test\nrequest.headers.Authorization = \"Basic REDACTED\";" | |
], | |
"before_scripts": [] | |
}, | |
{ | |
"step_type": "request", | |
"skipped": false, | |
"note": "Get Mock and compare", | |
"url": "{{mockEndpoint}}", | |
"multipart_form": [], | |
"auth": {}, | |
"headers": {}, | |
"fragment": "", | |
"method": "GET", | |
"assertions": [ | |
{ | |
"comparison": "equal_number", | |
"source": "response_status", | |
"value": 200 | |
} | |
], | |
"variables": [], | |
"scripts": [ | |
"\nvar orignMockBody = variables.get(\"bodyToMock\");\nvar newBody = response.body;\n\nvar b64Orig = orignMockBody;\n//log(b64Orig);\nvar b64New = btoa(newBody);\n//log(b64New);\n\nassert(b64Orig == b64New,\"body matches original\");\n" | |
], | |
"before_scripts": [ | |
"//remove Runscope authorization header from output of test\nvar newHeaders = request.headers;\ndelete newHeaders.Authorization;\nrequest.headers = newHeaders;\n" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment