我的注册过程在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的值,并将其保存以供其他测试使用。我需要让它发挥作用,否则我的其他测试都无法运行。感谢
我想你在看到其他问题后可能知道的简单答案是抓住片段,然后向片段询问值。您可能会考虑在测试中模拟此功能,或者允许您的测试使用一种能够为自己设置cookie的方法等(不确定这是否适用于您的情况)