Android测试-确定WebView是否缩放-收缩缩放
我一直在互联网上徘徊,试图找到如何使这项工作。 我有一个应用程序,允许用户禁用网络视图上的收缩缩放。它实际上可以工作,但我不能测试它…(API 15) 我做到了:Android测试-确定WebView是否缩放-收缩缩放,android,webview,robotium,android-testing,pinchzoom,Android,Webview,Robotium,Android Testing,Pinchzoom,我一直在互联网上徘徊,试图找到如何使这项工作。 我有一个应用程序,允许用户禁用网络视图上的收缩缩放。它实际上可以工作,但我不能测试它…(API 15) 我做到了: ... import com.robotium.solo.By; public class MainActivityTest { public MainActivityTest() { super(MainActivity.class); } ... public void test
...
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.
我不知道如何查看用户是否可以缩放屏幕。有什么想法吗?我不知道这是否是最好的方法,但我会回答我自己的问题,因为这很有效 我没有选择webview并尝试与之交互,而是直接进入该视图并尝试向上、向下和侧向滚动。仅当视图被缩放时才可能:
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));
}