我的注册过程在 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 工作,否则我的其他测试都不会运行。谢谢