class Program
{
public class SettingModel
{
public string Login { get; set; }
public string Password { get; set; }
public string Url { get; set; }
public string Assert { get; set; }
}
public static SettingModel ParseCommandLineArguments(string[] args)
{
var result = new SettingModel();
for( int n=0; n < args.Length; n++)
{
switch (args[n].ToLower())
{
case "-l":
result.Login = args[++n];
break;
case "-p":
result.Password = args[++n];
break;
case "-u":
result.Url = args[++n];
break;
case "-a":
result.Assert = args[++n];
break;
}
}
return result;
}
static void Main(string[] args)
{
var model = ParseCommandLineArguments(args);
Uri baseUri = new Uri(model.Url);
//HttpClientHandler handler = new HttpClientHandler();
//handler.CookieContainer = new CookieContainer();
//HttpClient client = new HttpClient(handler);
using (HttpClient client = new HttpClient())
{
var getRequest = client.GetAsync(baseUri);
getRequest.Wait();
HttpResponseMessage response = getRequest.Result;
//CookieCollection collection = handler.CookieContainer.GetCookies(uri); // Retrieving a Cookie
var htmlPage = response.Content.ReadAsStringAsync();
htmlPage.Wait();
var html = htmlPage.Result;
var reg = Regex.Match(html, "<input name=\"__RequestVerificationToken\" type=\"hidden\" value=\"(.*)\" />");
if (reg.Success)
{
var regexGroups = reg.Groups;
var formVariables = new List<KeyValuePair<string, string>>();
formVariables.Add(new KeyValuePair<string, string>("login", model.Login));
formVariables.Add(new KeyValuePair<string, string>("password", model.Password));
formVariables.Add(new KeyValuePair<string, string>("__RequestVerificationToken", regexGroups[1].Value));
var loginFormData = new FormUrlEncodedContent(formVariables);
var postRequest = client.PostAsync(baseUri, loginFormData);
postRequest.Wait();
var postResult = postRequest.Result;
var dashboardHtmlPage = postResult.Content.ReadAsStringAsync();
htmlPage.Wait();
var htmlToAssert = dashboardHtmlPage.Result;
Assert(model.Assert, htmlToAssert);
}
}
}
private static void Assert(string assertString, string htmlToAssert)
{
if (htmlToAssert.Contains(assertString)) // "/KlientskaZona/ProfilSpolecnosti/ProfilSpolecnosti"))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed");
}
}
}
středa 17. června 2020
Test přihlášení ASP stránky
Přihlásit se k odběru:
Komentáře k příspěvku (Atom)
Žádné komentáře:
Okomentovat