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; }); }
private void SetupElementSearch(By by, out Mock <IHtmlResult> mock) { var browserMock = new Mock <IBrowser>(); mock = new Mock <IHtmlResult>(); var foundElement = new Mock <IHtmlResult>(); var elmEnumerator = new Mock <IEnumerator <IHtmlResult> >(); foundElement.Setup(h => h.TotalElementsFound).Returns(1); foundElement.Setup(h => h.GetEnumerator()).Returns(elmEnumerator.Object); elmEnumerator.Setup(e => e.Current).Returns(foundElement.Object); elmEnumerator.SetupSequence(e => e.MoveNext()).Returns(true).Returns(false); mock.Setup(h => h.TotalElementsFound).Returns(1); mock.Setup(h => h.Select(It.IsAny <string>())).Returns(foundElement.Object); mock.Setup(root => root.Select(It.IsAny <string>())).Returns(foundElement.Object); browserMock.Setup(browser => browser.Find("html", It.IsAny <object>())).Returns(mock.Object); string url = "http://testweb.tst"; SimpleBrowserDriver driver = new SimpleBrowserDriver(browserMock.Object); driver.Navigate().GoToUrl(url); driver.FindElements(by); browserMock.Verify(b => b.Navigate(url)); browserMock.Verify(b => b.Find("html", It.IsAny <object>())); }
public void FrameSwitchingUsingElementReference() { 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/"); //traverse document to init var test = dr.FindElement(By.TagName("body")); Assert.That(test.TagName == "body"); 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"); }
private IWebDriver openAppAndLogin() { IWebDriver driver = new SimpleBrowserDriver(); driver.Url = baseUrl + "/login_page.php"; FillLoginForm(driver, "username", "administrator"); FillLoginForm(driver, "password", "123"); return(driver); }
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); }
private IWebDriver OpenAppAndLogin() { IWebDriver driver = new SimpleBrowserDriver(); driver.Url = baseUrl + "/login_page.php"; driver.FindElement(By.Name("username")).SendKeys("administrator"); driver.FindElement(By.XPath("//form[@id='login-form']/fieldset/input[contains(@class,'btn')]")).Click(); driver.FindElement(By.Name("password")).SendKeys("admin"); driver.FindElement(By.XPath("//form[@id='login-form']/fieldset/input[contains(@class,'btn')]")).Click(); return(driver); }
private IWebDriver OpenAppAndLogin() { IWebDriver driver = new SimpleBrowserDriver(); driver.Url = baseUrl + "/login_page.php"; driver.FindElement(By.Name("username")).SendKeys("administrator"); driver.FindElement(By.CssSelector("input.width-40.pull-right.btn.btn-success.btn-inverse.bigger-110")).Click(); driver.FindElement(By.Name("password")).SendKeys("qwerty123"); driver.FindElement(By.CssSelector("input.width-40.pull-right.btn.btn-success.btn-inverse.bigger-110")).Click(); return(driver); }
private IWebDriver OpenAppAndLogin() { IWebDriver driver = new SimpleBrowserDriver(); driver.Url = baseUrl + "/mantisbt-2.24.0/login_page.php"; driver.FindElement(By.Id("username")).SendKeys("administrator"); driver.FindElement(By.CssSelector("input.btn")).Click(); driver.FindElement(By.Id("password")).SendKeys("root"); driver.FindElement(By.CssSelector("input.btn")).Click(); return(driver); }
private IWebDriver OpenAppAndLogin() { IWebDriver driver = new SimpleBrowserDriver(); driver.Url = baseUrl + "/login_page.php"; Type(By.Name("username"), "administrator"); driver.FindElement(By.XPath("//input[2]")).Click(); Type(By.Name("password"), "root"); driver.FindElement(By.XPath("//form[@id='login-form']/fieldset/input[3]")).Click(); return(driver); }