DecoratedWebDriver extends DecoratedTopmost<WebDriver> implements WebDriver, WrapsDriver, JavascriptExecutor, HasInputDevices, HasTouchScreen, Interactive { @Override public Object executeAsyncScript(String script, Object... args) { WebDriver driver = getOriginal(); if (driver instanceof JavascriptExecutor) { return wrapObject(((JavascriptExecutor) driver).executeAsyncScript(script, args)); } else { throw new WebDriverException("Wrapped webdriver does not implement JavascriptExecutor: " + driver); } } DecoratedWebDriver(WebDriver driver); @Override final WebDriver getWrappedDriver(); @Override void get(String url); @Override String getCurrentUrl(); @Override String getTitle(); @Override WebElement findElement(final By by); @Override List<WebElement> findElements(final By by); @Override String getPageSource(); @Override void close(); @Override void quit(); @Override Set<String> getWindowHandles(); @Override String getWindowHandle(); @Override TargetLocator switchTo(); @Override Navigation navigate(); @Override Options manage(); @Override Object executeScript(String script, Object... args); @Override Object executeAsyncScript(String script, Object... args); @Override Keyboard getKeyboard(); @Override Mouse getMouse(); @Override TouchScreen getTouch(); @Override void perform(Collection<Sequence> actions); @Override void resetInputState();  }
@Test void testExecuteAsyncScriptNotSupported() { WebDriver mockedDriver = mock(WebDriver.class); DecoratedWebDriver decoratedDriver = new DecoratedWebDriver(mockedDriver); assertThrows(WebDriverException.class, () -> decoratedDriver.executeAsyncScript("...")); }
@Test void testExecuteAsyncScriptThatReturnsAPrimitive() { verifyFunction($ -> ((JavascriptExecutor) $).executeAsyncScript("..."), 1); }
@Test void testExecuteAsyncScriptThatReturnsAnElement() { WebElement element = mock(WebElement.class); verifyDecoratingFunction($ -> (WebElement) ((JavascriptExecutor) $).executeAsyncScript("..."), element, WebElement::click); }