0

I have requirement where need to read the all response header and assert them with pre-define values store in the Hashmap. I have written the following codes but getting error as Indexout of bound

Boolean IsPass = false;
Map.Entry<String, String> item : AssertHeaderFromExcel.entrySet()) {

                            try {
                                String key = item.getKey();
                                String value = item.getValue();
                                Headers headers = response.getHeaders();
                                String strjson = headers.getValues(key).size() > 0 ? headers.getValues(key).get(0) : "";

                                System.out.println("test" +headers.getValues(key));

                                strjson = strjson == null ? "" : strjson;
                                 Assert.assertEquals(strjson, value);
                                if (value.equalsIgnoreCase(strjson)) {
                                    if (IsPass) {
                                        IsPass = true;
                                    }
                                } else {
                                    IsPass = false;
                                }

The String value is blank for the first value read from the Hashmap. Hence cannot assert the key and value and IsPass remains as Fail only

Vipin Singh
  • 109
  • 1
  • 14
  • Your snippet appears incomplete. Where is `IsPass` declared? – Tyler Kindy Feb 09 '20 at 12:57
  • I have added now , just check – Vipin Singh Feb 09 '20 at 12:59
  • Sorry, I don't think it's possible to tell what's happening from this snippet. Where does `response` come from? At what point in the request pipeline does this code run? It's possible there aren't any headers added to the response yet. – Tyler Kindy Feb 09 '20 at 13:06
  • Response Header and body has already available now , we have to read the all Response Header and store them in separate as Key and Value string . – Vipin Singh Feb 09 '20 at 13:12

0 Answers0