{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":490,"path":"api-reference/rest-apis/cloudrunner-testgeneration-api.md","title":"Cloud Runner Test Generation REST API","bundle":null,"doc_type":null,"release":"australia","body":"\n# Cloud Runner Test Generation REST API\n\nManages test job generation to be executed in a cloud runner for Automated Test Framework \\(ATF\\).\n\nThe Cloud Runner Test Generation API requires the [ATF Test Generator and Cloud Runner](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/atf-tg-cr-intro.md) \\(sn\\_atf\\_tg\\) plugin. The methods available with this API run in the **now** namespace and can be called using API Name, **One-click regression testing for ATF**, in the REST API Explorer. The admin role is required to access this API.\n\nYou can use this API for the following tasks:\n\n-   Start the test generation job.\n-   Check the progress of the test generation job.\n-   Cancel the test generation job.\n\nThe Cloud Runner Test Generation API may be used in tandem with the [Cloud Runner Test Runner REST API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/cloudrunner-testrunner-api.md) and [Cloud Runner Test User REST API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/cloudrunner-testuser-api.md). For instance, you can call the Test Generation API to run a test and then get the progress of the test in the browser orchestration queue \\(Cloud Runner TEST Generation API\\) and then check the number of tests that passed or failed.\n\nTo view the Server API reference documentation of this API, see [Cloud Runner TestGenerationApi – Scoped, Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/cloudrnr-TestGenerationAPI-scoped.md).\n\n**Parent Topic:**[REST API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/api-rest.md)\n\n## Cloud Runner Test Generation - GET /now/sn\\_atf\\_tg/test\\_generation\\_progress\n\nProvides the status of each generated test for a provided Browser Orchestration Queue \\(BOQ\\) record.\n\n### URL format\n\nDefault URL: GET `/api/now/sn_atf_tg/test_generation_progress`\n\n### Supported request parameters\n\n|Name|Description|\n|----|-----------|\n|None| |\n\n<table id=\"table_pdy_gwz_31c\" class=\"rest_api_query_parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsnboqId\n\n</td><td>\n\nRequired. The BOQ record sys\\_id of the test generation job to get the progress of.Data type: String\n\nTable: BOQ \\[sn\\_atf\\_tg\\_sn\\_boq\\]\n\n</td></tr></tbody>\n</table>|Name|Description|\n|----|-----------|\n|None| |\n\n### Headers\n\nThe following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see [Supported REST API headers](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_RESTAPI.md).\n\n<table id=\"table_sdy_gwz_31c\" class=\"rest_api_request_headers\"><thead><tr><th>\n\nHeader\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nAccept\n\n</td><td id=\"accept-entry-RESTAPI\">\n\nData format of the response body. Supported types: **application/json** or **application/xml**. Default: **application/json**\n\n</td></tr></tbody>\n</table>|Header|Description|\n|------|-----------|\n|None| |\n\n### Status codes\n\nThe following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see [REST API HTTP response codes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_RESTAPI.md).\n\n<table id=\"table_vdy_gwz_31c\"><thead><tr><th>\n\nStatus code\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\n200\n\n</td><td>\n\nSuccessfully retrieved the progress of the BOQ job.\n\n</td></tr><tr><td>\n\n400\n\n</td><td>\n\nError getting BOQ record status. Returns one of the following messages:-   No BOQ ID passed in – No BOQ ID was provided. Add the BOQ ID to the request body.\n-   Unable to find BOQ record – Invalid Sys ID. Verify that the sys\\_id of the BOQ record is valid and the record exists.\n\n</td></tr><tr><td>\n\n403\n\n</td><td>\n\nError granting user access to the endpoint. Ensure that the user has the admin role.\n\n</td></tr></tbody>\n</table>### Response body parameters \\(JSON or XML\\)\n\n<table id=\"table_xdy_gwz_31c\"><thead><tr><th>\n\nName\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nresult\n\n</td><td>\n\nObject containing the progress results of the generated test job or a message explaining why the request failed.Data type: Object\n\n```\n\"result\": { \n    \"testsSucceeded\": Number, \n    \"testsFailed\": Number, \n    \"testsPending\": Number, \n    \"testsInProgress\": Number, \n    \"testsSkipped\": Number \n  } \n}\n```\n\nOr:\n\n```\n{\n  \"result\": { \n    \"message\": \"String\" \n  } \n}\n```\n\n</td></tr><tr><td>\n\nresult.message\n\n</td><td>\n\nError message detailing why the test generation progress cannot be retrieved. The message parameter is not returned in a successful response.Data type: String\n\n</td></tr><tr><td>\n\nresult.testsSucceeded\n\n</td><td>\n\nNumber of generated tests that passed.Data type: Number\n\n</td></tr><tr><td>\n\nresult.testsFailed\n\n</td><td>\n\nNumber of generated tests that failed.Data type: Number\n\n</td></tr><tr><td>\n\nresult.testsPending\n\n</td><td>\n\nNumber of use cases that are waiting for generated tests.Data type: Number\n\n</td></tr><tr><td>\n\nresult.testsInProgress\n\n</td><td>\n\nNumber of use cases that tests are created for.Data type: Number\n\n</td></tr><tr><td>\n\nresult.testsSkipped\n\n</td><td>\n\nNumber of tests skipped due to the job cancellation.Data type: Number\n\n</td></tr></tbody>\n</table>### cURL request\n\nThe following GET call returns progress information about generated tests associated with the snboqId 1234.\n\n```\ncurl \"https://instance.service-now.com/api/now/sn_atf_tg/test_generation_progress?snboqId=1234\" \\ \n--request GET \\ \n--header \"Accept:application/json\" \\ \n--user \"username\":\"password\"\n```\n\nOutput:\n\n```\n{ \n  \"result\": { \n    \"testsSucceeded\": 0, \n    \"testsFailed\": 0, \n    \"testsPending\": 0, \n    \"testsInProgress\": 0, \n    \"testsSkipped\": 161 \n  } \n}\n```\n\nThe following example returns a 400 error message when no BOQ ID is passed.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/test_generation_progress\" \\\n--request GET \\\n--header \"Accept:application/json\" \\\n--user \"username\":\"password\"\n```\n\nResponse:\n\n```\n{\n  \"result\": {\n    \"message\": \"No SNBOQ ID passed in, add snboqId to request body\"\n  }\n}\n```\n\nThe following example returns a 400 error message when an invalid BOQ ID is passed.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/test_generation_progress?snboqId=invalid_sys_id\" \\\n--request GET \\\n--header \"Accept:application/json\" \\\n--user \"username\":\"password\"\n```\n\nResponse:\n\n```\n{\n  \"result\": {\n    \"message\": \"Invalid SNBOQ sys_id passed in\"\n  }\n}\n```\n\n## Cloud Runner Test Generation - POST /now/sn\\_atf\\_tg/cancel\\_test\\_generation\n\nSets the test generation job and its associated update set record to complete status. If any test jobs are in progress on cancellation, this method sets any of the in-progress test records generated to skipped.\n\nTests can fail or cancel automatically due to business rules or access control rule \\(ACL\\) issues. View the generated test table for more details about failed or canceled tests.\n\n### URL format\n\nDefault URL: POST `/api/now/sn_atf_tg/cancel_test_generation`\n\n### Supported request parameters\n\n|Name|Description|\n|----|-----------|\n|None| |\n\n|Name|Description|\n|----|-----------|\n|None| |\n\n<table id=\"table_o1y_cwz_31c\" class=\"rest_api_request_body\"><thead><tr><th>\n\nName\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsnboqId\n\n</td><td>\n\nRequired. Sys\\_id of the Browser Orchestration Queue \\(BOQ\\) record to cancel.Data type: String\n\nTable: BOQ \\[sn\\_atf\\_tg\\_sn\\_boq\\]\n\n</td></tr></tbody>\n</table>### Headers\n\nThe following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see [Supported REST API headers](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_RESTAPI.md).\n\n<table class=\"rest_api_request_headers\"><thead><tr><th>\n\nHeader\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nAccept\n\n</td><td id=\"accept-entry-RESTAPI\">\n\nData format of the response body. Supported types: **application/json** or **application/xml**. Default: **application/json**\n\n</td></tr><tr><td>\n\nContent-Type\n\n</td><td id=\"content_type-entry-RESTAPI\">\n\nData format of the request body. Supported types: **application/json** or **application/xml**. Default: **application/json**\n\n</td></tr></tbody>\n</table>|Header|Description|\n|------|-----------|\n|None| |\n\n### Status codes\n\nThe following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see [REST API HTTP response codes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_RESTAPI.md).\n\n<table><thead><tr><th>\n\nStatus code\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\n200\n\n</td><td>\n\nSuccessfully canceled the BOQ job.\n\n</td></tr><tr><td>\n\n400\n\n</td><td>\n\nError canceling job. Returns one of the following messages:-   No BOQ ID passed in – No BOQ ID was provided. Add the BOQ ID to the request body.\n-   Unable to find BOQ record – Invalid Sys ID. Verify that the sys\\_id of the BOQ record is valid and the record exists.\n\n</td></tr><tr><td>\n\n403\n\n</td><td>\n\nError granting user access to the endpoint. Ensure that the user has the admin role.\n\n</td></tr></tbody>\n</table>### Response body parameters \\(JSON or XML\\)\n\n<table><thead><tr><th>\n\nName\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nresult\n\n</td><td>\n\nObject containing the results of the cancellation request.Data type: Object\n\n```\n\"result\": { \n    \"message\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\nresult.message\n\n</td><td>\n\nMessage detailing whether the test cancellation was successful.Data type: String\n\n</td></tr></tbody>\n</table>### cURL request\n\nThe following request cancels the test generation job of a specified BOQ record.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/cancel_test_generation\" \\ \n--request POST \\ \n--header \"Accept:application/json\" \\ \n--header \"Content-Type:application/json\" \\ \n--data \"{\\\"snboqId\\\":\\\"<sys_id of BOQ record>\\\"}\" \\ \n--user \"username\":\"password\"\n```\n\nThe response body returns a success message of the cancellation.\n\n```\n{ \n  \"result\": { \n    \"message\": \"success\" \n  } \n}\n```\n\nThe following example returns a 400 error message when no BOQ ID is passed.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/cancel_test_generation\" \\\n--request POST \\\n--header \"Accept:application/json\" \\\n--user \"username\":\"password\"\n```\n\nResponse:\n\n```\n{\n  \"result\": {\n    \"message\": \"No SNBOQ ID passed in, add snboqId to request body\"\n  }\n}\n```\n\nThe following example returns a 400 error message when an invalid BOQ ID is passed.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/cancel_test_generation\" \\\n--request POST \\\n--header \"Accept:application/json\" \\\n--header \"Content-Type:application/json\" \\\n--data \"{\\\"snboqId\\\":\\\"invalid_sys_id\\\"}\" \\\n--user \"username\":\"password\"\n```\n\nResponse:\n\n```\n{\n  \"result\": {\n    \"message\": \"No SNBOQ ID passed in, add snboqId to request body\"\n  }\n}\n```\n\n## Cloud Runner Test Generation - POST /now/sn\\_atf\\_tg/test\\_generation\n\nInserts a record into the Browser Orchestration Queue \\(BOQ\\) \\[sn\\_atf\\_tg\\_sn\\_boq\\] table to start a test job.\n\n### URL format\n\nDefault URL: POST `/api/now/sn_atf_tg/test_generation`\n\n### Supported request parameters\n\n|Name|Description|\n|----|-----------|\n|None| |\n\n|Name|Description|\n|----|-----------|\n|None| |\n\n<table id=\"table_o1y_cwz_31c\" class=\"rest_api_request_body\"><thead><tr><th>\n\nName\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncatalogEncodedQuery\n\n</td><td>\n\nEncoded query specifying which catalog items to generate tests on. An empty string defaults to all catalog items. For more information about forming encoded queries, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).Data type: String\n\n</td></tr><tr><td>\n\nemail\n\n</td><td>\n\nEmail address to alert when test generation is complete.Data type: String\n\n</td></tr><tr><td>\n\nmaxTestCount\n\n</td><td>\n\nNumber of overall tests to generate.Accepted values: Any number between 1 and 9999.\n\nData type: Number\n\nDefault: 9999\n\n</td></tr><tr><td>\n\nmaxTestCountPerItem\n\n</td><td>\n\nNumber of tests to generate per catalog item. Accepted values: Any number between 1 and 10.\n\nData type: Number\n\nDefault: 10\n\n</td></tr><tr><td>\n\nmaxTestCountPerTable\n\n</td><td>\n\nNumber of tests to generate per table. Accepted values: Any number between 1 and 10.\n\nData type: Number\n\nDefault: 10\n\n</td></tr><tr><td>\n\nscopeForGeneratingTests\n\n</td><td>\n\nRequired when **separateUpdateSetPerScope** is set to false. Sys\\_id of the scope in which to place all generated tests. Data type: String\n\n</td></tr><tr><td>\n\nseparateUpdateSetPerScope\n\n</td><td>\n\nFlag that indicates whether to separate generated tests into respective suites, update sets, and scopes, or to place tests into one suite, update set, and scope.Valid values:\n\n-   true: Tests are placed into their respective suite and update set according to the scope of each table or catalog item.\n-   false: All generated tests are placed in the same suite, update set, and scope. If false, **scopeForGeneratingTests** is required in the request.\n\nData type: Boolean\n\nDefault: true\n\n</td></tr><tr><td>\n\ntestSuite\n\n</td><td>\n\nOptional. Sets the name of the test suite to create via test generation.Data type: String\n\nDefault: ATF Generated Suite - &lt;time\\_stamp&gt;\n\n</td></tr><tr><td>\n\ntableEncodedQuery\n\n</td><td>\n\nEncoded query specifying the tables on which to generate tests. An empty string defaults to all tables. For more information about forming encoded queries, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).Data type: String\n\n</td></tr><tr><td>\n\nuserEncodedQuery\n\n</td><td>\n\nEncoded query specifying which users to generate tests on. An empty string input defaults to all tables. For more information about forming encoded queries, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).Data type: String\n\n</td></tr></tbody>\n</table>### Headers\n\nThe following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see [Supported REST API headers](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_RESTAPI.md).\n\n<table id=\"table_krf_y2j_41c\" class=\"rest_api_request_headers\"><thead><tr><th>\n\nHeader\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nAccept\n\n</td><td id=\"accept-entry-RESTAPI\">\n\nData format of the response body. Supported types: **application/json** or **application/xml**. Default: **application/json**\n\n</td></tr><tr><td>\n\nContent-Type\n\n</td><td id=\"content_type-entry-RESTAPI\">\n\nData format of the request body. Supported types: **application/json** or **application/xml**. Default: **application/json**\n\n</td></tr></tbody>\n</table>|Header|Description|\n|------|-----------|\n|None| |\n\n### Status codes\n\nThe following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see [REST API HTTP response codes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_RESTAPI.md).\n\n|Status code|Description|\n|-----------|-----------|\n|200|Successfully inserted a test generation BOQ job. Any errors are shown in the BOQ record logs during processing. All inputs default to generate the maximum number of tests for all tables and service catalog items.|\n|403|Error granting user access to the endpoint. Ensure that the user has the admin role.|\n\n### Response body parameters \\(JSON or XML\\)\n\n<table id=\"table_v1y_cwz_31c\"><thead><tr><th>\n\nName\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nresult\n\n</td><td>\n\nObject containing the results of the request.```\n\n  \"result\": { \n    \"snboqId\": String\n  }\n```\n\nData type: Object\n\n</td></tr><tr><td>\n\nresult.snboqId\n\n</td><td>\n\nSys\\_id of the record inserted in the sn\\_atf\\_tg\\_sn\\_boq table when the test generation starts.Data type: String\n\n</td></tr></tbody>\n</table>### cURL request\n\nThe following request example starts a new test job in the instance without any request parameters and inserts the job in the BOQ table.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/test_generation\" \\ \n--request POST \\ \n--header \"Accept:application/json\" \\ \n--user \"username\":\"password\"\n```\n\nResponse body:\n\n```\n{ \n  \"result\": { \n    \"snboqId\": <sys_id of newly inserted BOQ record> \n  } \n}\n```\n\nThe following request example starts a new test job with a maximum test count of 2 and filters the tests to the Incident table, and then inserts the job in the BOQ table.\n\n```\ncurl \"http://instance.service-now.com/api/now/sn_atf_tg/test_generation\" \\ \n--request POST \\ \n--header \"Accept:application/json\" \\ \n--header \"Content-Type:application/json\" \\ \n--data \"{\\\"maxTestCount\\\":\\\"2\\\",\\\"tableEncodedQuery\\\":\\\"name=incident\\\",\\\"testSuite\\\":\\\"Suite123\\\"}\" \\ \n--user \"username\":\"password\"\n```\n\nResponse body:\n\n```\n{ \n  \"result\": { \n    \"snboqId\": <sys_id of newly inserted BOQ record> \n  } \n}\n```\n\n"}}