/// <summary> /// Method invoked from the TestContainer [IeTest] /// Finds the text field and inputs the value /// </summary> public override void Do(IE ie) { if (ie == null) { ie = Wxs.Instance.Ie; } try { if (txtAttributeValue.Contains("*")) { txtAttributeValue = txtAttributeValue.Replace("*", String.Empty); ie.TextField(Find.By(txtAttributeName, new Regex(txtAttributeValue, RegexOptions.IgnoreCase))).TypeText(text); } else { ie.TextField(Find.By(txtAttributeName, txtAttributeValue)).TypeText(text); } Wxs.Instance.Log.Debug( String.Format("Text {0} entered on element {1}", text, txtAttributeName)); } catch (WatiN.Core.Exceptions.ElementNotFoundException e) { Wxs.Instance.Log.Error(String.Format("Element not found error in text input {0}", name), e); throw; } catch (Exception genEx) { Wxs.Instance.Log.Error(genEx.Message, genEx); } }
public void LocatingThingsByNonId() { using (var browser = new IE("http://localhost:62727/Pages/ApplyForCreditCard.aspx")) { Div errorContainer = browser.Div(Find.ByClass("error")); SelectList title = browser.SelectList(Find.ByName("Title")); Label ageLabel = browser.Label(Find.ByFor("Age")); TextField applicantAge = browser.TextField(Find.ByLabelText("Age In Years")); TextField applicantAge2 = browser.TextField(Find.By("id", "Age")); // var something = browser.Div(Find.By("someattribute","somevalue")); // Assert.That(something, Is.Not.Null); // Link helpHyperlink = browser.Link(Find.ById("HelpLink")); // Button applyButton = browser.Button(Find.ById("ApplyNow")); // Para nameParagraph = browser.Para(Find.ById("Name")); } }
/// <summary> /// Updates the resources. /// </summary> public void UpdateResources() { var tableState = browser.Table(Find.By("background", controller.ImageTitleBackground)); if (!tableState.Exists) { AppCore.LogSystem.Error("Не найден изображение ImageTitleBackground"); return; } var guildCell = tableState.TableRows[4].TableCells[2]; if (guildCell.Images.Count > 0) { var guilUrl = guildCell.Images[0].Src; var tmp = guilUrl.Substring(controller.UrlImageGuildsSSTemplate.IndexOf('{')); tmp = tmp.Substring(0, tmp.Length - 6); Guild = (GuildType)int.Parse(tmp); } if (string.IsNullOrEmpty(Name)) { AppCore.AcountSettings.UserName = Name = tableState.TableRows[2].TableCells[0].Text; } var resourceRow = tableState.TableRows[5]; Money = Integer.Parse(resourceRow.TableCells[0].Text); Cristals = Integer.Parse(resourceRow.TableCells[1].Text); Green = Integer.Parse(resourceRow.TableCells[2].Text); }
public int SetValInTreeOptionSet(Document iFrame, Element element, string value) { Div div = element as Div; var arrowImg = div.Elements.Filter(Find.ById($"{div.Id}_i")).FirstOrDefault(); if (arrowImg.Exists == true) { arrowImg.Click(); } else { if (div?.Divs.Count > 1) { if (div.Divs[0].Style.GetAttributeValue("display") == "block") { element.Click(); Thread.Sleep(100); } if (div.Divs[1].Style.GetAttributeValue("display") == "block") { arrowImg?.Click(); } } } Div treeDiv = iFrame.Div(element.Id + "_treediv_flyOut"); treeDiv.WaitUntilExists(Command.GetTimeoutLeftSeconds()); if (treeDiv == null) { throw new ApplicationException("Timeout occured while waiting for tree optionset menu to popup"); } TypeText("⋘down⋙"); TypeText("⋘right 60⋙"); treeDiv.WaitUntil(x => x.Elements?.Count > 0, Command.GetTimeoutLeftSeconds()); ElementCollection options = null; while (options == null && Command.CheckTimeout()) { options = treeDiv.Elements.Filter(Find.By("HREF", "#")); } while (options.Count == 0) { } foreach (var option in options) { string text1 = option.OuterText.ToLower().Trim(); string text2 = value.ToLower().Trim(); if (option.OuterText.ToLower().Trim() == value.ToLower().Trim()) { option.Click(); return(1); } } TypeText("⋘esc⋙"); return(0); }
public virtual void ClickRowLink <T>(string tableName, List <RowFilter <T> > filters, string relId) { TableRow filteredRow = GetFilteredRows(tableName, filters)[0]; var link = filteredRow.Link(Find.By("rel", relId)); link.Click(); }
void logoutCurrentUser(Browser browser) { if (browser.Links.Exists(Find.By("href", "https://haraj.com.sa/logout.php"))) { browser.Link(Find.By("href", "https://haraj.com.sa/logout.php")).Click(); } }
public override void Do(IE ie) { if (ie == null) { ie = Wxs.Instance.Ie; } try { if (lnkAttributeValue.Contains("*")) { lnkAttributeValue = lnkAttributeValue.Replace("*", String.Empty); ie.Link(Find.By(lnkAttributeName, new Regex(lnkAttributeValue))).Click(); } else { ie.Link(Find.By(lnkAttributeName, lnkAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Link {0}[{1}] clicked", lnkAttributeName, lnkAttributeValue)); } catch (Exception e) { Wxs.Instance.Log.Error("Error Clicking Link : " + name, e); } }
public void ElementByTagNameAndInputType() { ExecuteTest(browser => { element = browser.ElementWithTag("input", Find.By("id", "name"), "text"); Assert.IsTrue(element.Exists); }); }
void logoutCurrentUser(Browser browser) { if (browser.Elements.Exists(Find.By("data-au", "myAccount-AU"))) { browser.Link(Find.By("data-au", "myAccount-AU")).Click(); browser.Button(Find.ByText("Logout")).Click(); } }
public void ElementByTagName() { ExecuteTest(browser => { element = browser.ElementWithTag("a", Find.By("id", "testlinkid")); Assert.IsTrue(element.Exists); }); }
public void ShouldBeAbleToFindFrameUsingCustomAttributeInFrameSetElement() { ExecuteTest(browser => { var frame = browser.Frame(Find.By("mycustomattribute", "WatiN")); Assert.That(frame.Id, Is.EqualTo("mainid")); }); }
private Browser AttachToExistingBrowser <T>() where T : Browser { if (!_browserSetUp.CloseBrowserAfterEachTest && _browsers.Exists(x => x.GetType() == typeof(T))) { return(Browser.AttachTo <T>(Find.By("hwnd", _hwnd))); } return(null); }
static void Main(string[] args) { //using (var browser = new IE()) using (var browser = Browser.AttachTo <IE>(Find.ByTitle("Empirica Signal"))) { var a = 0; } using (var browser = Browser.AttachTo <IE>(Find.ByTitle("QBE"))) { //browser.TextField(Find.ByName("username")).ClickNoWait(); //browser.TextField(Find.ByName("username")).TypeText("admin"); //browser.TextField(Find.ByName("password")).ClickNoWait(); //browser.TextField(Find.ByName("password")).TypeText("Prudentia@123"); //browser.Button(Find.ByText("Submit")).Click(); //browser.Link(Find.By("href", "#/eventinfo")).Click(); //browser.GoTo("http://arisg7.ergomed.local:8080/Aris/login"); //browser.WaitForComplete(); //browser.SelectList(Find.ByName("dbnames")).Select("MDCO02"); //browser.TextField(Find.ByName("userId")).TypeText("gbajpai"); //browser.TextField(Find.ByName("password")).TypeText("Admin@123"); //browser.Button(Find.ByName("LoginSubmitButton")).Click(); browser.Button(Find.ByValue("SQL")).Click(); using (var popup = Browser.AttachTo <IE>(Find.ByTitle("SQL"))) { popup.Button(Find.ByValue("Retrieve from Database")).ClickNoWait(); HtmlDialog lookup = browser.HtmlDialog(Find.ByTitle("Query LookUp")); //using (var lookup = Browser.AttachTo<IE>(Find.ByUrl("http://arisg7.ergomed.local:8080/Aris/QBE/jsp/LoadQueryFromUseSQL.jsp"))) //{ lookup.TextField(Find.ByName("QUERY")).TypeText("PRU_QBE_MONTHLY_PROD_SUBMISSION"); lookup.Button(Find.ByValue("OK")).Click(); lookup.WaitForComplete(); lookup.Button(Find.ByValue("Select")).ClickNoWait(); //} popup.WaitForComplete(); var sql = popup.TextField(Find.ByName("SQL_STRING")).Text; sql = sql.Replace("##Start Date##", "'01-SEP-2016'").Replace("##End Date##", "'30-SEP-2016'").Replace("##PRODUCT GNAME##", "'Bivalirudin'").Replace("##COUNTRY##", "'USA'"); sql = sql.Replace(", AER_PRODUCT AP", ""); sql = sql.Replace("AER_CNTRY WHERE", "AER_CNTRY, AER_PRODUCT AP WHERE"); popup.TextField(Find.ByName("SQL_STRING")).Value = sql; popup.Button(Find.ByValue("OK")).Click(); popup.CheckBox(Find.ById("selectallChk")).ClickNoWait(); lookup = popup.HtmlDialog(Find.ByTitle("ARISg7")); lookup.Button(Find.ByValue("Yes")).ClickNoWait(); popup.Link(Find.By("href", "javascript:generateReport(\"104\",\"2002\")")).ClickNoWait(); //lookup = popup.HtmlDialog(Find.ByTitle("ARISg7")); //lookup.WaitUntilClosed(); //var progBrowser = Browser.AttachTo<IE>(Find.ByTitle("ARISg7")); var pdfBrowser = Browser.AttachTo <IE>(Find.ByTitle("ARISg")); pdfBrowser.WaitForComplete(); string a = ""; } Console.Read(); } }
public bool Stale(Options options) { try { return(!WatiN.Core.Browser.Exists <IE>(Find.By("hwnd", browser.hWnd.ToString()))); } catch (System.Runtime.InteropServices.COMException) { return(true); } }
public void WhenISearchForAt_Info(string searchPhrase) { TextField txtSearchBox = WebBrowser.TextField("text"); txtSearchBox.TypeText(searchPhrase); Button btnSearch = WebBrowser.Button(Find.By("tabindex", "20")); btnSearch.Click(); СпиМояРадостьУсни(3000); }
private static Constraint FindWindowHandle(string locator) { var by = Find.ByTitle(locator) | Find.By("hwnd", locator); if (Uri.IsWellFormedUriString(locator, UriKind.Absolute)) { by |= Find.ByUrl(locator); } return(by); }
public void IEExistsByHWND() { var hwnd = "0"; Assert.IsFalse(Browser.Exists <IE>(Find.By("hwnd", hwnd)), "hwnd = 0 should not be found"); using (var ie = new IE(MainURI)) { hwnd = ie.hWnd.ToString(); Assert.IsTrue(Browser.Exists <IE>(Find.By("hwnd", hwnd)), "hwnd of ie instance should be found"); } Assert.IsFalse(Browser.Exists <IE>(Find.By("hwnd", hwnd)), "hwnd of closed ie instance should not be found"); }
public void Setup() { mockAttributeBag = new Mock <IAttributeBag>(); findBy = null; findBy1 = Find.By("1", "true"); findBy2 = Find.By("2", "true"); findBy3 = Find.By("3", "true"); findBy4 = Find.By("4", "true"); findBy5 = Find.By("5", "true"); findBy6 = Find.By("6", "true"); findBy7 = Find.By("7", "true"); findBy8 = Find.By("8", "true"); }
public void ShouldThrowFrameNotFoundExceptionWhenFindingFrameWithNonExistingAttribute() { ExecuteTest(browser => { try { browser.Frame(Find.By("nonexisting", "something")); Assert.Fail("Expected " + typeof(FrameNotFoundException)); } catch (Exception e) { Assert.That(e, Is.TypeOf(typeof(FrameNotFoundException)), "Unexpected exception"); } }); }
public void Setup() { mockAttributeBag = new MockAttributeBag("1", "true"); mockAttributeBag.Add("2", "false"); mockAttributeBag.Add("4", "true"); mockAttributeBag.Add("5", "false"); findBy = null; findBy1 = Find.By("1", "true"); findBy2 = Find.By("2", "true"); findBy3 = Find.By("3", "true"); findBy4 = Find.By("4", "true"); findBy5 = Find.By("5", "true"); }
public void ShouldCancelCloseBrowser() { using (var ie = new IE()) { var hwnd = ie.hWnd.ToString(); // GIVEN var command = "window.close();"; using (new UseDialogOnce(ie.DialogWatcher, new CloseIEDialogHandler(false))) { // WHEN ie.Eval(command); } // THEN Assert.That(Browser.Exists <IE>(Find.By("hwnd", hwnd)), Is.True, "Expected IE"); } }
private static Constraint FindWindowHandle(string locator, Options exact) { Constraint byTitle = Find.ByTitle(locator); if (exact.TextPrecision == TextPrecision.Exact) { byTitle = byTitle | Find.ByTitle(t => t.Contains(locator)); } var by = byTitle | Find.By("hwnd", locator); if (Uri.IsWellFormedUriString(locator, UriKind.Absolute)) { by |= Find.ByUrl(locator); } return(by); }
public static string PreviousSpanWrap(Span span) { var previousSpan = span.PreviousSibling as Span; if (previousSpan == null) { return(null); } var element = previousSpan.Element(Find.By("id", id => !String.IsNullOrEmpty(id))); if (!element.Exists) { return(null); } return(element.Id); }
public WatiN.Core.Element FindButton(string locator, Scope scope) { var isButton = Constraints.OfType <Button>() | Find.ByElement(e => e.TagName == "INPUT" && e.GetAttributeValue("type") == "image") | Find.By("role", "button"); var byText = Find.ByText(locator); var byIdNameValueOrAlt = Find.ById(locator) | Find.ByName(locator) | Find.ByValue(locator) | Find.ByAlt(locator); var byPartialId = Constraints.WithPartialId(locator); var hasLocator = byText | byIdNameValueOrAlt | byPartialId; var isVisible = Constraints.IsVisible(scope.ConsiderInvisibleElements); var candidates = WatiNScope(scope).Elements.Filter(isButton & hasLocator & isVisible); return(candidates.FirstMatching(byText, byIdNameValueOrAlt, byPartialId)); }
public ElementFound FindWindow(string locator, Scope scope) { var by = Find.ByTitle(locator) | Find.By("hwnd", locator); if (Uri.IsWellFormedUriString(locator, UriKind.Absolute)) { by |= Find.ByUrl(locator); } try { var window = WatiN.Core.Browser.AttachTo <IE>(by); return(new WatiNBrowser(window)); } catch (WatiN.Core.Exceptions.BrowserNotFoundException) { throw new MissingHtmlException("No such window found: " + locator); } }
private static void CollectFromFshare(List <VideoSeason> videoSeasons, string url, int seasonNo) { var videoSeason = new VideoSeason { No = seasonNo }; var web = new HtmlWeb(); var htmlDoc = web.Load(url).DocumentNode; var linkNodes = htmlDoc.SelectNodes(@"//a[@class=""filename""]"); foreach (var node in linkNodes) { var link = node.Attributes["href"].Value; var ie = new IE("http://www.linkvip.info/"); ie.TextField(Find.ByName("url")).TypeText(link); ie.Button(Find.By("type", x => x == "submit")).Click(); } videoSeasons.Add(videoSeason); }
public void Register() { try { Ie = new IE("about:blank"); Ie.GoTo("http://localhost/GuestBook/GuestBook.aspx"); Ie.TextField(Find.ByName("name")).TypeText("Jay"); Ie.TextField(Find.ByName("comments")).TypeText("Hello"); Ie.Button(Find.ByName("save")).Click(); Assert.AreEqual("Jay", Ie.TableCell(Find.By("innerText", "Jay")).Text, @"innerText does not match"); Assert.AreEqual("Hello", Ie.TableCell(Find.By("innerText", "Hello")).Text, @"innerText does not match"); } finally { if (Ie != null) { InternetExplorer internetExplorer = (InternetExplorer)Ie.InternetExplorer; internetExplorer.Quit(); } } }
public void RecusiveCallExceptionExpected() { var mockAttributeBag = new Mock <IAttributeBag>(); // Note: Creating a re-entrant constraint is now much more difficult than // before because constraints are immutable. Even the code findBy |= findBy // will not create a re-entrant constraint, it will just be an Or constraint // with two identical clauses. Given this change in constraint construction // we should consider removing the re-entrance checks in the future. -- Jeff. Constraint findBy = Find.By("tag", "value"); findBy |= new PredicateConstraint <IAttributeBag>(bag => findBy.Matches(bag, new ConstraintContext())); ConstraintContext context = new ConstraintContext(); mockAttributeBag.Expect(bag => bag.GetAttributeValue("tag")).Returns("val"); mockAttributeBag.Expect(bag => bag.GetAdapter <IAttributeBag>()).Returns(mockAttributeBag.Object); findBy.Matches(mockAttributeBag.Object, context); mockAttributeBag.VerifyAll(); }
public void FindBy() { const string id = "id"; var value = Find.By(id, "idvalue"); Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer"); Assert.AreEqual(id, value.AttributeName, "Wrong attributename"); Assert.That(value.Comparer.ToString(), Text.Contains("'idvalue'"), "Wrong value"); var mockAttributeBag = new MockAttributeBag(id, "idvalue"); var context = new ConstraintContext(); Assert.IsTrue(value.Matches(mockAttributeBag, context), "Compare should match"); mockAttributeBag = new MockAttributeBag(id, "id"); Assert.IsFalse(value.Matches(mockAttributeBag, context), "Compare should not partial match id"); mockAttributeBag = new MockAttributeBag(id, "val"); Assert.IsFalse(value.Matches(mockAttributeBag, context), "Compare should not partial match val"); mockAttributeBag = new MockAttributeBag(id, "value"); Assert.IsFalse(value.Matches(mockAttributeBag, context), "Compare should not partial match value"); var regex = new Regex("lue$"); value = Find.By(id, regex); mockAttributeBag = new MockAttributeBag(id, "idvalue"); Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex lue$ should match"); value = Find.By(id, new StringContainsAndCaseInsensitiveComparer("dVal")); Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used"); _expectedPredicateCompareValue = "idvalue"; value = Find.By(id, TestPredicateCompareMethod); Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used"); }
public Document GetCurrentIframe(string iFrame = "") { Document result = null; if (iFrame == "none") { result = Ie; } else if (iFrame == "") { result = Ie.Frames.Filter(Find.By("title", "Content Area")).Filter(Find.ByStyle("visibility", "visible")).FirstOrDefault(); } else if (iFrame != null) { iFrame = iFrame.Replace("#", ""); result = Ie.Frames.Filter(Find.ById(iFrame)).FirstOrDefault(); } if (result == null) { throw new ApplicationException($"Iframe {iFrame} could not be found."); } return(result); }