Interface JavaScriptHandler
- All Superinterfaces:
Serializable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A handler is registered for the whole test environment, with
BrowserlessTestConfig.javaScriptHandlers() or
BrowserlessConfiguration.Builder.withJavaScriptHandlers(Class[]).
Every UI the environment creates, also on a reload or in a new window, gets
its own instance, created with the public no-argument constructor before the
UI is initialized. The handler then sees each piece of JavaScript at the
moment it is sent to the simulated browser, in order, also while a view is
being navigated to, and answers it the way the browser would, so the
application behaves as it does in a browser without the test doing anything:
public class BrowserTimeZone implements JavaScriptHandler {
@Override
public void handle(ExecutedJavaScript.Execution execution) {
if (execution.isWaitingForResult() && execution.getExpression()
.contains("resolvedOptions().timeZone")) {
execution.resolve("Europe/Helsinki");
}
}
}
@BrowserlessTestConfig(javaScriptHandlers = BrowserTimeZone.class)
class ScheduleViewTest extends BrowserlessTest {
}
A handler is offered every piece of JavaScript and ignores what it does not
simulate. ExecutedJavaScript.Execution.getUI() tells which UI the
JavaScript was sent to. Handlers run after the simulations Browserless Test
ships with, in the order they are registered. JavaScript that a handler makes
the application schedule, from a result handler for example, is sent at the
next client boundary, as with a browser. To check afterwards what was sent,
use ExecutedJavaScript.capture() instead.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidhandle(ExecutedJavaScript.Execution execution) Reacts to a piece of JavaScript that the simulated browser has received.
-
Method Details
-
handle
Reacts to a piece of JavaScript that the simulated browser has received.- Parameters:
execution- the JavaScript the browser received, not null
-