我是Espresso的新手。我想知道是否有办法验证hybird应用程序中的webview元素。例如:有一个按钮,点击一个html页面后显示,如何验证内容(比如购物页面,以及要验证的是显示价格)。如何将所有这些步骤仅用于一个测试用例?非常感谢。
以下是我尝试但失败的内容:
代码:
public class EspressoTest {
@Rule
public IntentsTestRule<MainActivity> mActivityRule =
new IntentsTestRule<>(MainActivity.class);
@Test
public void testMembershipCenter(){
//click user profile button to access shopping center
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
onView(withId(R.id.tv_main_username)).perform(click());
onView(withId(R.id.tv_vip)).perform(click());
//actually, I can see the shopping center is showing up on the real device
onWebView().forceJavascriptEnabled();
onWebView().withElement(findElement(Locator.XPATH,"//span[@class='orginal']")).check(webMatches(getText(),containsString("10")));
onView(withId(R.id.ivBack)).perform(click());
Log.i("taggggg","AAAA");
}
}
错误:
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed.''. Check device logcat for details
Test running failed: Instrumentation run failed due to 'Process crashed.'
官员https://developer.android.com/training/testing/espresso/web.html只显示纯webview示例吗?或者我误会了。
希望有人能给我看一些示例代码,再次感谢。)