Skip to content

Commit 804fdb1

Browse files
authored
Appium Conf 2024 : Java Examples (#48)
* Appium conference 2024 Examples Added examples as per the demo given in Appium Conference 2024 * Appium conference 2024 Examples Updated the examples shown in the Appium conference * Appium conference 2024 Examples Added examples based on what is shown in Appium conference
1 parent 17d6471 commit 804fdb1

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

docs/commands.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,108 @@ config.put("responseBody","{\n" +
274274
driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'List')]")).click();
275275
```
276276

277+
### Add or Remove Request Headers
278+
// Create the remove headers list
279+
List<String> removeHeaders = new ArrayList<>();
280+
removeHeaders.add("cookie");
277281

282+
// Create the headers object
283+
Map headers = new HashMap();
284+
headers.put("remove", removeHeaders);
285+
286+
infoLogs("** add mock code here **");
287+
Map<String, Object> config = new HashMap();
288+
config.put("url", "**/api/lobbyApi/v1/getMatches");
289+
config.put("headers",headers);
290+
Object id= ((JavascriptExecutor) driver).executeScript("interceptor: addMock", new HashMap() {{
291+
put("config", config);
292+
}});
293+
294+
### Update request Payload partially
295+
296+
```
297+
ObjectMapper objectMapper = new ObjectMapper();
298+
299+
ArrayNode updateRequestBodyArray = objectMapper.createArrayNode();
300+
// Update sportsType to 1,so that all the sports tab should show the same data.
301+
302+
ObjectNode sportsType = objectMapper.createObjectNode();
303+
sportsType.put("jsonPath", "$.sportsType");
304+
sportsType.put("value", "1");
305+
306+
updateRequestBodyArray.add(sportsType);
307+
308+
309+
List<Map<String, Object>> updateRequestBodyList = new ArrayList<>();
310+
for (int i = 0; i < updateRequestBodyArray.size(); i++) {
311+
Map<String, Object> map = objectMapper.convertValue(updateRequestBodyArray.get(i), Map.class);
312+
updateRequestBodyList.add(map);
313+
}
314+
315+
Map<String, Object> config = new HashMap<>();
316+
config.put("url", "**/api/lobbyApi/v1/getMatches");
317+
config.put("updateRequestBody", updateRequestBodyList);
318+
319+
infoLogs("Step 2: Add Mock Interceptor");
320+
Object id= ((JavascriptExecutor) driver).executeScript("interceptor: addMock", new HashMap<String, Object>() {{
321+
put("config", config);
322+
}});
323+
```
324+
325+
### Response Payload Partial Update
326+
327+
```
328+
ArrayNode updateRequestBodyArray = objectMapper.createArrayNode();
329+
updateRequestBodyArray.add(createUpdateBodySpec
330+
("$.matches.1[0].team1.dName", "Appium"));
331+
updateRequestBodyArray.add(createUpdateBodySpec
332+
("$.matches.1[0].team2.dName", "Selenium"));
333+
updateRequestBodyArray.add(createUpdateBodySpec
334+
("$.matches.1[0].seriesName", "The Official Appium Conference 2024"));
335+
336+
337+
List<Map<String, Object>> updateRequestBodyList = new ArrayList<>();
338+
for (int i = 0; i < updateRequestBodyArray.size(); i++) {
339+
Map<String, Object> map = objectMapper.convertValue(updateRequestBodyArray.get(i), Map.class);
340+
updateRequestBodyList.add(map);
341+
}
342+
343+
Map<String, Object> config = new HashMap<>();
344+
config.put("url", "**/api/lobbyApi/v1/getMatches");
345+
config.put("updateResponseBody", updateRequestBodyList);
346+
347+
Object id= ((JavascriptExecutor) driver).executeScript("interceptor: addMock", new HashMap<String, Object>() {{
348+
put("config", config);
349+
}});
350+
```
351+
352+
### Status code update
353+
354+
```
355+
Map<String, Object> config = new HashMap();
356+
config.put("url", "**/api/fl/auth/v3/getOtp");
357+
config.put("statusCode", Integer.valueOf(500));
358+
359+
Object id= ((JavascriptExecutor) driver)
360+
.executeScript("interceptor: addMock",
361+
new HashMap() {{put("config", config); }});
362+
363+
```
364+
365+
### Remove Mock
366+
367+
```
368+
369+
infoLogs("** Remove the Mock **");
370+
((JavascriptExecutor) driver)
371+
.executeScript("interceptor: removeMock", new HashMap() {{
372+
put("id", id);
373+
}});
374+
375+
Below code shows how to add the mock and get the id
376+
377+
Object id= ((JavascriptExecutor) driver)
378+
.executeScript("interceptor: addMock",
379+
new HashMap() {{put("config", config); }});
380+
381+
```

0 commit comments

Comments
 (0)