Android 从WebView中提取Cookie的Robotium测试
我的注册过程在WebView中生成cookie,而不是在本机代码中。我的所有测试都依赖于从Webview检索的cookies,因此我需要一种在Robotium测试中从Webview提取数据的方法。如何做到这一点?以下是我的WebView片段:Android 从WebView中提取Cookie的Robotium测试,android,robotium,Android,Robotium,我的注册过程在WebView中生成cookie,而不是在本机代码中。我的所有测试都依赖于从Webview检索的cookies,因此我需要一种在Robotium测试中从Webview提取数据的方法。如何做到这一点?以下是我的WebView片段: public class MyWebViewFragment extends Fragment { private CookieManager cookieManager; @ViewById WebView myWebVie
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测试,该测试将在正确的位置提取Cookies的值,并将其保存以供其他测试使用。我需要让它工作,否则我的其他测试都不会运行。谢谢我想你可能知道,看到你的其他问题后,简单的答案是抓住片段,然后询问片段的值。潜在地,您可能会考虑在测试中嘲笑此功能,或者允许您的测试方法能够为自身设置cookies(不确定这是否适用于您的案例)。