[英]Change System time using Java
I have a situation where I need to change the system time programatically using Java. 我遇到一种情况,需要使用Java以编程方式更改系统时间。 Is there any way to do it with Java or Selenium?
使用Java或Selenium有什么办法吗?
No , Selenium is API to talk with browsers only so you cant achieve this using Selenium. 不 ,Selenium是仅与浏览器通信的 API,因此您无法使用Selenium实现此目的。
Even Java doesn't provide any API for this: How can I set the System Time in Java? 甚至Java也没有为此提供任何API: 如何在Java中设置系统时间?
Why exactly do you need to modify the system time? 为什么需要修改系统时间呢? I can only think it's because you want to validate the display of a date on a page.
我只能认为这是因为您要验证页面上日期的显示。 If this is the case, I would recommend taking 'test_start_time' and 'test_end_time' datestamps, and validating the value you receive from selenium as being within these limits rather than asserting a specific time.
如果是这种情况,我建议您使用“ test_start_time”和“ test_end_time”日期戳,并验证您从硒中获得的值在这些限制之内,而不是断言特定的时间。
If you need it for another reason then there are options, but they're pretty hacky. 如果您出于其他原因需要它,那么可以选择,但是它们很笨拙。 :(
:(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.