From 03ab1dc334dd1ca63a34d107fb02b31e55b3fcfc Mon Sep 17 00:00:00 2001 From: Sudharsan Selvaraj Date: Mon, 18 Mar 2024 22:39:25 +0530 Subject: [PATCH] Update java example to use Hashmap (#28) --- docs/commands.md | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 2effd3b..f34db2d 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -253,26 +253,24 @@ stopListening command will retunrs an array of network details in the below JSON ### Java Example ``` -JSONObject customObject = new JSONObject(); - customObject.put("url","/api/users?.*"); - customObject.put("responseBody","{\n" + - " \"page\": 2,\n" + - " \"per_page\": 6,\n" + - " \"total\": 12,\n" + - " \"total_pages\": 2,\n" + - " \"data\": [\n" + - " {\n" + - " \"id\": 7,\n" + - " \"email\": \"michael.test@reqres.in\",\n" + - " \"first_name\": \"Michael\",\n" + - " \"last_name\": \"Lawson\",\n" + - " \"avatar\": \"https://reqres.in/img/faces/7-image.jpg\"\n" + - " }\n" + - " ]\n" + - "}"); -JSONObject parentJson = new JSONObject(); -parentJson.put("config", customObject); -driver.executeScript("interceptor: addMock",new JSONObject(parentJson)); +Map config = new HashMap(); +config.put("url", "/api/users?.*"); +config.put("responseBody","{\n" + + " \"page\": 2,\n" + + " \"per_page\": 6,\n" + + " \"total\": 12,\n" + + " \"total_pages\": 2,\n" + + " \"data\": [\n" + + " {\n" + + " \"id\": 7,\n" + + " \"email\": \"michael.test@reqres.in\",\n" + + " \"first_name\": \"Michael\",\n" + + " \"last_name\": \"Lawson\",\n" + + " \"avatar\": \"https://reqres.in/img/faces/7-image.jpg\"\n" + + " }\n" + + " ]\n" + + "}"); +((JavascriptExecutor)DriverManager.getDriver()).executeScript("interceptor: addMock",config); driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'List')]")).click(); ```