Web.WebInteraction

public static class Web.WebInteraction
extends Object

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


类似于ViewInteraction或DataInteraction,WebInteraction将流畅的API暴露给底层的WebView。

Summary

Public methods

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

评估给定的WebAssertion。

WebInteraction<R> forceJavascriptEnabled()

在WebView上执行强制启用Javascript。

R get()

返回先前调用的结果以执行或检查。

WebInteraction<R> inWindow(WindowReference window)

使此WebInteraction在特定的DOM窗口中对其进行JavaScript评估。

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

使此WebInteraction在特定的DOM窗口中对其进行JavaScript评估。

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

在当前上下文中执行提供的原子(Window和Element References的组合)。

WebInteraction<R> reset()

从此交互中移除元素和窗口引用。

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

允许使用所选元素上下文评估此WebInteraction。

WebInteraction<R> withElement(ElementReference element)

导致此WebInteraction在评估之前将给定的ElementReference提供给Atom。

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

导致此WebInteraction在评估之前将给定的ElementReference提供给Atom。

WebInteraction<R> withNoTimeout()

在此WebInteraction上禁用所有超时。

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

为此WebInteraction设置特定的超时时间。

Inherited methods

From class java.lang.Object

Public methods

check

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

评估给定的WebAssertion。 WebAssertion的原子在评估完成后进行评估,WebAssertion在主线程上运行以执行进一步检查。 WebAssertion被赋予了Atom的结果和它运行的WebView。 此方法完成后,原子评估的结果可通过get获得。

Parameters
assertion WebAssertion
Returns
WebInteraction<E>

forceJavascriptEnabled

WebInteraction<R> forceJavascriptEnabled ()

在WebView上执行强制启用Javascript。 所有的WebView交互都是通过Javascript完成的 - 因此我们正在研究的WebView必须支持Javascript评估。 启用Javascript可能会导致被测试的WebView被重新加载。 这对确保WebView加载测试基础架构的JavaScript桥是非常必要的。

Returns
WebInteraction<R>

get

R get ()

返回先前调用的结果以执行或检查。

Returns
R

inWindow

WebInteraction<R> inWindow (WindowReference window)

使此WebInteraction在特定的DOM窗口中对其进行JavaScript评估。 默认情况下,Javascript可以在主窗口中进行评估。 但是,在使用框架的应用程序中,您可能需要在另一个框架中进行评估。

Parameters
window WindowReference
Returns
WebInteraction<R>

inWindow

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

使此WebInteraction在特定的DOM窗口中对其进行JavaScript评估。 此方法接受一个Atom,它将在主窗口中进行评估以选择特定的DOM窗口以进一步进行交互。 此方法将阻塞,直到提供的Atom返回结果。

Parameters
windowPicker Atom
Returns
WebInteraction<R>

perform

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

在当前上下文中执行提供的原子(Window和Element References的组合)。 该方法阻塞直到Atom返回。 Atom评估的结果用于创建WebInteraction的新实例,该实例可用于访问Atom评估的结果。

Parameters
atom Atom
Returns
WebInteraction<E>

reset

WebInteraction<R> reset ()

从此交互中移除元素和窗口引用。 当先前的操作(例如点击)引入使ElementReference和WindowReference指针无效的导航时,这通常是必需的。

Returns
WebInteraction<R>

withContextualElement

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

允许使用所选元素上下文评估此WebInteraction。 具体来说,elementPicker原子将使用当前选定的元素进行评估,以发现要应对的新元素。 这允许调用者与看起来像这样的文档进行交互:

 <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)

导致此WebInteraction在评估之前将给定的ElementReference提供给Atom。 调用此方法将重置以前选择的任何ElementReference。

Parameters
element ElementReference
Returns
WebInteraction<R>

也可以看看:

withElement

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

导致此WebInteraction在评估之前将给定的ElementReference提供给Atom。 这个方法接受一个Atom 它将在当前上下文的窗口上进行评估。 此方法会阻止,直到评估完成。 调用此方法将重置以前选择的任何ElementReference。 如果您想在之前选择的ElementReference的上下文中评估elementPicker

Parameters
elementPicker Atom
Returns
WebInteraction<R>

也可以看看:

withNoTimeout

WebInteraction<R> withNoTimeout ()

在此WebInteraction上禁用所有超时。 Javascript评估是在WebKit / Chromium线程上异步执行的。 默认情况下,我们等待一会儿,结果被传回测试。

Returns
WebInteraction<R>

withTimeout

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

为此WebInteraction设置特定的超时时间。

Parameters
amount long
unit TimeUnit
Returns
WebInteraction<R>