Skip to content

Commit 03ab1dc

Browse files
Update java example to use Hashmap (#28)
1 parent af903d8 commit 03ab1dc

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

docs/commands.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,26 +253,24 @@ stopListening command will retunrs an array of network details in the below JSON
253253

254254
### Java Example
255255
```
256-
JSONObject customObject = new JSONObject();
257-
customObject.put("url","/api/users?.*");
258-
customObject.put("responseBody","{\n" +
259-
" \"page\": 2,\n" +
260-
" \"per_page\": 6,\n" +
261-
" \"total\": 12,\n" +
262-
" \"total_pages\": 2,\n" +
263-
" \"data\": [\n" +
264-
" {\n" +
265-
" \"id\": 7,\n" +
266-
" \"email\": \"michael.test@reqres.in\",\n" +
267-
" \"first_name\": \"Michael\",\n" +
268-
" \"last_name\": \"Lawson\",\n" +
269-
" \"avatar\": \"https://reqres.in/img/faces/7-image.jpg\"\n" +
270-
" }\n" +
271-
" ]\n" +
272-
"}");
273-
JSONObject parentJson = new JSONObject();
274-
parentJson.put("config", customObject);
275-
driver.executeScript("interceptor: addMock",new JSONObject(parentJson));
256+
Map<String, String> config = new HashMap();
257+
config.put("url", "/api/users?.*");
258+
config.put("responseBody","{\n" +
259+
" \"page\": 2,\n" +
260+
" \"per_page\": 6,\n" +
261+
" \"total\": 12,\n" +
262+
" \"total_pages\": 2,\n" +
263+
" \"data\": [\n" +
264+
" {\n" +
265+
" \"id\": 7,\n" +
266+
" \"email\": \"michael.test@reqres.in\",\n" +
267+
" \"first_name\": \"Michael\",\n" +
268+
" \"last_name\": \"Lawson\",\n" +
269+
" \"avatar\": \"https://reqres.in/img/faces/7-image.jpg\"\n" +
270+
" }\n" +
271+
" ]\n" +
272+
"}");
273+
((JavascriptExecutor)DriverManager.getDriver()).executeScript("interceptor: addMock",config);
276274
driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'List')]")).click();
277275
```
278276

0 commit comments

Comments
 (0)