@Test public void should_Give_Focus_To_Component_And_Wait_Till_It_Is_Focused() { showWindow(); assertThatButtonDoesNotHaveFocus(); window.button.waitToRequestFocus(); final CountDownLatch done = new CountDownLatch(1); StopWatch stopWatch = startNewStopWatch(); new Thread() { @Override public void run() { driver.focusAndWaitForFocusGain(window.button); done.countDown(); } }.start(); try { done.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } stopWatch.stop(); assertThatButtonHasFocus(); assertThatWaited(stopWatch, TIME_TO_WAIT_FOR_FOCUS_GAIN); }
public static StopWatch startNewStopWatch() { StopWatch stopWatch = new StopWatch(); stopWatch.start(); return stopWatch; }