0

I have to validate an error message getting populated for 10 fields, 10 field names will be mentioned in the error message together.

Example :

Error message:10 fields got over lapped and 10 field names are ac, bc, dc..

Can you please help me to write the logic to validate the error message having all random strings.

Need to pass all strings values in to the creates string to compare the error message.

 Map<String,String> m =  arg1.asMap(String.class,String.class);
        System.out.println("\nFilling form with below data\n");
        for( String fieldname : m.keySet())
        {
//Need to pass this field name to the error message and the error message may have multiple fieldnames//

            System.out.println("Key -> " + fieldnames + " Value -> " + m.get(fieldnames));
        }
    }
Marit
  • 2,399
  • 18
  • 27

1 Answers1

1

You can get key and values as following and here is a good answer for how to use Map and EntrySet :

Map<String,String> map =  arg1.asMap(String.class,String.class);
for (Entry<String, String> entry : map.entrySet()) {
    System.out.println(entry.getKey() + "=" + entry.getValue());
}

OUTPUT :

key1=value1
key2=value2
.
.
.

As an answer of your question for how to assert them :

   List<String> fieldNames = new ArrayList<String>();
   Map<String,String> map =  arg1.asMap(String.class,String.class);
   int i = 0;
    for (Entry<String, String> entry : map.entrySet()) {
        System.out.println(entry.getKey() + "=" + entry.getValue());
        fieldName.add(entry.getKey());
        i++;
    }
    Assert.assertEquals(errorMessage, "Error message:" + i + "fields got over lapped and" +  i + "field names are" +  fieldName.toString() );
sayhan
  • 1,168
  • 1
  • 16
  • 22