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 ClosingWindows() { IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker( new List<Tuple<string, string>>() { Tuple.Create("^/otherpage", "<html></html>"), Tuple.Create("^.*", @" <html> <a href=""/otherpage"" target=""_blank"" id=""blanklink"">click</a> </html>"), } ))); var dr = new SimpleBrowserDriver((IBrowser)b); dr.Navigate().GoToUrl("http://blah/"); dr.FindElement(By.Id("blanklink")).Click(); Assert.That(dr.Url == "http://blah/"); Assert.That(dr.WindowHandles.Count == 2); string otherWindowName = dr.WindowHandles.First(n => n != dr.CurrentWindowHandle); var otherDr = dr.SwitchTo().Window(otherWindowName); Assert.That(otherDr.Url == "http://blah/otherpage"); // Now we will close the first window and see that everything behaves as expected dr.Close(); Assert.That(otherDr.WindowHandles.Count == 1); Assert.That(otherDr.Url == "http://blah/otherpage"); // still there Assert.Throws<ObjectDisposedException>(() => { var a = dr.Url; }); }
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 FrameSwitchingUsingElementReference() { IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker( new List<Tuple<string, string>>() { Tuple.Create("^/frame", "<html></html>"), Tuple.Create("^.*", @" <html> <iframe src=""/frame""/><iframe src=""/frame""/> </html>"), } ))); var dr = new SimpleBrowserDriver((IBrowser)b); b.Navigate("http://blah/"); var test = dr.FindElement(By.TagName("html")); Assert.That(dr.WindowHandles.Count == 3); var iframe = dr.FindElement(By.TagName("iframe")); var firstFrame = dr.SwitchTo().Frame(iframe); Assert.That(firstFrame.Url == "http://blah/frame"); }
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 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"); }
static void Main(string[] args) { // This is some really stupid testing code. I want to replace this by proper unit test and mock away // the simplebrowser library and the internet using MoQ IWebDriver browser = new SimpleBrowserDriver(); browser.Navigate().GoToUrl("http://*****:*****@placeholder]")); inputBox.SendKeys("test"); Console.WriteLine(inputBox.Text); inputBox = browser.FindElement(By.Name("somename")); Console.WriteLine(inputBox.Text); browser.Navigate().GoToUrl("http://www.funda.nl/koop"); var firstThings = browser.FindElements(By.CssSelector("*[name!='description' ]")); firstThings = browser.FindElements(By.CssSelector("div[class ~= frst]")); firstThings = browser.FindElements(By.CssSelector("*[class ^= nav]")); var input = browser.FindElement(By.Name("PCPlaats")); input.SendKeys("Utrecht"); input.Submit(); Console.WriteLine(browser.Title); Console.ReadLine(); }
public void IframesShouldLoad() { IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker( new List<Tuple<string, string>>() { Tuple.Create("^/frame", "<html></html>"), Tuple.Create("^.*", @" <html> <body> <iframe src=""/frame""/><iframe src=""/frame""/> </body> </html>"), } ))); var dr = new SimpleBrowserDriver((IBrowser)b); b.Navigate("http://blah/"); var test = dr.FindElement(By.TagName("body")); Assert.That(dr.WindowHandles.Count == 3); var firstFrame = dr.SwitchTo().Frame(0); Assert.Throws<NoSuchElementException>(()=>firstFrame.FindElement(By.TagName("iframe"))); }
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"); }
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 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); }
public void ShouldSaveContact() { var browser = new SimpleBrowserDriver(); //Create user if (userMgr.GetUserByName("Wills") == null) { browser.Url = "http://localhost:54075/User/Register"; browser.FindElement(By.Id("UserName")).SendKeys("Wills"); browser.FindElement(By.Id("Password")).SendKeys("abcdef"); browser.FindElement(By.Id("ConfirmPassword")).SendKeys("abcdef"); browser.FindElement(By.Id("register")).Submit(); } else { browser.Url = "http://localhost:54075/User/LogOn"; browser.FindElement(By.Id("UserName")).SendKeys("Wills"); browser.FindElement(By.Id("Password")).SendKeys("abcdef"); browser.FindElement(By.Id("RememberMe")).Click(); browser.FindElement(By.Id("logon")).Submit(); } //Add user browser.Url = "http://localhost:54075/Contact/Create"; browser.FindElement(By.Id("Name")).SendKeys("Darth Vader"); browser.FindElement(By.Id("Address")).SendKeys("Death Star"); browser.FindElement(By.Id("create")).Submit(); //Search user-existing browser.Url = "http://localhost:54075/Contact/Search"; browser.FindElement(By.Id("SearchQuery")).SendKeys("darth vader"); browser.FindElement(By.Id("search")).Submit(); string retrieved = browser.FindElement(By.Id("result00")).Text; retrieved.Trim().Should().Be("Darth Vader"); //Search user-non existing browser.Url = "http://localhost:54075/Contact/Search"; browser.FindElement(By.Id("SearchQuery")).SendKeys("anakin"); browser.FindElement(By.Id("search")).Submit(); retrieved = browser.FindElement(By.Id("noResults")).Text; retrieved.Trim().Should().Be("No Matches....."); }
public void CtrlClick_Should_Open_Link_In_Other_Window() { var b = GetMockedBrowser(); var dr = new SimpleBrowserDriver((IBrowser)b); dr.Navigate().GoToUrl("http://www.a.com/link.htm"); Assert.That(dr.WindowHandles.Count == 1); Assert.That(dr.Url == "http://www.a.com/link.htm"); var link = dr.FindElement(By.LinkText("link")); Assert.NotNull(link); link.Click(); Assert.That(dr.Url == "http://www.a.com/otherpage.htm"); dr.Navigate().Back(); Assert.That(dr.Url == "http://www.a.com/link.htm"); link = dr.FindElement(By.LinkText("link")); Actions builder = new Actions(dr); builder.KeyDown(Keys.Control).Click(link).KeyUp(Keys.Control); var act = builder.Build(); act.Perform(); Assert.That(dr.Url == "http://www.a.com/link.htm"); Assert.That(dr.WindowHandles.Count == 2); }
public void Issue9() { SimpleBrowserDriver driver = new SimpleBrowserDriver(); driver.Navigate().GoToUrl("http://www.totaljobs.com"); var txt = driver.FindElement(By.Id("left_0_txtKeywords")); }
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 OpeningOtherWindows() { IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker( new List<Tuple<string, string>>() { Tuple.Create("^/otherpage", "<html></html>"), Tuple.Create("^.*", @" <html> <a href=""/otherpage"" target=""_blank"" id=""blanklink"">click</a> </html>"), } ))); var dr = new SimpleBrowserDriver((IBrowser)b); dr.Navigate().GoToUrl("http://blah/"); dr.FindElement(By.Id("blanklink")).Click(); Assert.That(dr.Url == "http://blah/"); Assert.That(dr.WindowHandles.Count == 2); string otherWindowName = dr.WindowHandles.First(n => n != dr.CurrentWindowHandle); var otherDr = dr.SwitchTo().Window(otherWindowName); Assert.That(otherDr.Url == "http://blah/otherpage"); // click it again will create a thrid window dr.FindElement(By.Id("blanklink")).Click(); Assert.That(dr.Url == "http://blah/"); Assert.That(dr.WindowHandles.Count == 3); }