public IWebDriver StartBrowser(string DirPath = "", int Zoom = 100) { string URL = string.Empty; List <Models.URL> uRLs = new List <Models.URL>(); we = new WebElem(this); if (DirPath == "") { DirPath = Path.GetDirectoryName(typeof(Browser).Assembly.Location) + @"..\..\..\TestConfig\urls.json"; } using (StreamReader r = new StreamReader(DirPath)) { string json = r.ReadToEnd(); uRLs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.URL> >(json); } URL = uRLs.Where(i => i.environment.ToLower() == env.ToLower() && i.application.ToLower() == application.ToLower()).FirstOrDefault().url; we.Log(URL); driv = OpenBrowser(); driv.Navigate().GoToUrl(URL); // ((IJavaScriptExecutor)driv).ExecuteScript("document.body.style.zoom='" + Convert.ToString(Zoom) + "%';"); we = new WebElem(this); return(driv); }
string PostAsync(string _route, Dictionary <string, string> QueryParams, object _body) { string QueryString = string.Empty; int countr = 1; if (QueryParams.Count >= 1) { QueryString = "?"; foreach (var param in QueryParams) { if (countr == 1) { QueryString = QueryString + param.Key + "=" + param.Value; } else { QueryString = QueryString + "&" + param.Key + "=" + param.Value; } countr = countr++; } } string DATA = Newtonsoft.Json.JsonConvert.SerializeObject(_body); System.Net.Http.HttpContent content = new StringContent(DATA, UTF8Encoding.UTF8, "application/json"); HttpResponseMessage response = CLIENT.PostAsync(CLIENT.BaseAddress + _route + QueryString, content).Result; string description = string.Empty; try { string result = response.Content.ReadAsStringAsync().Result; description = result; } catch { webElem.Log(string.Format("There was an issue with the responce from a Post call to {0}", _route)); } return(description); }
private void TimedClickOnWebElement(Object source, System.Timers.ElapsedEventArgs e) { if (countr <= _clickSetting.MaxPollCount) { try { if (countr >= 5 && countr <= 10) { we.scroll(HH, _firstScroll); } else if (countr >= 10) { we.scroll(HH, _secondScroll); } HH.Click(); WasSuccessful = true; aTimer.Enabled = false; } catch { if (countr < 5) { we.scrollintoView(HH); } we.HighLight(HH, 1); countr++; we.Log(WebElem.loglevel.debug, string.Format("Can't click {0} on attempt number {1}", Convert.ToString(HH), Convert.ToString(countr))); } } else if (countr > _clickSetting.MaxPollCount) { WasSuccessful = false; aTimer.Enabled = false; } }