简体   繁体   English

在Selenium rc中检查Dateformat

[英]To Check Dateformat in selenium rc

I am struggling in the below code. 我在下面的代码中苦苦挣扎。 In the webpage some of the document are displayed in the grid. 在网页中,某些文档显示在网格中。 I am selecting first row, then I want check whether it displays date & time format as per the standard. 我选择第一行,然后检查是否按照标准显示日期和时间格式。

DateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss aa");
Date date = new Date();

String newDate = dateFormat.format(date);

// This xpath for selecting first row on the grid
if(!selenium.getText("//*@id='gbs_evo_grid__TreeView_1']/div/div/div/div[1]/table/tbody/tr/td[3]").equals(newDate))
{
    SeleneseTestBase.fail("The Date format is not correct");
}

Can you help me whether the above code is correct or can you give alternate code for that. 您能帮我上面的代码是否正确,还是可以提供替代代码?

mm/dd/yyyy hh:mm:ss aa : You're using m for month, instead of M . mm/dd/yyyy hh:mm:ss aa :您将m用作月份,而不是M

Moreover, your code checks that the date in the page is exactly the same as the current date (with second precision). 此外,您的代码还会检查页面中的日期是否与当前日期完全相同(以秒为单位)。 Is this really what you need? 这真的是您所需要的吗? If the server generating the page doesn't have exactly the ssame date as the client executing the test, or if the test is a bit slow, the test will never pass. 如果生成页面的服务器的执行日期与执行测试的客户端的日期不完全相同,或者测试有点慢,则测试将永远无法通过。 Don't you simply want to check that the generated date is parsable with the date format (and, potentially, that its value is in the same minute or hour as the current date)? 您是否只是想检查一下生成的日期是否可以用日期格式解析(并且有可能其值与当前日期在同一分钟或几小时内)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM