Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android测试-确定WebView是否缩放-收缩缩放_Android_Webview_Robotium_Android Testing_Pinchzoom - Fatal编程技术网

Android测试-确定WebView是否缩放-收缩缩放

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

我一直在互联网上徘徊,试图找到如何使这项工作。 我有一个应用程序,允许用户禁用网络视图上的收缩缩放。它实际上可以工作,但我不能测试它…(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.

我不知道如何查看用户是否可以缩放屏幕。有什么想法吗?

我不知道这是否是最好的方法,但我会回答我自己的问题,因为这很有效

我没有选择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));
}