Web.WebInteraction

public static class Web.WebInteraction
extends Object

java.lang.Object
   ↳ android.support.test.espresso.web.sugar.Web.WebInteraction<R>


Analogous to a ViewInteraction or a DataInteraction, a WebInteraction exposes a fluent API to the underlying WebView.

Summary

Public methods

<E> WebInteraction<E> check(WebAssertion<E> assertion)

Evaluates the given WebAssertion.

WebInteraction<R> forceJavascriptEnabled()

Performs a force enable of Javascript on a WebView.

R get()

Returns the result of a prior call to perform or check.

WebInteraction<R> inWindow(WindowReference window)

Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.

WebInteraction<R> inWindow(Atom<WindowReference> windowPicker)

Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.

<E> WebInteraction<E> perform(Atom<E> atom)

Executes the provided atom within the current context (the combination of Window and Element References).

WebInteraction<R> reset()

Removes the Element and Window references from this interaction.

WebInteraction<R> withContextualElement(Atom<ElementReference> elementPicker)

Allows for contextually evaluating this WebInteraction with the selected element.

WebInteraction<R> withElement(ElementReference element)

Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.

WebInteraction<R> withElement(Atom<ElementReference> elementPicker)

Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.

WebInteraction<R> withNoTimeout()

Disables all Timeouts on this WebInteraction.

WebInteraction<R> withTimeout(long amount, TimeUnit unit)

Sets a specific timeout for this WebInteraction.

Inherited methods

From class java.lang.Object

Public methods

check

WebInteraction<E> check (WebAssertion<E> assertion)

Evaluates the given WebAssertion.

The WebAssertion's atom is evaluated, after it's evaluation completes, the WebAssertion is run on the main thread to perform further checks. The WebAssertion is given the Atom's result and the WebView it had run against.

After this method completes, the result of the atom's evaluation is avaliable via get.

Parameters
assertion WebAssertion

Returns
WebInteraction<E>

forceJavascriptEnabled

WebInteraction<R> forceJavascriptEnabled ()

Performs a force enable of Javascript on a WebView.

All WebView interactions are done via Javascript - therefore the WebView we are working on must support Javascript evaluation.

Enabling Javascript may cause the WebView under test to be reloaded. This is necessary to ensure the test infrastructure javascript bridges are loaded by the WebView.

Returns
WebInteraction<R>

get

R get ()

Returns the result of a prior call to perform or check.

Returns
R

inWindow

WebInteraction<R> inWindow (WindowReference window)

Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.

By default Javascript may be evaluated in the main window. However in an application which uses frames, you may want to evaluate in another frame.

Parameters
window WindowReference

Returns
WebInteraction<R>

inWindow

WebInteraction<R> inWindow (Atom<WindowReference> windowPicker)

Causes this WebInteraction to have it's javascript evaluated in a particular DOM window.

This method accepts an Atom which will be evaluated in the main window to choose a particular DOM window for further interactions. This method will block until the the provided Atom returns with a result.

Parameters
windowPicker Atom

Returns
WebInteraction<R>

perform

WebInteraction<E> perform (Atom<E> atom)

Executes the provided atom within the current context (the combination of Window and Element References).

This method blocks until the Atom returns. The result of the Atom's evaluation is used to create a new instance of WebInteraction which can be used to access the result of the Atom's evaluation.

Parameters
atom Atom

Returns
WebInteraction<E>

reset

WebInteraction<R> reset ()

Removes the Element and Window references from this interaction.

This is usually necessary when a prior action (for example a click) introduces a navigation that invalidates the ElementReference and WindowReference pointers.

Returns
WebInteraction<R>

withContextualElement

WebInteraction<R> withContextualElement (Atom<ElementReference> elementPicker)

Allows for contextually evaluating this WebInteraction with the selected element.

Specifically the elementPicker atom will be evaluated with the CURRENTLY selected element to discover the new element to work against.

This allows callers to interact with a document that looks like this:

 <div id="teacher">
   <div id="person_name">
     <p>Socrates</p>
   </div>
 </div>
 <div id="student">
   <div id="person_name">
     <p>Plato</p>
   </div>
 </div>
 
 
With code like this:
onWebView()
   .withElement(findElement(Locator.ID, "teacher"))
   .withContextualElement(findElement(Locator.ID, "person_name"))
   .check(webMatches(getText(), containsString("Socrates")));
 

Parameters
elementPicker Atom

Returns
WebInteraction<R>

withElement

WebInteraction<R> withElement (ElementReference element)

Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.

Calling this method resets any previously selected ElementReference.

Parameters
element ElementReference

Returns
WebInteraction<R>

withElement

WebInteraction<R> withElement (Atom<ElementReference> elementPicker)

Causes this WebInteraction to supply the given ElementReference to the Atom prior to evaluation.

This method accepts an Atom which it will evaluate on the current context's Window. This method blocks until the evaluation completes.

Calling this method resets any previously selected ElementReference.

If you want to evaluate the elementPicker in the context of the previously selected ElementReference

Parameters
elementPicker Atom

Returns
WebInteraction<R>

withNoTimeout

WebInteraction<R> withNoTimeout ()

Disables all Timeouts on this WebInteraction.

Javascript evaluation is performed asynchronously on the WebKit/Chromium thread. By default we wait a short while for the result to be delivered back to the test.

Returns
WebInteraction<R>

withTimeout

WebInteraction<R> withTimeout (long amount, 
                TimeUnit unit)

Sets a specific timeout for this WebInteraction.

Parameters
amount long

unit TimeUnit

Returns
WebInteraction<R>