Developer manual > API - Add a sample scenario and explanations for using it with API
TODO: add a sample scenario and explanations for using it with API
see: Asqatasun#611 (comment 749390690)
API works differently than webapp for scenarios:
- you don't have to provide a path to a scenario file,
- you have to provide escaped json of the scenario.
{
"name": "My scenario name",
"scenario": "paste here your escaped json scenario",
"referential": "RGAA_4_0",
"level": "AAA",
"contractId": 1,
"tags": []
}
Example for following scenario: wikipedia.org.side
I used this following tool to escape the Json. It is not perfect, because we should not replace new line and carriage return (\n\r
) that can be used in Selenium selectors. In case of this scenario, however, it works very well.
https://www.freeformatter.com/json-escape.html
{
"name": "My scenario name",
"scenario": "{\r\n \"id\": \"86c8c21b-0f67-4a85-856e-9e5f8d4960a9\",\r\n \"version\": \"2.0\",\r\n \"name\": \"wikipedia.org\",\r\n \"url\": \"https:\/\/en.wikipedia.org\",\r\n \"tests\": [{\r\n \"id\": \"3859ced4-3a39-41d7-992e-04c6b8445a3f\",\r\n \"name\": \"en.wikipedia.org\",\r\n \"commands\": [{\r\n \"id\": \"af4cd92b-07c8-46bc-aade-445b521f2c00\",\r\n \"comment\": \"\",\r\n \"command\": \"open\",\r\n \"target\": \"\/wiki\/Main_Page\",\r\n \"targets\": [],\r\n \"value\": \"\"\r\n }, {\r\n \"id\": \"b5beaf64-abf5-4098-8c49-8ea55a51bee0\",\r\n \"comment\": \"\",\r\n \"command\": \"setWindowSize\",\r\n \"target\": \"1311x800\",\r\n \"targets\": [],\r\n \"value\": \"\"\r\n }, {\r\n \"id\": \"592b3730-d3bc-4e88-b9e5-590657a8ee33\",\r\n \"comment\": \"\",\r\n \"command\": \"click\",\r\n \"target\": \"linkText=Wikipedia\",\r\n \"targets\": [\r\n [\"linkText=Wikipedia\", \"linkText\"],\r\n [\"css=#mp-welcome > a\", \"css:finder\"],\r\n [\"xpath=\/\/a[contains(text(),'Wikipedia')]\", \"xpath:link\"],\r\n [\"xpath=\/\/div[@id='mp-welcome']\/a\", \"xpath:idRelative\"],\r\n [\"xpath=\/\/a[contains(@href, '\/wiki\/Wikipedia')]\", \"xpath:href\"],\r\n [\"xpath=\/\/div[5]\/div\/div\/div\/div\/a\", \"xpath:position\"]\r\n ],\r\n \"value\": \"\"\r\n }, {\r\n \"id\": \"e68d481a-f41c-44a4-93de-d9c1b92266e4\",\r\n \"comment\": \"\",\r\n \"command\": \"click\",\r\n \"target\": \"css=#ca-history span\",\r\n \"targets\": [\r\n [\"css=#ca-history span\", \"css:finder\"],\r\n [\"xpath=\/\/li[@id='ca-history']\/a\/span\", \"xpath:idRelative\"],\r\n [\"xpath=\/\/div[2]\/nav\/div\/ul\/li[3]\/a\/span\", \"xpath:position\"],\r\n [\"xpath=\/\/span[contains(.,'View history')]\", \"xpath:innerText\"]\r\n ],\r\n \"value\": \"\"\r\n }, {\r\n \"id\": \"75db0b8b-106d-469f-93d4-e3122e7d08ae\",\r\n \"comment\": \"\",\r\n \"command\": \"click\",\r\n \"target\": \"css=#n-contactpage span\",\r\n \"targets\": [\r\n [\"css=#n-contactpage span\", \"css:finder\"],\r\n [\"xpath=\/\/li[@id='n-contactpage']\/a\/span\", \"xpath:idRelative\"],\r\n [\"xpath=\/\/li[6]\/a\/span\", \"xpath:position\"],\r\n [\"xpath=\/\/span[contains(.,'Contact us')]\", \"xpath:innerText\"]\r\n ],\r\n \"value\": \"\"\r\n }, {\r\n \"id\": \"607aacf5-f188-46f9-934b-32edbd334f58\",\r\n \"comment\": \"\",\r\n \"command\": \"click\",\r\n \"target\": \"css=#n-randompage span\",\r\n \"targets\": [\r\n [\"css=#n-randompage span\", \"css:finder\"],\r\n [\"xpath=\/\/li[@id='n-randompage']\/a\/span\", \"xpath:idRelative\"],\r\n [\"xpath=\/\/div[2]\/nav\/div\/ul\/li[4]\/a\/span\", \"xpath:position\"],\r\n [\"xpath=\/\/span[contains(.,'Random article')]\", \"xpath:innerText\"]\r\n ],\r\n \"value\": \"\"\r\n }]\r\n }],\r\n \"suites\": [{\r\n \"id\": \"661276a1-5489-422d-b2cf-955cc2968ebf\",\r\n \"name\": \"Default Suite\",\r\n \"persistSession\": false,\r\n \"parallel\": false,\r\n \"timeout\": 300,\r\n \"tests\": [\"3859ced4-3a39-41d7-992e-04c6b8445a3f\"]\r\n }],\r\n \"urls\": [\"https:\/\/en.wikipedia.org\/\"],\r\n \"plugins\": []\r\n}",
"referential": "RGAA_4_0",
"level": "AAA",
"contractId": 1,
"tags": []
}
Edited by Fabrice Gangler