public void TestTileRendered() { _ie.GoTo(_webServer.BaseUrl + "default.aspx"); Assert.That(_ie.Url.EndsWith("default.aspx"), "Should open with default.aspx"); Assert.That(_ie.Element(Find.ById("paragraph1")).InnerHtml, Is.EqualTo("This is a paragraph")); Assert.That(_ie.Element(Find.ById("paragraph2")).InnerHtml, Is.EqualTo("Some text")); }
private void LogIn(IE browser) { if (browser.Links.Count(link => link.Title == "Log back into your account") > 0) { // Just been logged out. Need to press the above link browser.Link(Find.ByTitle("Log back into your account")).Click(); } else { browser.Link(Find.ByTitle("Sign in ")).Click(); } if (browser.Links.Count(link => link.Title == "Log back into your account") > 0) { // Just been logged out. Need to press the above link browser.Link(Find.ByTitle("Log back into your account")).Click(); } browser.TextField(Find.ById("frmLogin:strCustomerLogin_userID")).Value = Config.UserId; browser.TextField(Find.ById("frmLogin:strCustomerLogin_pwd")).Value = Config.Password; browser.Form(Find.ByName("frmLogin")).Submit(); LloydsGroupHelpers.FillLloydsGroupMemorableInformation(browser, Config); browser.Element(Find.ByName("frmentermemorableinformation1:btnContinue")).Click(); }
private void LogIn(IE browser) { browser.TextField(Find.ById("userid1")).Value = Config.Username; browser.Button(Find.ByTitle("Sign in")).Click(); FillInPasswordCharacters(browser); browser.TextField(Find.ById("memorableAnswer")).Value = Config.SecretAnswer; browser.Element(Find.ByTitle("Continue")).Click(); }
private void Start(ref Exception exception, ref string output, string term) { IE browser = null; try { browser = IEBrowserHelper.GetBrowser(); browser.GoTo("https://www.google.com.br/"); browser.WaitForComplete(); TextField txtSearch = browser.TextField(Find.ByName("q")); if (txtSearch.Exists) { txtSearch.SetAttributeValue("value", term); } Element btnFind = browser.Element(Find.ByName("btnK")); if (btnFind.Exists) { btnFind.Click(); } var resultadosComplementares = browser.Div(Find.ByClass(p => p.Contains("kno-ecr-pt kno-fb-ctx"))); if (resultadosComplementares.Exists) { output = resultadosComplementares.OuterText; var resultadosComplementaresDescricao = browser.Div(Find.ByClass(p => p.Contains("kno-rdesc"))); if (resultadosComplementaresDescricao.Exists) { output += ": " + resultadosComplementaresDescricao.Spans[0].OuterText.Replace("\r\n", string.Empty); } } else { output = "O termo de busca não resultou em algo com a area de Resultados complementares"; } } catch (Exception e) { exception = e; } finally { //Close the browser if (browser != null) { browser.Close(); browser.Dispose(); } } }
/// <summary> /// Determines whether [has cool status]. /// </summary> /// <returns> /// <c>true</c> if [has cool status]; otherwise, <c>false</c>. /// </returns> public bool?HasCoolStatus() { if (!OpenUrl(UrlKormushka)) { return(null); } var cell = browser.Element(Find.ByClass("text_main_1")).Text; return(cell != "Премиум не активирован"); }
public void Test1() { _driver.NativeBrowser.NavigateTo(_uri); WaitUntilDriverIsFree(); _driver.TextField(Find.BySelector(SEARCH_FIELD_CSS)).TypeText("xpath"); WaitUntilDriverIsFree(); _driver.Element(Find.BySelector(SEARCH_BUTTON_CSS)).Click(); WaitUntilDriverIsFree(); _driver.Element(Find.BySelector(WIKI_RESULT_CSS)).Click(); WaitUntilDriverIsFree(); var allContextElements = _driver.Links.Filter(Find.BySelector(CONTEXT_LIST_CSS)); var contextListLength = allContextElements.Count; Assert.IsTrue(contextListLength == 36, $"Number of elements in context should be 36, but it is {contextListLength}"); }
/// <summary> /// This method returns the inner HTML of the HTML tag. /// </summary> /// <param name="selector">The selector to find the HTML tag.</param> /// <returns>A string containing the result.</returns> public string ReturnInnerHtml(string selector) { string result = string.Empty; var field = _browser.Element(Find.BySelector(selector)); if (field != null) { result = field.InnerHtml ?? string.Empty; } return(result); }
private void FillSecurityNumber(IE browser) { var securityDropdownsDiv = browser.Div(Find.ById("security-dropdowns")); var numbersRequestedAsStrings = securityDropdownsDiv.Paras.Select(p => p.Text); var numbersRequestedAsInts = numbersRequestedAsStrings.Select(str => int.Parse(Regex.Match(str, @"\d+").Value)); numbersRequestedAsInts = numbersRequestedAsInts.OrderBy(i => i); var securityNumbersString = string.Join("", numbersRequestedAsInts.Select(i => Config.SecurityNumber[i - 1])); browser.Element( Find.ByName("METROBANK[1].LOGIN[1].SECURITYNUMBER[1].APPENDEDVALUE")) .SetAttributeValue("value", securityNumbersString); }
public void UnsuccessfulAdministrationLogin() { bool result; using (var browser = new IE("http://localhost:1200/")) { browser.Link(Find.ByText("Admin")).Click(); browser.TextField(Find.ById("UserName")).TypeText("admin"); browser.TextField(Find.ById("Password")).TypeText("admin"); browser.Element(Find.ByValue("Log On")).Click(); result = browser.ContainsText("Login was unsuccessful."); } Assert.That(result, "Browser Url is incorrect"); }
public void Login_WithoutUsernameAndPassword_Should_Have_ErrorMessage() { using (var browser = new IE()) { browser.GoTo("http://localhost:1100/"); browser.BringToFront(); browser.Link(Find.ByText("Admin")).Click(); browser.Element(Find.BySelector("input.LogOn")).Click(); Assert.IsTrue(browser.ContainsText("The User name field is required")); Assert.IsTrue(browser.ContainsText("The Password field is required.")); } }
public void SuccessfulAdministrationLogin() { var browserUrl = string.Empty; using (var browser = new IE("http://localhost:1200/")) { browser.Link(Find.ByText("Admin")).Click(); browser.TextField(Find.ById("UserName")).TypeText("administrator"); browser.TextField(Find.ById("Password")).TypeText("password123!"); browser.Element(Find.ByValue("Log On")).Click(); browser.WaitForComplete(2); browserUrl = browser.Url; } Assert.That(browserUrl.Contains("/StoreManager"), string.Format("Browser Url is incorrect - it is actually {0}", browserUrl)); }
public void Login_UnSuccessful_Should_Have_Error() { var browser = new IE(); browser.GoTo("http://localhost:1100/"); browser.BringToFront(); browser.Link(Find.ByText("Admin")).Click(); browser.TextField(Find.ById("UserName")).TypeText("admin"); browser.TextField(Find.ById("Password")).TypeText("1234"); browser.Element(Find.BySelector("input.LogOn")).Click(); Assert.IsTrue(browser.ContainsText("Login was unsuccessful.")); }
public void Login_Successful_Should_Have_LogOut_Link() { using (var browser = new IE()) { browser.GoTo("http://localhost:1100/"); browser.BringToFront(); browser.Link(Find.ByText("Admin")).Click(); //browser.Element(x => x.) browser.TextField(Find.ById("UserName")).TypeText("administrator"); browser.TextField(Find.ById("Password")).TypeText("password123!"); browser.Element(Find.BySelector("input.LogOn")).Click(); Assert.IsTrue(browser.Link(Find.ByText("Log Out")).Exists); browser.Link(Find.ByText("Log Out")).Click(); } }
private void fillLineAddress() { IElementContainer predictiveAddress = (IElementContainer)ie.Element(Find.By(Constants.BlueBirdConstants.PREDICTIVE_ADDRESS_ATTRIBUTE, Constants.BlueBirdConstants.PREDICTIVE_ADDRESS_ATTRIBUTE_VALUE)); predictiveAddress.TextField(Constants.BlueBirdConstants.PREDICTIVE_ADDRESS_LINE1_ELEMENT_ID).TypeText(data.Line1); }
protected Element GetFlashPlayerElement() { return(browser.Element(Find.ById("FlexBridgeTests"))); }
private async void Login(object sender, RoutedEventArgs e) { var ctx = new OAuthConsumerContext { ConsumerKey = _settings.OauthConsumerKey, ConsumerSecret = _settings.OauthConsumerSecret, SignatureMethod = SignatureMethod.HmacSha1 }; var session = new OAuthSession( ctx, "https://www.obsidianportal.com/oauth/request_token", "https://www.obsidianportal.com/oauth/authorize", "https://www.obsidianportal.com/oauth/access_token"); IToken token = session.GetRequestToken(); string authLink = session.GetUserAuthorizationUrlForToken(token, "oob"); Task <IToken> getTokenTask = CallbackAsyncThread.RunAsync( () => { string verifier = null; using (var browser = new IE(authLink) { AutoClose = true }) { while ( !string.Equals( browser.Url, "https://www.obsidianportal.com/oauth/authorize", StringComparison.OrdinalIgnoreCase)) { NameValueCollection queryString = HttpUtility.ParseQueryString(browser.Uri.Query); if (queryString["oauth_verifier"] != null) { verifier = queryString["oauth_verifier"]; break; } Thread.Sleep(500); } if (verifier == null) { Element element = browser.Element("oauth-verifier"); if (!element.Exists) { return(null); } verifier = element.Text; } } return(session.ExchangeRequestTokenForAccessToken(token, verifier)); }, ApartmentState.STA); IToken accessToken; try { accessToken = await getTokenTask; } catch (Exception) { MessageBox.Show(this, "Failed to log in", "Login Failed", MessageBoxButton.OK, MessageBoxImage.Error); return; } _settings.OauthToken = accessToken.Token; _settings.OauthTokenSecret = accessToken.TokenSecret; _settings.Save(); await LoadInformation(); }
private void CommenceReporting() { try { using (var browser = new IE("https://mobile.bet365.com/#type=InPlay;key=;ip=1;lng=1")) { browser.Visible = false; System.Threading.Thread.Sleep(5000); while (continueReporting) { try { Element mapElement = browser.Element("wrapper"); string mapHtml = mapElement.InnerHtml; // --- Iterate over areas HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(mapHtml); try { List <League> daLeagues = new List <League>(); if (currentLeagues.Count > 0) { previousLeagues.Clear(); previousLeagues.AddRange(currentLeagues); } foreach (HtmlNode sportBaseNode in doc.DocumentNode.SelectNodes("//div[contains(@class, 'ipo-ClassificationMenuBase ') and not(contains(@class, 'ipo-Competition_EventLink'))]")) { HtmlNode selectedSportNode = sportBaseNode.SelectSingleNode("//div[contains(@class, 'ipo-ClassificationMenu_Selected')]"); string selectedSport = selectedSportNode.InnerText.ToLower().Trim(); if (selectedSport == "soccer") { foreach (HtmlNode categoryNode in doc.DocumentNode.SelectNodes("//div[@class='ipo-CompetitionBase ']")) { try { League daLeague = new League(); List <Game> daGames = new List <Game>(); HtmlNode leagueNode = categoryNode.FirstChild.SelectSingleNode(".//div[@class='ipo-Competition_Name ']"); if (leagueNode != null) { daLeague.GameLeague = leagueNode.InnerText; foreach (HtmlNode gameTimeOuterNode in categoryNode.SelectNodes(".//div[contains(@class, 'ipo-Fixture') and contains(@class, 'ipo-Fixture_TimedFixture')]")) { try { Game daGame = new Game(); HtmlNode gameTimeNode = gameTimeOuterNode.SelectSingleNode(".//div[contains(@class, 'ipo-Fixture_GameInfo') and contains(@class, 'ipo-Fixture_Time')]"); daGame.GameTime = new TimeSpan(0, Int32.Parse(gameTimeNode.InnerText.Substring(0, gameTimeNode.InnerText.IndexOf(':'))), Int32.Parse(gameTimeNode.InnerText.Substring(gameTimeNode.InnerText.IndexOf(':') + 1))); int teamCount = 0; foreach (HtmlNode gameNode in gameTimeOuterNode.SelectNodes(".//div[contains(@class, 'ipo-Fixture_GameItem ')]")) { int tryParseNumber; if (teamCount == 0) { Team team = new Team(); HtmlNode team1Node = gameNode.FirstChild.FirstChild; team.TeamName = team1Node.InnerText; HtmlNode team1PointsNode = gameNode.FirstChild.NextSibling.FirstChild; if (Int32.TryParse(team1PointsNode.InnerText, out tryParseNumber)) { team.TeamScore = Int32.Parse(team1PointsNode.InnerText); } else { team.TeamScore = 0; } daGame.Teams.Add(team); // --- Bump team count teamCount++; } else if (teamCount == 1) { Team team = new Team(); HtmlNode team2NameNode = gameNode.FirstChild.FirstChild; team.TeamName = team2NameNode.InnerText; HtmlNode team2PointsNode = gameNode.FirstChild.NextSibling.FirstChild; if (Int32.TryParse(team2PointsNode.InnerText, out tryParseNumber)) { team.TeamScore = Int32.Parse(team2PointsNode.InnerText); } else { team.TeamScore = 0; } daGame.Teams.Add(team); teamCount = 0; } } // --- Add the game daLeague.Games.Add(daGame); } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); // --- Report on error and continue emailHelper.SendExceptionEmail(ex.Message + " " + line); } } daLeagues.Add(daLeague); } } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); // --- Report on error and continue emailHelper.SendExceptionEmail("Error going over category nodes - " + ex.Message + " " + line); } } // --- Report to master int a = 0; } } if (previousLeagues.Count == 0) { previousLeagues.AddRange(daLeagues); } else { currentLeagues.AddRange(daLeagues); this.ReportChanges(); } } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); // --- Report on error and continue emailHelper.SendExceptionEmail("Error going over sport base nodes - " + ex.Message + " " + line); } // --- Check the page only ever 5 seconds System.Threading.Thread.Sleep(5000); } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); // --- Report on error and continue emailHelper.SendExceptionEmail("Error in try right after start of while loop - " + ex.Message + " " + line); } } } } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); // --- Report on error and continue emailHelper.SendExceptionEmail("Error outside using - " + ex.Message + " " + line); } }
public string AddedToBasketMessage() { return(_browser.Element(Find.ById("confirm-text")).ToString()); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { try { //foreach (WatiN.Core.TextField obj in ie.TextFields) //{ // obj.Highlight(false); //} //foreach (WatiN.Core.Button obj in ie.Buttons) //{ // obj.Highlight(false); //} //foreach (WatiN.Core.Div obj in ie.Divs) //{ // obj.Highlight(false); //}\ txtSelect.Text = e.Node.Text; string Value = e.Node.Text; if (Value.IndexOf(" = ") >= 0) { Value = Value.Split('=')[1].Trim(); } if (e.Node.FullPath.IndexOf("Div") >= 0) { if (txtSelect.Text.IndexOf("Name = ") >= 0) { Div div = ie.Div(Find.ByName(Value)); if (div != null && div.Exists) { div.Highlight(true); } } else { Div div = ie.Div(Find.ById(Value)); if (div != null && div.Exists) { div.Highlight(true); } } } else if (e.Node.FullPath.IndexOf("TextBox") >= 0) { TextField text = ie.TextField(Find.ByName(Value)); if (text != null && text.Exists) { text.Highlight(true); text.Select(); } } else if (e.Node.FullPath.IndexOf("Button") >= 0) { WatiN.Core.Button butt = ie.Button(Find.ByValue(Value)); if (butt != null && butt.Exists) { butt.Highlight(true); } } else if (e.Node.FullPath.IndexOf("Link") >= 0) { if (txtSelect.Text.IndexOf("Class = ") >= 0) { WatiN.Core.Link link = ie.Link(Find.ByClass(Value)); if (link != null && link.Exists) { link.Highlight(true); } } else { WatiN.Core.Link link = ie.Link(Find.ByText(Value)); if (link != null && link.Exists) { link.Highlight(true); } } } else if (e.Node.FullPath.IndexOf("Element") >= 0) { if (txtSelect.Text.IndexOf("Id = ") >= 0) { WatiN.Core.Element link = ie.Element(Find.ById(Value)); if (link != null && link.Exists) { link.Highlight(true); } } else { WatiN.Core.Element link = ie.Element(Find.ByText(Value)); if (link != null && link.Exists) { link.Highlight(true); } } } } catch { } }
public bool Bind(DAL dal, IE ie) { //indicates a dummy object that only hold a scalar value if (Name.Length + Website.Length == 0) { return(true); } if ((dal == null) || (ie == null)) { throw new Exception("a critical resource is missing (either DB or IE reference)"); } IEnumerable <DAL.RecognitionProperty> props = dal.GetElementRecogitionProperties(Website, Name); if (props.Count() == 0) { return(false); } else { Dictionary <Element, int> priorityMap = new Dictionary <Element, int>(); //if (! Website.Contains(ie.Uri.Host)) { ie.GoTo(Website); // Log.GetInstance().Write("navigating to " + Website); } try { foreach (var item in props) { if (item.Priority == 0) { continue; //don't bother to check irrelevant attributes } //handle special attribute name/id:root childnum childnum .... if (item.Attribute.Equals("indirectPath")) { String[] path = item.Value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); String[] root = path[0].Split(':'); Element elm = null; if (root[0].Equals("id")) { elm = ie.Element(Find.ById(root[1])); for (int i = 1; i < path.Length; i++) { elm = new Element(elm.DomContainer, elm.NativeElement.Children.GetElements().ElementAt(int.Parse(path[i]))); } this.WatinElement = elm; } else if (root[0].Equals("name")) { elm = ie.Element(Find.ByName(root[1])); for (int i = 1; i < path.Length; i++) { elm = new Element(elm.DomContainer, elm.NativeElement.Children.GetElements().ElementAt(int.Parse(path[i]))); } } priorityMap[elm] += item.Priority; if (priorityMap[elm] >= 100) { this.WatinElement = elm; break; } } Element element = null; if (item.Attribute.Equals("class", StringComparison.OrdinalIgnoreCase)) { element = ie.Element(Find.ByClass(item.Value)); } else if (item.Attribute.Equals("id", StringComparison.OrdinalIgnoreCase)) { element = ie.Element(Find.ById(item.Value)); } else if (item.Attribute.Equals("name", StringComparison.OrdinalIgnoreCase)) { element = ie.Element(Find.ByName(item.Value)); } /// TAG makes some trouble so I bypass it for now else if (item.Attribute.Equals("tag", StringComparison.OrdinalIgnoreCase)) { continue; } else if ((item.Value != null) && (item.Value != "") && (item.Value != "null")) { element = ie.Element(Find.By(item.Attribute, item.Value)); } try { if (element != null) { if (priorityMap.ContainsKey(element)) { priorityMap[element] += item.Priority; if (priorityMap[element] >= 100) { this.WatinElement = element; break; } } else { priorityMap.Add(element, item.Priority); } } } catch (Exception exc) { Log.GetInstance().Write(exc.Message); Console.WriteLine(exc.Message); } } foreach (var key in priorityMap.Keys) { if (this.WatinElement == null) { this.WatinElement = key; } else { if (priorityMap[this.WatinElement] < priorityMap[key]) { this.WatinElement = key; } } } this.IsBound = true; this.Value = this.WatinElement.GetAttributeValue("value"); } catch (WatiN.Core.Exceptions.ElementNotFoundException) { //try to navigate to page if (doNavigate) { doNavigate = false; string wUrl = dal.GetWebSiteUrlByName(Website); if (wUrl.Length > 0) { Log.GetInstance().Write(string.Format("navigating to {0}({1})", Website, wUrl)); ie.GoTo(wUrl); this.IsBound = false; return(this.Bind(dal, ie)); } } } catch (Exception exc) { Log.GetInstance().Write(exc.Message); Console.WriteLine(exc.Message); Log.GetInstance().Write(exc.StackTrace); Console.WriteLine(exc.StackTrace); this.IsBound = false; } finally { doNavigate = true; } } return(IsBound); }