void () { CountDownLatch latch1 = new CountDownLatch(1); CountDownLatch latch2 = new CountDownLatch(1); JBCefBrowser jbCefBrowser = new JBCefBrowser("https://maps.google.com"); // we need some heavy website, taking time to load jbCefBrowser.setErrorPage(JBCefBrowserBase.ErrorPage.DEFAULT); jbCefBrowser.getJBCefClient().addLoadHandler(new CefLoadHandler() { @Override public void onLoadingStateChange(CefBrowser browser, boolean isLoading, boolean canGoBack, boolean canGoForward) { System.out.println("JBCefLoadHtmlTest.onLoadingStateChange: " + isLoading); if (!isLoading && latch1.getCount() < 1) { latch2.countDown(); } } @Override public void onLoadStart(CefBrowser browser, CefFrame frame, CefRequest.TransitionType transitionType) { System.out.println("JBCefLoadHtmlTest.onLoadStart: " + frame.getURL()); if (frame.getURL().contains("google")) { jbCefBrowser.loadURL("https://www.jetbrains.com"); // we need some heavy website, taking time to load } } @Override public void onLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) { System.out.println("JBCefLoadHtmlTest.onLoadEnd: " + frame.getURL()); if (frame.getURL().contains("jetbrains")) { latch1.countDown(); } } @Override public void onLoadError(CefBrowser browser, CefFrame frame, ErrorCode errorCode, String errorText, String failedUrl) { System.out.println("JBCefLoadHtmlTest.onLoadError: " + failedUrl); } }, jbCefBrowser.getCefBrowser()); invokeAndWaitForLoad(jbCefBrowser, () -> { JFrame frame = new JFrame(JBCefLoadHtmlTest.class.getName()); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.add(jbCefBrowser.getComponent()); frame.setVisible(true); }); await(latch1); await(latch2); assertThat(jbCefBrowser.getCefBrowser().getURL()).contains("jetbrains"); }