【发布时间】:2021-10-03 02:04:30
【问题描述】:
我的情况是,从我的应用程序中打开位智等待 25 秒,进入主屏幕,等待 10 秒,然后系统返回位智,然后我等待 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
看起来很奇怪,打印的时间不正确,也超出了时间限制,而且这些是否是等待的正确解决方案(什么都不做)? 谢谢
【问题讨论】:
-
你想做什么?暂停特定时间段的执行?
-
是的,但我不想做 Thread.sleep
-
调试代码以在运行时查看变量值。
-
@pburgr 做到了,它就是你看到的打印堆栈
-
这些是等待(什么都不做)的正确解决方案吗? --> 你能把openWaze() 和validateWhereToField() 的代码贴出来吗?如果我们能看到,那么只有我们可以告诉你。你可以试试 int passTimeInSeconds = 0; 吗?