我的测试站点显示一个弹出框以输入用户凭据。我可以使用
登录该网站private CredentialCache GetCredential(LoginData loginData)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new System.Uri(loginData.LoginURL), "Basic", new NetworkCredential(loginData.LoginUserName, loginData.LoginPwd));
return credentialCache;
}
//above code is thanks to another post on SO
public void SiteLogin(LoginData loginData)
{
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = WebRequest.Create(loginData.LoginURL) as HttpWebRequest;
request.CookieContainer = cookieContainer;
request.Method = WebRequestMethods.Http.Post;
request.KeepAlive = false;
request.ContentLength = 0;
request.Credentials = GetCredential(loginData);
request.PreAuthenticate = true;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
string testString = reader.ReadToEnd(); //see what response is here, only for initial coding
}
我无法访问测试网站,所以我不知道控件的名称是什么,用于登录弹出窗口。
我如何使用watin执行类似的步骤?