public final class Scripts extends Object
Fn.Presenters that delegate
to Java scripting API. Initialize your presenter
like this:
and your runnable can make extensive use ofRunnablerun = ...; // your own init codeFn.Presenterp = Scripts.Scripts.createPresenter(); BrowserBuilder.newBrowser(p).loadFinished(run).BrowserBuilder.showAndWait();
JavaScriptBody directly or
indirectly via APIs using such annotation themselves.
Alternatively one can manipulate the presenter manually, which is especially useful when writing tests:
The previous code snippet requires Java 7 language syntax, as it relies on try-with-resources language syntactic sugar feature. The same block of code can be used on older versions of Java, but it is slightly more verbose.@Testpublic void runInASimulatedBrowser() throws Exception {Fn.Presenterp = Scripts.Scripts.createPresenter(); try (Closeablec =Fn.activate(p)) { // your code operating in context of p } }
| Modifier and Type | Method and Description |
|---|---|
static Fn.Presenter |
createPresenter()
Simple implementation of
Fn.Presenter that delegates
to Java scripting API. |
static Fn.Presenter |
createPresenter(Executor exc)
Implementation of
Fn.Presenter that delegates
to Java scripting API and can control execution
thread. |
public static Fn.Presenter createPresenter()
Fn.Presenter that delegates
to Java scripting API. The presenter runs headless
without appropriate simulation of browser APIs. Its primary usefulness
is inside testing environments. The presenter implements Executor
interface, but invokes all runnables passed to Executor.execute(java.lang.Runnable)
immediately.ScriptEngine for text/javascript mimetypepublic static Fn.Presenter createPresenter(Executor exc)
Fn.Presenter that delegates
to Java scripting API and can control execution
thread. The presenter runs headless
without appropriate simulation of browser APIs. Its primary usefulness
is inside testing environments. The presenter implements Executor
interface, and passes all runnables from Executor.execute(java.lang.Runnable)
to here in provided exc instance.exc - the executor to re-schedule all asynchronous requests toScriptEngine for text/javascript mimetypeCopyright © 2019 The Apache Software Foundation. All rights reserved.