我的情况是,从我的应用程序中,我打开waze等待25秒,进入主屏幕,等待10秒,然后系统移回waze,然后等待15秒,然后再次进入主页,在那里等待10秒,
mainScreen.openWaze();
TimeWatch watch = TimeWatch.start();
double passedTimeInSeconds = 0;
System.out.println("start");
while(passedTimeInSeconds < 26.0){
passedTimeInSeconds = watch.time(TimeUnit.SECONDS);
System.out.println("the seconds of 1 "+passedTimeInSeconds);
wazeInApp.validateWhereToField();
}
watch.reset();
passedTimeInSeconds = 0;
wazeInApp.goToHomeScreen();
while(passedTimeInSeconds < 11.0){
passedTimeInSeconds = watch.time(TimeUnit.SECONDS);
System.out.println("the seconds of 2 "+passedTimeInSeconds);
wazeInApp.validateWhereToField();
}
watch.reset();
passedTimeInSeconds = 0;
while(passedTimeInSeconds < 16.0){
passedTimeInSeconds = watch.time(TimeUnit.SECONDS);
System.out.println("the seconds 3 "+passedTimeInSeconds);
wazeInApp.validateWhereToField();
}
wazeInApp.goToHomeScreen();
}
我的控制台打印:
start
the seconds of 1 0.0
the seconds of 1 12.0
the seconds of 1 13.0
the seconds of 1 13.0
the seconds of 1 34.0
the seconds of 2 0.0
the seconds of 2 0.0
the seconds of 2 0.0
the seconds of 2 0.0
the seconds of 2 9.0
the seconds of 2 15.0
the seconds 3 0.0
the seconds 3 2.0
the seconds 3 4.0
the seconds 3 6.0
the seconds 3 9.0
the seconds 3 11.0
the seconds 3 13.0
the seconds 3 34.0
看起来奇怪的是,打印的时间不正确,也超出了时间限制,而且这些是正确的解决方案吗?非常感谢。
1条答案
按热度按时间0yycz8jy1#
我相信你正试图在这26秒的时间内检查一些东西,所以你不想
Thread.sleep()
我尝试了下面的方法,它对我有效。在这里,我以系统当前秒为单位,加上26秒(我们预期的时间),循环将从当前秒开始迭代到26秒。输出:
由于毫秒的原因,有时情况可能会失败。