0

我的注册过程在 WebView 中生成 cookie,而不是在本机代码中。我所有的测试都依赖于从 Webview 检索到的 cookie,所以我需要一种从 Robotium 测试中的 webview 中提取数据的方法。如何才能做到这一点?这是我的 WebView 片段:

public class MyWebViewFragment extends Fragment {


    private CookieManager cookieManager;

    @ViewById
    WebView myWebView;

        @AfterViews
        void theAfterViews() {

             myWebView.getSettings().setJavaScriptEnabled(true);
             myWebView.getSettings().setDomStorageEnabled(true);

             CookieSyncManager.createInstance(getActivity());
             cookieManager = CookieManager.getInstance();

             myWebView.loadUrl(theURL);

             myWebView.setWebViewClient(new WebViewClient() 
             {
             public void onPageStarted(WebView view, String url, Bitmap favicon) {

            if ((url != null) && (url.equals(theURL)))
            {
                String theCookies = cookieManager.getCookie(url);
                            // ######## I need to pull these Cookies out here in the Robotium test. How do I use Solo etc to do this?

            }


             }
  }

}

我需要知道如何编写一个 Robotium 测试,该测试将在正确的位置提取 Cookie 的值并将其保存以供其余测试使用。我需要让 thiw 工作,否则我的其他测试都不会运行。谢谢

4

1 回答 1

0

我认为您可能知道看到其他问题的简单答案是获取片段,然后向片段询问值。您可能会考虑为您的测试模拟此功能,或者允许您的测试使用一种能够为自己设置 cookie 的方法等(不确定这对您的情况是否可行。)

于 2013-09-27T13:43:30.427 回答