Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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 使用Robolectric而不是加载页面测试Activitys WebView_Android_Android Webview_Robolectric_Android Testing_Robolectric Gradle Plugin - Fatal编程技术网

Android 使用Robolectric而不是加载页面测试Activitys WebView

Android 使用Robolectric而不是加载页面测试Activitys WebView,android,android-webview,robolectric,android-testing,robolectric-gradle-plugin,Android,Android Webview,Robolectric,Android Testing,Robolectric Gradle Plugin,我正在尝试使用Robolectric测试WebView中的一些内容,但是没有数据进入 我在WebView上调用了以下内容 Robolectric.getFakeHttpLayer().interceptHttpRequests(false); Robolectric.getFakeHttpLayer().interceptResponseContent(true); 我也打电话给下面的人是为了尝试清除机器人世界里排队的任何东西。我必须这样做,以便我能完成其他一些事情 Robolectric.r

我正在尝试使用Robolectric测试
WebView
中的一些内容,但是没有数据进入

我在
WebView
上调用了以下内容

Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
Robolectric.getFakeHttpLayer().interceptResponseContent(true);
我也打电话给下面的人是为了尝试清除机器人世界里排队的任何东西。我必须这样做,以便我能完成其他一些事情

Robolectric.runBackgroundTasks();
Robolectric.runUiThreadTasks();
Robolectric.runUiThreadTasksIncludingDelayedTasks();
下面是加载url的代码

    WebView webView = new WebView(this);

    webView.getSettings().setUseWideViewPort(false);
    webView.getSettings().setSupportMultipleWindows(false);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAppCacheEnabled(false);
    webView.getSettings().setDomStorageEnabled(false);
    webView.getSettings().setLoadWithOverviewMode(true);

    webView.setInitialScale(1);

    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int newProgress) {
           super.onProgressChanged(view, newProgress);

           Log.d(TAG, newProgress + " URL: " + view.getUrl());//this never happens!
        }
    });

    webView.loadUrl("https://the-url.to/load");

    Log.d(TAG, "Loading: " + url);//i see this..

我非常喜欢Robolectric以及它如何解决模拟器开销问题,但我需要它与上面的WebView实现一起工作。有什么想法吗?

你会测试什么?也许检查loadurl是否使用预期url调用就足够了

看起来目前不可能有更多的。

我希望在DOM元素上注入click事件,然后验证行为。也许您可以使用额外的工具来测试web视图内容。我不太熟悉web测试,但发现hyyyy plz可以帮助我通过robolectric测试web视图。我无法从google找到任何代码。