public void UsingBrowserDirect() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); var found = b.Find("div", FindBy.Class, "issues_closed"); Assert.That(found.TotalElementsFound == 3); }
public void FindingDuplicatesAndNotFinding() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var anchor = driver.FindElement(By.TagName("a")); Assert.That(anchor.TagName == "a"); Assert.Throws(typeof(NoSuchElementException), ()=>driver.FindElement(By.TagName("nosuchtag"))); }
public void Searching_Html_Root_Element_Should_Work() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var rootElement = driver.FindElements(By.TagName("html")); Assert.NotNull(rootElement); Assert.That(rootElement.Count > 0); }
public void UsingLinks() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var link = driver.FindElement(By.CssSelector("a.clickLink")); string lastRequest = ""; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.Url.ToString(); }; link.Click(); Assert.That(lastRequest.Contains("www.google.com/search"), "Link has resulted in unexpected request"); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); link = driver.FindElement(By.CssSelector("a.link-relative")); link.Click(); Assert.That(lastRequest.Contains("/search"), "Link has resulted in unexpected request"); }
public void UsingRadioButtons() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var radio1 = driver.FindElement(By.CssSelector(".rb-container #first-radio")); var radio2 = driver.FindElement(By.CssSelector(".rb-container #second-radio")); var radio1Label = driver.FindElement(By.CssSelector("label[for=first-radio]")); Assert.That(radio1.Selected, "Radiobutton 1 should be selected"); Assert.That(!radio2.Selected, "Radiobutton 2 should not be selected"); radio2.Click(); Assert.That(!radio1.Selected, "Radiobutton 1 should not be selected"); Assert.That(radio2.Selected, "Radiobutton 2 should be selected"); Assert.NotNull(radio1Label, "Label not found"); radio1Label.Click(); Assert.That(radio1.Selected, "Radiobutton 1 should be selected"); Assert.That(!radio2.Selected, "Radiobutton 2 should be not selected"); }
public void UsingCheckboxes() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var checkbox1 = driver.FindElement(By.CssSelector(".cb-container #first-checkbox")); var checkbox2 = driver.FindElement(By.CssSelector(".cb-container #second-checkbox")); Assert.That(checkbox1.Selected, "Checkbox 1 should be selected"); Assert.That(!checkbox2.Selected, "Checkbox 2 should not be selected"); checkbox2.Click(); Assert.That(checkbox1.Selected, "Checkbox 1 should still be selected"); Assert.That(checkbox2.Selected, "Checkbox 2 should be selected"); var checkbox1Label = driver.FindElement(By.CssSelector("label[for=first-checkbox]")); Assert.NotNull(checkbox1Label, "Label not found"); checkbox1Label.Click(); Assert.That(checkbox2.Selected, "Checkbox 2 should still be selected"); Assert.That(!checkbox1.Selected, "Checkbox 1 should be not selected"); }
public void UsingSelectBoxes() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var selectbox = driver.FindElement(By.Name("sel")); var box = new SelectElement(selectbox); Assert.That(box.SelectedOption.Text == "two"); box.SelectByValue("3"); Assert.That(box.SelectedOption.Text == "three"); box.SelectByText("one"); Assert.That(box.SelectedOption.Text == "one"); selectbox = driver.FindElement(By.Name("sel_multi")); box = new SelectElement(selectbox); Assert.That(box.IsMultiple); box.SelectByValue("3"); box.SelectByText("one"); Assert.That(box.AllSelectedOptions.Count == 3); }
public void SearchingInKnownDocument() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var iconSpans = driver.FindElements(By.CssSelector("span.icon")); Assert.That(iconSpans.Count == 4, "There should be 4 spans with class icon"); var accountSettings = driver.FindElements(By.CssSelector("*[title~= Account]")); Assert.That(accountSettings.Count == 1 && accountSettings[0].Text == "Account Settings", "There should be 1 element with title containing the word Account"); var topStuff = driver.FindElements(By.CssSelector("*[class|=top]")); Assert.That(topStuff.Count == 3 , "There should be 3 elements with class starting with top-"); var h2s = driver.FindElements(By.CssSelector("h2")); Assert.That(h2s.Count == 8, "There should be 8 h2 elements"); var titleContainingTeun = driver.FindElements(By.CssSelector("*[title*=Teun]")); Assert.That(titleContainingTeun.Count == 3, "There should be 3 elements with 'Teun' somewhere in the title attrbute"); }
public void PostAspnetPostbackForm() { Browser b = new Browser(Helper.GetAllways200RequestMocker()); b.SetContent(Helper.GetFromResources("DriverTest.PostbackForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var form = driver.FindElement(By.CssSelector("form")); NameValueCollection lastRequest = null; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.PostData; }; var postbackLink = driver.FindElement(By.Id("postbackLink")); postbackLink.Click(); Assert.That(lastRequest.AllKeys.Contains("__EVENTTARGET") && lastRequest["__EVENTTARGET"].Contains("colorBox"), "colorBox was not indicated as the postback target"); }
public void SubmitPostForm() { Browser b = new Browser(Helper.GetAllways200RequestMocker()); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var form = driver.FindElement(By.CssSelector("form")); NameValueCollection lastRequest = null; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.PostData; }; form.Submit(); Assert.That(lastRequest.AllKeys.Contains("radios") && lastRequest["radios"].Contains("first"), "Radio buttons not in correct state"); // NOTE: this line seems wrong: the line breaks in a textarea should remain preserved. But, XML parsing will remove this. // What are the actual rules around this //Assert.That(lastRequest.AllKeys.Contains("textarea_a") && lastRequest["textarea_a"].Contains("This is a full text part\r\nwith"), "Textarea not posted correctly"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); form = driver.FindElement(By.CssSelector("form")); var firstRadio = driver.FindElement(By.Id("first-radio")); var firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]")); var secondRadio = driver.FindElement(By.Id("second-radio")); secondRadio.Click(); form.Submit(); Assert.That(lastRequest.AllKeys.Contains("radios") && lastRequest["radios"].Contains("second"), "Radio buttons not in correct state"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); form = driver.FindElement(By.CssSelector("form")); firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]")); firstRadioLabel.Click(); form.Submit(); Assert.That(lastRequest.AllKeys.Contains("radios") && lastRequest["radios"].Contains("first"), "Radio buttons not in correct state"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); form = driver.FindElement(By.CssSelector("form")); var selectBox = driver.FindElement(By.Id("optionsList")); var box = new SelectElement(selectBox); Assert.That(box.AllSelectedOptions.Count == 1, "First option should be selected in selectbox"); form.Submit(); Assert.That(lastRequest.AllKeys.Contains("optionsList") && lastRequest["optionsList"].Contains("opt1"), "Selectbox not in correct state"); Assert.That(!lastRequest.AllKeys.Contains("submitButton"), "Value of submit button should not be posted"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); var submitButton = driver.FindElement(By.CssSelector("input[type=submit]")); submitButton.Click(); Assert.That(lastRequest.AllKeys.Contains("submitButton") && lastRequest["submitButton"].Contains("button1"), "Value of submit button not posted"); Assert.That(!lastRequest.AllKeys.Contains("submitButton2"), "Value of submit button should not be posted"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); submitButton = driver.FindElement(By.CssSelector("button[type=submit]")); submitButton.Click(); Assert.That(lastRequest.AllKeys.Contains("submitButton2") && lastRequest["submitButton2"].Contains("button2"), "Value of submit button not posted"); }
public void UsingHtml5Inputs() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var colorBox = driver.FindElement(By.Id("colorBox")); Assert.NotNull(colorBox, "Couldn't find colorbox"); colorBox.SendKeys("ff0000"); Assert.AreEqual(colorBox.Text, "ff0000", "Colorbox did not pick up sent keys"); var form = driver.FindElement(By.CssSelector("form")); string lastRequest = ""; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.Url.AbsoluteUri; }; form.Submit(); Assert.That(lastRequest.Contains("colorBox=ff0000"), "Color box not posted correctly"); }
public void UsingTextareas() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var textbox = driver.FindElement(By.Name("textarea_a")); Assert.That(textbox != null); Assert.That(textbox.Text.Contains("\n"), "Textarea should not make line breaks coalesce into space"); }
public void UsingTextboxes() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var textbox = driver.FindElement(By.CssSelector("#your-repos-filter")); Assert.NotNull(textbox, "Couldn't find textbox"); Assert.That(textbox.Text == String.Empty, "Textbox without a value attribute should have empty text"); textbox.SendKeys("test text"); Assert.That(textbox.Text == "test text", "Textbox did not pick up sent keys"); textbox.SendKeys(" more"); Assert.That(textbox.Text == "test text more", "Textbox did not append second text"); textbox.Clear(); Assert.That(textbox.Text == String.Empty, "Textbox after Clear should have empty text"); }
public void SubmitGetForm() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var form = driver.FindElement(By.CssSelector("form")); string lastRequest = ""; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.Url.AbsoluteUri; }; form.Submit(); Assert.That(lastRequest.Contains("radios=first"), "Radio buttons not in correct state"); // NOTE: this line seems wrong: the line breaks in a textarea should remain preserved. But, XML parsing will remove this. // What are the actual rules around this Assert.That(lastRequest.Contains("textarea_a=This+is+a+full+text+part%0d%0awith"), "Textarea not posted correctly"); var firstRadio = driver.FindElement(By.Id("first-radio")); var firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]")); var secondRadio = driver.FindElement(By.Id("second-radio")); secondRadio.Click(); form.Submit(); Assert.That(lastRequest.Contains("radios=second"), "Radio buttons not in correct state"); firstRadioLabel.Click(); form.Submit(); Assert.That(lastRequest.Contains("radios=first"), "Radio buttons not in correct state"); var selectBox = driver.FindElement(By.Id("optionsList")); var box = new SelectElement(selectBox); Assert.That(box.AllSelectedOptions.Count == 1, "First option should be selected in selectbox"); form.Submit(); Assert.That(lastRequest.Contains("optionsList=opt1"), "Selectbox not in correct state"); Assert.That(!lastRequest.Contains("submitButton=button1"), "Value of submit button should not be posted"); var submitButton = driver.FindElement(By.CssSelector("input[type=submit]")); submitButton.Click(); Assert.That(lastRequest.Contains("submitButton=button1"), "Value of submit button not posted"); }
XDocument GetTestDocument() { var browser = new Browser(); // this must be the document that was apparently been available on http://xbrowser.axefrog.com/htmltests/basic2.htm browser.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.Axefrog_Basic2.htm")); return browser.Select("*").XElement.Document; }
public void Repro_Issue24() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var by = By.XPath("//input[contains(@id, 'repos')]"); var tst = driver.FindElement(by); }