### Question:
HighlightOnError extends Monitor.NULL { protected void executeScript(WebElement webElement) { ((JavascriptExecutor) driver).executeScript(highlightOperation(), webElement, highlightValue()); } HighlightOnError(WebDriver driver); @Override FluentExecutionStopped exceptionDuringExecution(FluentExecutionStopped ex, WebElement webElement);  }### Answer:
@Test public void lengthier_expression_causing_runtime_exception_should_cause_highlight() { when(wd.findElement(ID_A)).thenReturn(we); when(we.getTagName()).thenReturn("div"); when(we.findElement(ID_B)).thenReturn(we2); when(we2.getTagName()).thenReturn("div"); try { FluentWebElement span = fwd.div(ID_A).div(ID_B); doThrow(new RuntimeException()).when(we2).findElement(tagName("span")); span.span(); fail("should have barfed"); } catch (FluentExecutionStopped e) { assertThat(e.getMessage(), equalTo("RuntimeException during invocation of: ?.div(By.id: idA).div(By.id: idB).span()")); assertThat(e.getCause(), notNullValue()); verify(wd).executeScript("op", we2, "value"); } }
@Test public void webelement_operation_should_cause_highlight() { when(wd.findElement(ID_A)).thenReturn(we); when(we.getTagName()).thenReturn("div"); when(we.findElement(ID_B)).thenReturn(we2); when(we2.getTagName()).thenReturn("div"); when(we2.findElement(tagName("span"))).thenReturn(we3); when(we3.getTagName()).thenReturn("span"); try { FluentWebElement span = fwd.div(ID_A).div(ID_B).span(); doThrow(new RuntimeException()).when(we3).sendKeys("RAIN_IN_SPAIN"); span.sendKeys("RAIN_IN_SPAIN"); fail("should have barfed"); } catch (FluentExecutionStopped e) { assertThat(e.getMessage(), equalTo("RuntimeException during invocation of: ?.div(By.id: idA).div(By.id: idB).span().sendKeys('RAIN_IN_SPAIN')")); assertThat(e.getCause(), notNullValue()); verify(wd).executeScript("op", we3, "value"); } }
@Test public void webelement_operation2_should_cause_highlight() { when(wd.findElement(ID_A)).thenReturn(we); when(we.getTagName()).thenReturn("div"); when(we.findElement(ID_B)).thenReturn(we2); when(we2.getTagName()).thenReturn("div"); when(we2.findElement(tagName("span"))).thenReturn(we3); when(we3.getTagName()).thenReturn("span"); try { FluentWebElement span = fwd.div(ID_A).div(ID_B).span(); doThrow(new RuntimeException()).when(we3).getText(); span.getText().shouldBe("foo"); fail("should have barfed"); } catch (FluentExecutionStopped e) { assertThat(e.getMessage(), equalTo("RuntimeException during invocation of: ?.div(By.id: idA).div(By.id: idB).span().getText().shouldBe('foo')")); assertThat(e.getCause(), notNullValue()); verify(wd).executeScript("op", we3, "value"); } }