public void login() { browser = new IE(); browser.ClearCache(); browser.ClearCookies(); Utils.GoTo(browser, "http://www.tribalwars.net/sv-se/page/logout"); Utils.GoTo(browser, "http://www.tribalwars.net"); //browser.Body.Focus(); browser.TextField(Find.ById("user")).TypeText(username); browser.TextField(Find.ById("password")).TypeText(password); System.Console.WriteLine("Clicking login."); browser.Link(Find.ByClass("btn-login")).Click(); System.Console.WriteLine("Waiting"); Div wContainer = browser.Div(Find.ByClass("worlds-container")); wContainer.WaitUntilExists(); System.Console.WriteLine("Going to world"); Utils.GoTo(browser, "http://www.tribalwars.net/sv-se/page/play/" + world); System.Console.WriteLine("Logged in"); while (browser.Html == null) { System.Threading.Thread.Sleep(100); } Utils.CheckBotProtection(browser.Html); isLoggedIn = true; // Give browser object to villages. foreach (Village village in villages) { village.SetBrowser(ref browser); village.SetWorld(world); } }
private void frmWebBowser_Load(object sender, EventArgs e) { Settings.WaitForCompleteTimeOut = 120000; Settings.AttachToBrowserTimeOut = 120000; webBrowser1.ScriptErrorsSuppressed = false; Settings.AutoStartDialogWatcher = false; ie = new IE(webBrowser1.ActiveXInstance); try { ie.ClearCache(); } catch { } //ie = new IE(); dialogWatcher = new DialogWatcher(new Window(this.Handle)); dialogWatcher.CloseUnhandledDialogs = false; webpage = new WebPage(); lookUpEditPage.Properties.DataSource = WebPage.GetAll(); lookUpEditPage.Properties.DisplayMember = "Page"; lookUpEditPage.Properties.ValueMember = "ID"; if (pageID > 0) { lookUpEditPage.EditValue = long.Parse(pageID.ToString()); } }
public void TearDownTest() { browser.ClearCookies(rootUrl); browser.ClearCache(); browser.Close(); browser.Dispose(); browser = null; }
void Close() { ie.ClearCache(); ie.ClearCookies(); ie.Close(); ie.Dispose(); complete(); }
public void SetUp() { ie = new IE(); ie.Refresh(); ie.ClearCache(); Settings.WaitForCompleteTimeOut = 240; // to hide IE window // ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide); }
private void initialize() { data = new Data(); ie = new IE(); ie.ClearCookies(); ie.ClearCache(); ie.WaitForComplete(); ie.Visible = data.BrowserVisible; accountRegistrationUrl = getOpenAccountUrl(); navigateToRegistrationPage(); fillAccountForm(); }
/// <summary> /// Default constructor. /// </summary> /// <param name="maxWaitInMs">The maximum number of milliseconds before the tests should timeout after page load; -1 for infinity, 0 to not support asynchronous tests</param> public QUnitParser(int maxWaitInMs) { _maxWaitInMs = maxWaitInMs < 0 ? Int32.MaxValue : maxWaitInMs; _ie = new IE(); if (NQUnit.HideBrowserWindow) { _ie.ShowWindow(NativeMethods.WindowShowStyle.Hide); } if (NQUnit.ClearCacheBeforeRunningTests) { _ie.ClearCache(); } }
void Open() { try { ie = new IE(); ie.ShowWindow(NativeMethods.WindowShowStyle.Hide); ie.ClearCache(); ie.ClearCookies(); } catch { } //ie.ShowWindow(NativeMethods.WindowShowStyle.Hide); }
public LambdAssert GoToUrlInFreshBrowser(string url) { using (IE ie = WebBrowser as IE) { ie.ClearCookies(); ie.ClearCache(); ie.Close(); } WebBrowser.Reopen(); WebBrowser.GoTo(url); WebBrowser.WaitForComplete(); return(LambdAssert); }
private void navigateToUrl(string url) { while (true) { ie.ClearCache(); ie.ClearCookies(); ie.GoTo(url); Thread.Sleep(6000); ie.WaitForComplete(); if (ie.Url == url) { break; } } }
public void ClearCache() { using (var ie = new IE(GoogleUrl)) { // Testing cache clearing directly is a little difficult because we cannot // easily enumerate its contents without using system APIs. // We could create a sample page that includes a nonce but says it's cacheable // forever. Then we should only observe the change on refresh or cache clearing. // Fortunately Google has already done it for us. // Save the original page html. var oldHtml = GetHtmlSource(ie); // If we navigate to the page again, we should see identical Html. ie.GoTo(GoogleUrl); Assert.AreEqual(oldHtml, GetHtmlSource(ie), "HTML should be identical when pulling from the cache."); // But after clearing the cache, things are different. ie.ClearCache(); ie.GoTo(GoogleUrl); Assert.AreNotEqual(oldHtml, GetHtmlSource(ie), "HTML should differ after cache has been cleared."); } }
/// <summary> /// Method to clear the cache of a browser /// will clear cache of IE or FireFox browser /// </summary> /// <param name="browser"></param> /// <param name="browsertype">IE or FireFox</param> public void ClearCache(Browser browser, string browsertype) { switch (browsertype) { case "IE": IE ie = (IE)browser; ie.ClearCache(); ie.ClearCookies(); break; case "FireFox": FireFox ff = (FireFox)browser; Console.Write("Unsure how to clear cache in FireFox"); ff.Refresh(); break; } }
public static void RenewAdsProcessByEmailAccount(int computerId) { var totalrenewList = SQLHelper.PopulateEmailHavingRenewAds(computerId); foreach (var eAccount in totalrenewList) { if (_browser != null && IsAlreadyLogin()) { System.Threading.Thread.Sleep(2000); _browser.Span(Find.ById("ef")).Links.First().Click(); System.Threading.Thread.Sleep(6000); _browser.ClearCache(); _browser.ClearCookies(); } var ieProcesses = Process.GetProcessesByName("iexplore"); if (ieProcesses.Any()) { foreach (Process ie in ieProcesses) { ie.Kill(); } } System.Threading.Thread.Sleep(2000); //var networkManagement = new NetworkManagement(); //networkManagement.SetIP(eAccount); System.Threading.Thread.Sleep(8000); try { if (_browser == null) { _browser = new IE("https://accounts.craigslist.org/"); } else { _browser.GoTo("https://accounts.craigslist.org/"); } _browser.ShowWindow(NativeMethods.WindowShowStyle.ShowMaximized); System.Threading.Thread.Sleep(2000); _browser.TextField(Find.ByName("inputEmailHandle")).TypeText(eAccount.CraigslistAccount); _browser.TextField(Find.ByName("inputPassword")).TypeText(eAccount.CraigsListPassword); System.Threading.Thread.Sleep(2000); _browser.Buttons.First().Click(); int numberofPages = 1; int numberofFilterpage = 0; foreach (var tmp in _browser.Links) { if (!String.IsNullOrEmpty(tmp.Url) && tmp.Url.Contains("filter_page")) { numberofFilterpage++; } } numberofPages = numberofPages + numberofFilterpage / 2; if (numberofPages > 0) { for (int i = 1; i <= numberofPages; i++) { if (i == 1) { var allDeleteTab = _browser.TableCells.ToArray(); var listofDeleted = new List <long>(); foreach (var deleteTmp in allDeleteTab) { if (!String.IsNullOrEmpty(deleteTmp.GetAttributeValue("style")) && deleteTmp.GetAttributeValue("style").Contains("border: 1px solid pink") && !String.IsNullOrEmpty(deleteTmp.Text)) { long clpostingId = 0; Int64.TryParse(deleteTmp.Text, out clpostingId); if (clpostingId > 0) { listofDeleted.Add(clpostingId); } } } System.Threading.Thread.Sleep(2000); if (_browser.Buttons.Any(x => x.Value == "renew")) { do { var tmp = _browser.Buttons.First(x => x.Value == "renew"); System.Threading.Thread.Sleep(3000); tmp.Click(); var clPostingIdString = _browser.Url.Substring( _browser.Url.LastIndexOf("/", System.StringComparison.Ordinal) + 1); long clPostingId = 0; Int64.TryParse(clPostingIdString, out clPostingId); if (clPostingId > 0) { SQLHelper.ShowAdsButEligibleForRenewFromClAccountManagement( clPostingId); } System.Threading.Thread.Sleep(8000); _browser.GoTo("https://accounts.craigslist.org/"); System.Threading.Thread.Sleep(3000); } while (_browser.Buttons.Any(x => x.Value == "renew")); } } else { _browser.GoTo("https://accounts.craigslist.org/?filter_page=" + i + "&filter_cat=0&filter_date=0&filter_active=0&show_tab=postings"); var allDeleteTab = _browser.TableCells.ToArray(); var listofDeleted = new List <long>(); foreach (var deleteTmp in allDeleteTab) { if (!String.IsNullOrEmpty(deleteTmp.GetAttributeValue("style")) && deleteTmp.GetAttributeValue("style").Contains("border: 1px solid pink") && !String.IsNullOrEmpty(deleteTmp.Text)) { long clpostingId = 0; Int64.TryParse(deleteTmp.Text, out clpostingId); if (clpostingId > 0) { listofDeleted.Add(clpostingId); } } } SQLHelper.PinkAdInClAccountManagement( listofDeleted); System.Threading.Thread.Sleep(2000); if (_browser.Buttons.Any(x => x.Value == "renew")) { do { var tmp = _browser.Buttons.First(x => x.Value == "renew"); System.Threading.Thread.Sleep(3000); tmp.Click(); var clPostingIdString = _browser.Url.Substring( _browser.Url.LastIndexOf("/", System.StringComparison.Ordinal) + 1); long clPostingId = 0; Int64.TryParse(clPostingIdString, out clPostingId); if (clPostingId > 0) { SQLHelper.ShowAdsButEligibleForRenewFromClAccountManagement( clPostingId); } System.Threading.Thread.Sleep(8000); _browser.GoTo("https://accounts.craigslist.org/?filter_page=" + i + "&filter_cat=0&filter_date=0&filter_active=0&show_tab=postings"); System.Threading.Thread.Sleep(3000); } while (_browser.Buttons.Any(x => x.Value == "renew")); } } } } } catch (Exception ex) { if (_browser != null) { _browser.ClearCache(); _browser.ClearCookies(); _browser = new IE("https://accounts.craigslist.org/"); } else { _browser.GoTo("https://accounts.craigslist.org/"); } throw new Exception(ex.Message); System.Threading.Thread.Sleep(2000); } } }
public void SetUpTest() { browser = new IE(rootUrl); browser.ClearCookies(rootUrl); browser.ClearCache(); }
private void CraigslistLogin(int trackingId) { if (_browser == null) { _browser = new IE("https://accounts.craigslist.org/"); } else { _browser.ClearCache(); _browser.Close(); _browser = null; _browser = new IE("https://accounts.craigslist.org/"); } _browser.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized); if (IsAlreadyLogin()) { System.Threading.Thread.Sleep(2000); _browser.Span(Find.ById("ef")).Links.First().Click(); System.Threading.Thread.Sleep(3000); } System.Threading.Thread.Sleep(2000); var trackingads = DataHelper.GetAds(trackingId); if (trackingads != null) { var emailAccount = DataHelper.GetEmail(trackingads.EmailAccount); if (emailAccount != null) { _browser.TextField(Find.ByName("inputEmailHandle")).Value = emailAccount.Email; _browser.TextField(Find.ByName("inputPassword")).Value = emailAccount.Password; System.Threading.Thread.Sleep(2000); _browser.Buttons.First().Click(); System.Threading.Thread.Sleep(2000); _browser.GoTo("https://post.craigslist.org/manage/" + trackingads.CLPostingId); System.Threading.Thread.Sleep(1000); if (_browser.Buttons.Any(x => x.Value == "Edit this Posting")) { _browser.Button(Find.ByValue("Edit this Posting")).Click(); System.Threading.Thread.Sleep(1000); _browser.TextField(Find.ById("Ask")).Value = GlobalVar.CurrentDealer.Inventory.FirstOrDefault(x => x.ListingId == trackingads.ListingId) .SalePrice.ToString(CultureInfo.InvariantCulture); System.Threading.Thread.Sleep(1000); _browser.Button(Find.ByValue("Continue")).Click(); System.Threading.Thread.Sleep(1000); _browser.Button(Find.ByValue("Continue")).Click(); System.Threading.Thread.Sleep(1000); _browser.Button(Find.ByValue("Done with Images")).Click(); System.Threading.Thread.Sleep(1000); _browser.Button(Find.ByValue("Continue")).Click(); } else { MessageBox.Show( "This ads is not eligible for editing.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show( "Email account associated with this ad no longer exist in CLDMS system", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
public void ClearCache() { using (var ie = new IE(GoogleUrl)) { // Testing cache clearing directly is a little difficult because we cannot // easily enumerate its contents without using system APIs. // We could create a sample page that includes a nonce but says it's cacheable // forever. Then we should only observe the change on refresh or cache clearing. // Fortunately Google has already done it for us. // Save the original page html. var oldHtml = GetHtmlSource(ie); // If we navigate to the page again, we should see identical Html. ie.GoTo(GoogleUrl); Assert.AreEqual(oldHtml, GetHtmlSource(ie), "HTML should be identical when pulling from the cache."); // But after clearing the cache, things are different. ie.ClearCache(); ie.GoTo(GoogleUrl); Assert.AreNotEqual(oldHtml, GetHtmlSource(ie), "HTML should differ after cache has been cleared."); } }
public static void ReportProcessRenew() { CloseInternetExplorers(); var totaltodayReportList = MySqlHelper.PopulateTodayRenewAdsForReport(); ServiceLog.CraigslistErrorLog("*****************************************NUMBEROFADTORUN = " + totaltodayReportList.Count + "*******************************************"); int showedAds = 0; int flagedAds = 0; foreach (var vehicle in totaltodayReportList) { try { if (_browser == null) { _browser = new IE(vehicle.CraigslistUrl); } else { _browser.GoToNoWait(vehicle.CraigslistUrl); } _browser.ShowWindow(NativeMethods.WindowShowStyle.Hide); System.Threading.Thread.Sleep(1000); if (_browser.Html.Contains("This posting has been flagged for removal")) { MySqlHelper.NonShowAds(vehicle.AdTrackingId); ServiceLog.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == FLAGGED"); flagedAds++; } else { MySqlHelper.ShowAds(vehicle.AdTrackingId); ServiceLog.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == SHOWED"); showedAds++; } System.Threading.Thread.Sleep(200); } catch (Exception ex) { ServiceLog.CraigslistErrorLog(ex.Message); } } if (_browser != null) { _browser.ClearCache(); _browser.ClearCookies(); _browser.Close(); _browser = null; } var percentage = Math.Ceiling(((double)showedAds / totaltodayReportList.Count()) * 100); var builder = new StringBuilder(); builder.Append("NUMBER OF RENEW ADS TODAY = <b>" + totaltodayReportList.Count + "....."); builder.Append("NUMBER OF RENEW ADS SHOWED = " + showedAds + "....."); builder.Append("NUMBER OF RENEW ADS FLAGGED = " + flagedAds + "...."); builder.Append("PERCENTAGE = <b>" + percentage.ToString(CultureInfo.InvariantCulture) + "%" + "......."); SmsHelper.SendMessageToAtt("Craigslist Report", builder.ToString()); ServiceLog.CraigslistErrorLog("*****************************************SHOWED = " + showedAds + "*******************************************"); ServiceLog.CraigslistErrorLog("*****************************************FLAGGED = " + flagedAds + "*******************************************"); ServiceLog.CraigslistErrorLog("*****************************************DONE*******************************************"); }
public static void RenewAdsProcess(int splitPart) { var totalrenewList = MySqlHelper.PopulateAvailableRenewAds(); var renewList = totalrenewList.Skip(totalrenewList.Count * splitPart / 2).Take(totalrenewList.Count / 2).ToList(); var ieProcesses = Process.GetProcessesByName("iexplore"); if (ieProcesses.Any() && ieProcesses.Count() > 5) { foreach (Process ie in ieProcesses) { ie.Kill(); } } if (_browser != null) { _browser.ClearCache(); _browser.ClearCookies(); _browser.Close(); _browser = null; } if (_browser != null && IsAlreadyLogin()) { System.Threading.Thread.Sleep(2000); _browser.Span(Find.ById("ef")).Links.First().Click(); System.Threading.Thread.Sleep(3000); } foreach (var vehicle in renewList) { try { if (_browser == null) { _browser = new IE(vehicle.CraigslistCityUrl + "search/ctd?zoomToPosting=&query=" + vehicle.CLPostingId + "&srchType=A&minAsk=&maxAsk="); } else { _browser.GoToNoWait(vehicle.CraigslistCityUrl + "search/ctd?zoomToPosting=&query=" + vehicle.CLPostingId + "&srchType=A&minAsk=&maxAsk="); } _browser.ShowWindow(NativeMethods.WindowShowStyle.ShowMaximized); System.Threading.Thread.Sleep(2000); if (_browser.Html.Contains("Found: ")) { if (vehicle.AutoID == 1 || (renewList.Any(x => x.AutoID == vehicle.AutoID - 1) && !renewList.First(x => x.AutoID == vehicle.AutoID - 1).CraigslistAccountName.Equals(vehicle.CraigslistAccountName))) { if (_browser == null) { _browser = new IE("https://accounts.craigslist.org/"); } else { _browser.GoTo("https://accounts.craigslist.org/"); } if (_browser != null && IsAlreadyLogin()) { System.Threading.Thread.Sleep(2000); _browser.Span(Find.ById("ef")).Links.First().Click(); System.Threading.Thread.Sleep(3000); _browser.ClearCache(); _browser.ClearCookies(); _browser.Close(); _browser = null; } if (_browser == null) { _browser = new IE("https://accounts.craigslist.org/"); } else { _browser.GoTo("https://accounts.craigslist.org/"); } _browser.TextField(Find.ByName("inputEmailHandle")).TypeText(vehicle.CraigslistAccountName); _browser.TextField(Find.ByName("inputPassword")).TypeText(vehicle.CraigslistAccountPassword); System.Threading.Thread.Sleep(2000); _browser.Buttons.First().Click(); } else { if (_browser != null) { _browser.GoTo("https://accounts.craigslist.org/"); } else { _browser = new IE("https://accounts.craigslist.org/"); } if (!IsAlreadyLogin()) { _browser.ClearCache(); _browser.ClearCookies(); _browser.Close(); _browser = null; _browser = new IE("https://accounts.craigslist.org/"); _browser.TextField(Find.ByName("inputEmailHandle")).TypeText(vehicle.CraigslistAccountName); _browser.TextField(Find.ByName("inputPassword")).TypeText(vehicle.CraigslistAccountPassword); System.Threading.Thread.Sleep(2000); _browser.Buttons.First().Click(); } } System.Threading.Thread.Sleep(2000); _browser.GoTo("https://post.craigslist.org/manage/" + vehicle.CLPostingId); if (_browser.Buttons.Any(x => x.Value == "Renew this Posting")) { System.Threading.Thread.Sleep(1000); _browser.Button(Find.ByValue("Renew this Posting")).ClickNoWait(); System.Threading.Thread.Sleep(4000); MySqlHelper.ShowAdsButEligibleForRenew(vehicle.AdTrackingId); //ServiceLog.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == RENEWED"); } else { MySqlHelper.ShowAdsButIneligibleForRenew(vehicle.AdTrackingId); _browser.GoTo("https://accounts.craigslist.org/"); System.Threading.Thread.Sleep(2000); _browser.Span(Find.ById("ef")).Links.First().Click(); System.Threading.Thread.Sleep(3000); _browser.ClearCache(); _browser.ClearCookies(); _browser.Close(); _browser = null; //.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == NOT ELIGIBLE TO RENEW"); } } else { MySqlHelper.DeleteTracking(vehicle.AdTrackingId); } System.Threading.Thread.Sleep(10000); } catch (Exception ex) { //throw new Exception(ex.Message); } } }
/// <summary> /// Performs authentication. /// </summary> private void EnsureAuth() { if (this.session != null && !this.session.Expired) { return; } try { using (var browser = new IE()) { var timer = new System.Diagnostics.Stopwatch(); timer.Start(); browser.AutoClose = true; browser.GoTo(this.AuthUrl); // Do autologin if needed. if (this.AutoLogin && !browser.Url.ToLowerInvariant().Contains("access_token=") && !browser.Url.ToLowerInvariant().Contains("error=")) { // Fill email password. if (browser.TextField(Find.ByName("email")).Exists&& browser.TextField(Find.ByName("pass")).Exists) { browser.TextField(Find.ByName("email")).Value = this.userEmail; browser.TextField(Find.ByName("pass")).Value = this.userPassword; browser.Button("install_allow").Click(); } // Accept application permissions. if (browser.Button("install_allow").Exists) { browser.Button("install_allow").Click(); } if (!browser.Url.ToLowerInvariant().Contains("access_token=") && !browser.Url.ToLowerInvariant().Contains("error=")) { throw new AuthenticationException("Most likely wrong email\\password."); } } // Wait for user to login. if (!this.AutoLogin) { while (!browser.Url.ToLowerInvariant().Contains("access_token=")) { System.Threading.Thread.Sleep(3000); } } if (browser.Url.ToLowerInvariant().Contains("error=")) { var error = Regex.Match(browser.Url, "error=(?<error>[^&$]*)", RegexOptions.IgnoreCase).Groups["error"].Value; var desc = Regex.Match(browser.Url, "error_description=(?<desc>[^&$]*)", RegexOptions.IgnoreCase).Groups["desc"].Value; throw new AuthenticationException( string.Format( "Error: {0}\nDescription: {1}", HttpUtility.UrlDecode(error), HttpUtility.UrlDecode(desc))); } // Create auth session. var token = Regex.Match(browser.Url, "access_token=(?<token>[^&$]*)", RegexOptions.IgnoreCase).Groups["token"].Value; var expires = int.Parse(Regex.Match(browser.Url, "expires_in=(?<expires>\\d+)", RegexOptions.IgnoreCase).Groups["expires"].Value); var uid = uint.Parse(Regex.Match(browser.Url, "user_id=(?<uid>\\d+)", RegexOptions.IgnoreCase).Groups["uid"].Value); timer.Stop(); this.session = new AuthSession(uid, token, expires - (int)timer.Elapsed.TotalSeconds); // Clears IE cache, all cookies (!) and kills IE process. Weird, I know :) browser.ClearCache(); browser.ClearCookies(); browser.ForceClose(); } } catch (AuthenticationException) { // WTF?! Browser closed? Wrong auth url?! throw; } catch (Exception ex) { throw new InvalidOperationException("Authentication failed.", ex); } }