简体   繁体   中英

Robotium Test to Extract Cookies from WebView

My Sign Up Process produces cookies in a WebView, not in native code. All my tests depend on the cookies retrieved from the Webview so I need a way to extract data from a webview inside a Robotium test. How can this be done? Here is my WebView fragment:

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?

            }


             }
  }

}

I need to know how to write a Robotium test that will at the right point pull out the values of the Cookies and save it for the rest of the tests to use. I need to get thiw working or none of my other tests will run. Thanks

The simple answer as i think you may know having seen your other questions is to get hold of the fragment and then ask the fragment for the value. Potentially you might consider mocking this functionality out for your tests or allow your tests a method to be able to set the cookies for itself etc (not sure if this is feasible for your case or not.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM