我一直在网上闲逛,试图找出如何使这项工作。 我有一个应用程序,允许用户在webview上禁用缩放缩放。它确实有效,但我无法测试......(API 15)
我做了:
...
import com.robotium.solo.By;
public class MainActivityTest {
public MainActivityTest() {
super(MainActivity.class);
}
...
public void test_is_user_scalable() {
getActivity();
assertTrue(mSolo.waitForText("On Fake Page 1"));
WebView webview = (WebView) getActivity().findViewById(R.id.activity_main_webview);
assertFalse(webview.canZoomOut());
mSolo.pinchToZoom(new PointF(500, 500), new PointF(600, 600), new PointF(200, 200), new PointF(700, 700));
assertTrue(webview.canZoomOut());
}
}
即使我将测试的第三行改为这一行:
WebView webview = (WebView) mSolo.getView(R.id.activity_main_webview);
我仍然收到错误:
java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'Instr: android.test.InstrumentationTestRunner'. All WebView methods must be called on the same thread.
我无法弄清楚如何查看用户是否可以捏缩放屏幕。有什么想法吗?
答案 0 :(得分:0)
我不知道这是不是最好的方法,但我会回答我自己的问题,因为这很有效。
我没有选择网页视图并试图与之互动,而是直接进入视图并尝试向上,向下和向侧面滚动。只有当视图被缩放时才有可能:
public void test_user_scalable() {
getActivity();
assertTrue(mSolo.waitForText("On Fake Page 1"));
View webview = getActivity().findViewById(R.id.activity_main_webview);
assertFalse(webview.canScrollVertically(-1));
assertFalse(webview.canScrollVertically(1));
assertFalse(webview.canScrollHorizontally(-1));
assertFalse(webview.canScrollHorizontally(1));
mSolo.pinchToZoom(new PointF(500, 500), new PointF(600, 600), new PointF(200, 200), new PointF(700, 700));
assertTrue(webview.canScrollVertically(-1));
assertTrue(webview.canScrollVertically(1));
assertTrue(webview.canScrollHorizontally(-1));
assertTrue(webview.canScrollHorizontally(1));
}