Skip to content

Commit

Permalink
Update java example to use Hashmap (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudharsan-selvaraj authored Mar 18, 2024
1 parent af903d8 commit 03ab1dc
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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();
```

Expand Down

0 comments on commit 03ab1dc

Please sign in to comment.