需要使用selenium Java验证带有多个随机字符串的错误消息

需要使用selenium Java验证带有多个随机字符串的错误消息,selenium,automation,cucumber,Selenium,Automation,Cucumber,我必须验证为10个字段填充的错误消息,10个字段名称将一起出现在错误消息中 示例: Error message:10 fields got over lapped and 10 field names are ac, bc, dc.. 你能帮我写逻辑来验证包含所有随机字符串的错误消息吗 需要将所有字符串值传递到creates字符串以比较错误消息 Map<String,String> m = arg1.asMap(String.class,String.class);

我必须验证为10个字段填充的错误消息,10个字段名称将一起出现在错误消息中

示例:

Error message:10 fields got over lapped and 10 field names are ac, bc, dc..
你能帮我写逻辑来验证包含所有随机字符串的错误消息吗

需要将所有字符串值传递到creates字符串以比较错误消息

 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));
        }
    }
Map m=arg1.asMap(String.class,String.class);
System.out.println(“\n包含以下数据的填充表单\n”);
for(字符串字段名:m.keySet())
{
//需要将此字段名传递给错误消息,并且错误消息可能有多个字段名//
System.out.println(“Key->”+fieldnames+“Value->”+m.get(fieldnames));
}
}

您可以获得如下键和值,这是如何使用
Map
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());
}
回答您关于如何断言它们的问题:

key1=value1
key2=value2
.
.
.
   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() );
List fieldNames=new ArrayList();
Map Map=arg1.asMap(String.class,String.class);
int i=0;
for(条目:map.entrySet()){
System.out.println(entry.getKey()+“=”+entry.getValue());
fieldName.add(entry.getKey());
i++;
}
Assert.assertEquals(错误消息,“错误消息:“+i+”字段被重叠,“+i+”字段名为“+fieldName.toString());