### Question:
WebBase extends MappedElement implements BaseUI { public void waitElement(Integer index) { final String locator = getLocatorWithParameters(getElementMap().locator()[index].toString()); final By by = ByConverter.convert(getElementMap().locatorType(), locator); final long startedTime = GregorianCalendar.getInstance().getTimeInMillis(); Date startWaitTotal = GregorianCalendar.getInstance().getTime(); while (true) { try { waitThreadSleep(BehaveConfig.getRunner_ScreenMinWait()); getDriver().manage().timeouts().implicitlyWait(getImplicitlyWaitTimeoutInMilliseconds(), TimeUnit.MILLISECONDS); waitLoading(); Date endLoading = GregorianCalendar.getInstance().getTime(); Long diffLoading = endLoading.getTime() - startWaitTotal.getTime(); logStatistics("O tempo para esperar o LOADING foi de [" + diffLoading + "ms]"); getDriver().manage().timeouts().implicitlyWait(getImplicitlyWaitTimeoutInMilliseconds(), TimeUnit.MILLISECONDS); waitClickable(by); Date endClickable = GregorianCalendar.getInstance().getTime(); Long diffClickable = endClickable.getTime() - endLoading.getTime(); Long diffTotal = endClickable.getTime() - startWaitTotal.getTime(); logStatistics("O tempo para esperar o CLICKABLE foi de [" + diffClickable + "ms] e total foi de [" + diffTotal + "ms]"); getDriver().manage().timeouts().implicitlyWait(getImplicitlyWaitTimeoutInMilliseconds(), TimeUnit.MILLISECONDS); waitVisibility(by); Date endVisibility = GregorianCalendar.getInstance().getTime(); Long diffVisibility = endVisibility.getTime() - endClickable.getTime(); diffTotal = endVisibility.getTime() - startWaitTotal.getTime(); logStatistics("O tempo para esperar o VISIBILITY foi de [" + diffVisibility + "ms] e total foi de [" + diffTotal + "ms]"); break; } catch (Exception e) { log.warn("Erro no Wait Element"); log.warn(e); } finally { getDriver().manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); if (GregorianCalendar.getInstance().getTimeInMillis() - startedTime > BehaveConfig.getRunner_ScreenMaxWait()) { throw new BehaveException(message.getString("exception-element-not-found", getElementMap().name())); } } } }  WebDriver getDriver(); void logStatistics(String msg); List<WebElement> getElements(); String getText(); void waitElement(Integer index); void waitElementOnlyVisible(Integer index); @SuppressWarnings("unchecked") void waitLoading(); void isVisibleDisabled(); void waitVisibleClickableEnabled(); Long getImplicitlyWaitTimeoutInMilliseconds(); List<String> getLocatorParameter(); void setLocatorParameters(List<String> locatorParameter2); JavascriptExecutor getJavascriptExecutor(); String getId(); void waitVisibleText(String text); void waitNotVisibleText(String text); void waitVisibleOrNotTextInElement(String text, boolean visible); void waitInvisible(); void waitInvisible(int index); void blur(); void waitText(String text); void waitNotText(String text); void waitTextNotInElement(String text); void waitTextInElement(String text); static ElementMap loadingMap; static boolean alreadySearchLoadingMap; }### Answer:
@Test @Ignore public void testWaitElement() { WebElement element = Mockito.mock(WebElement.class); Mockito.when(element.isDisplayed()).thenReturn(true); WebDriver driver = Mockito.mock(WebDriver.class); Mockito.when(driver.findElement((By) Mockito.anyObject())).thenReturn(element); Runner runner = Mockito.mock(Runner.class); Mockito.when(runner.getDriver()).thenReturn(driver); WebBase webBase = new WebBase(); ElementMap mapa = Mockito.mock(ElementMap.class); Mockito.when(mapa.locator()).thenReturn(new String[] { "ID" }); Mockito.when(mapa.locatorType()).thenReturn(ElementLocatorType.XPath); webBase.setRunner(runner); webBase.setElementMap(mapa); webBase.waitElement(1); }