Closed anuj3011 closed 5 months ago
Im unable to reproduce the issue on my end. If this is blocking, you can try the below example
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);
Hi @sudharsan-selvaraj, While using the hapmap I'm getting the below error.
Could you please help on this issue.
Error: org.openqa.selenium. InvalidArgumentException: The following required parameter is missing: ["config"]
Known required parameters are: ["config"]
You have provided none
@PrakashBalraj94 Can you try with the below example?
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" +
"}");
Map<String,Map<String, String>> args = new HashMap("config", config);
((JavascriptExecutor)DriverManager.getDriver()).executeScript("interceptor: addMock", args);
@sudharsan-selvaraj Thanks for your response!
The above works find after adding the below line,
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" +
"}");
Map<String,Map<String, String>> args = new HashMap();
// Added below line to the existing code
args.put("config", config);
((JavascriptExecutor)DriverManager.getDriver()).executeScript("interceptor: addMock", args);
Using the exact same java code provided in the example, I'm getting
java.lang.IllegalArgumentException: Argument is of an illegal type: org.json.JSONObject at org.openqa.selenium.remote.internal.WebElementToJsonConverter.apply(WebElementToJsonConverter.java:83)