在JavaSelenium中使用hashmap验证月数

在JavaSelenium中使用hashmap验证月数,java,selenium-webdriver,automation,hashmap,logic,Java,Selenium Webdriver,Automation,Hashmap,Logic,我的自动化框架是基于Perfecto云的,使用Java中的Selenium API。 在我的测试场景中,我需要在月视图中打开日历,然后向右向左滑动,然后验证是否显示下一个月。 我读了一些帖子,发现HaspMap可以用于此。有谁能指导我如何在这种情况下使用hashmap吗。一些代码片段会很有帮助 测试步骤: 在月视图中启动日历 捕获当前月份(如三月)并保存在字符串curMonth中 现在向右向左旋转一个月,以便更换 捕获屏幕上显示的月份值,现在是4月份,并在字符串nextMonth中保存 验证值n

我的自动化框架是基于Perfecto云的,使用Java中的Selenium API。 在我的测试场景中,我需要在月视图中打开日历,然后向右向左滑动,然后验证是否显示下一个月。 我读了一些帖子,发现HaspMap可以用于此。有谁能指导我如何在这种情况下使用hashmap吗。一些代码片段会很有帮助

测试步骤:

在月视图中启动日历 捕获当前月份(如三月)并保存在字符串curMonth中 现在向右向左旋转一个月,以便更换 捕获屏幕上显示的月份值,现在是4月份,并在字符串nextMonth中保存 验证值nextMonth实际上是curMonth旁边的值 下面是我正在尝试使用的代码示例。阅读评论

    HashMap<String, Integer> Table = new HashMap<String, Integer>();
    Table.put("JAN", 1);    
    Table.put("FEB", 2);    
    Table.put("MAR", 3);    
    Table.put("APR", 4);    
    Table.put("MAY", 5);    
    Table.put("JUN", 6);    

    String testdata="MAR";
    System.out.println("------------------------------------------------");
    Integer curMon = Table.get(testdata);
    System.out.println(curMon);
    //Here output will be 3 which it will fetch from the hashmap table

    //Now I am adding 1 from the return value which is 3. So 3+1=4 
    Integer newMonthValue=curMon+1;

    //Now how to associate the integer value which is 4 stored in newMonthValue and map it to April from the Map

要按值获取月份名称,只需调用以下实用程序方法:

private static String getMonthByValue(HashMap<String, Integer> table, Integer newMonthValue) {
    for (Map.Entry<String, Integer> mapEntry : table.entrySet()) {
        if (mapEntry.getValue().equals(newMonthValue)) {
            return mapEntry.getKey();
        }
    }
    return null;
}
用法:

String newMonthName = getMonthByValue(Table, newMonthValue);//returns "APR" in your case

在我的场景中,在阅读了几篇文章之后,我假设应该使用HaspMap,因此发布了this.OK,但是添加一些链接将有助于理解场景。HashMap将值映射到键。您认为这些日期的关键和价值是什么?为什么不能直接比较前两个日期和当前日期?
String newMonthName = getMonthByValue(Table, newMonthValue);//returns "APR" in your case