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 GoingBackInTimeShouldntThrowExceptions()
        {
            var b        = GetMockedBrowser();
            var dr       = new SimpleBrowserDriver((IBrowser)b);
            var givenUrl = "http://www.a.com/";

            dr.Navigate().GoToUrl(givenUrl);
            dr.Navigate().Back();
            dr.Navigate().Back();
        }
        public void GoingForwardInTimeShouldntCallNavigateAgain()
        {
            var b        = GetMockedBrowser();
            var dr       = new SimpleBrowserDriver((IBrowser)b);
            var givenUrl = "http://www.a.com/";

            dr.Navigate().GoToUrl(givenUrl);
            b.LastRequest = null;
            dr.Navigate().Forward();

            Assert.IsNull(b.LastRequest);
        }
        public void CallingRefreshShouldNavigateAgainToSame()
        {
            var b        = GetMockedBrowser();
            var dr       = new SimpleBrowserDriver((IBrowser)b);
            var givenUrl = "http://www.a.com/";

            dr.Navigate().GoToUrl(givenUrl);
            b.LastRequest = null;

            dr.Navigate().Refresh();

            Assert.NotNull(b.LastRequest);
        }
        public void NavigatingBackwardsAfterSecondShouldNavigateToFirstUrl()
        {
            var b  = GetMockedBrowser();
            var dr = new SimpleBrowserDriver((IBrowser)b);

            string[] givenUrls = { "http://www.a.com", "http://www.b.com" };
            foreach (string url in givenUrls)
            {
                dr.Navigate().GoToUrl(url);
            }

            dr.Navigate().Back();

            Assert.That(new Uri(dr.Url), Is.EqualTo(new Uri(givenUrls[0])));
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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 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 GoingBackAndForthWithNewUrlShouldCallNavigateWithNewUrl()
        {
            var b  = GetMockedBrowser();
            var dr = new SimpleBrowserDriver((IBrowser)b);

            string[] givenUrls = { "http://www.a.com", "http://www.b.com" };
            foreach (string url in givenUrls)
            {
                dr.Navigate().GoToUrl(url);
            }
            dr.Navigate().Back();
            string newUrl = "http://www.c.com";

            dr.Navigate().GoToUrl(newUrl);

            Assert.That(b.LastRequest.Url, Is.EqualTo(new Uri(newUrl)));
        }
        public void GoingToNullUriShouldntCallNavigate()
        {
            var b  = GetMockedBrowser();
            var dr = new SimpleBrowserDriver((IBrowser)b);

            dr.Navigate().GoToUrl((Uri)null);

            Assert.IsNull(b.LastRequest);
        }
        public void GoingBackInitiallyShouldntCallNavigate()
        {
            var b  = GetMockedBrowser();
            var dr = new SimpleBrowserDriver((IBrowser)b);

            dr.Navigate().Back();

            Assert.IsNull(b.LastRequest);
        }
        public void SubmitGetForm()
        {
            Browser b = new Browser(Helper.GetAllways200RequestMocker());

            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");

            driver.Navigate().Back();
            b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.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.Contains("radios=second"), "Radio buttons not in correct state");

            b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
            form            = driver.FindElement(By.CssSelector("form"));
            firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]"));
            firstRadioLabel.Click();
            form.Submit();
            Assert.That(lastRequest.Contains("radios=first"), "Radio buttons not in correct state");

            b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.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.Contains("optionsList=opt1"), "Selectbox not in correct state");

            Assert.That(!lastRequest.Contains("submitButton=button1"), "Value of submit button should not be posted");

            b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
            form = driver.FindElement(By.CssSelector("form"));
            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 NavigatingToUrlShouldDoIt()
        {
            var b        = GetMockedBrowser();
            var dr       = new SimpleBrowserDriver((IBrowser)b);
            var givenUrl = "http://www.a.com/";

            dr.Navigate().GoToUrl(givenUrl);

            Assert.AreEqual(dr.Url, givenUrl);
            Assert.AreEqual(b.LastRequest.Url.ToString(), givenUrl);
        }
        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 Processar()
        {
            using (IWebDriver driver = new SimpleBrowserDriver())
            {
                driver.Navigate().GoToUrl("https://www.alura.com.br/");

                var html = driver.PageSource;

                driver.FindElement(By.ClassName("header__nav__link--entrar--home")).Click();

                html = driver.PageSource;

                driver.Quit();
            }
        }
Exemple #16
0
        static ExitCode DownloadAndSaveLeave(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage HolidayCalendarDownloader.exe <username> <password>");
                return(ExitCode.InvalidParameters);
            }

            var userName = args[0];
            var password = args[1];

            try
            {
                var webDriver = new SimpleBrowserDriver();
                webDriver.Navigate().GoToUrl("https://ewassist.co.uk/CC/Areas_Holidays_Cal.aspx?Token=AS&Ar=5");


                var loginForm = webDriver.FindElement(By.Name("ctl00"));
                if (loginForm != null)
                {
                    var loginElement    = webDriver.FindElement(By.Name("LoginLogin"));
                    var passwordElement = webDriver.FindElement(By.Name("LoginPassword"));
                    var loginButton     = webDriver.FindElement(By.Id("LoginButton_DoLogin"));

                    loginElement.SendKeys(userName);
                    passwordElement.SendKeys(password);

                    loginButton.Click();
                }

                CalendarParser.ParseEWAHtmlString(webDriver.PageSource).Save("Leave.xml");
                return(ExitCode.Success);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                Console.WriteLine(ex.StackTrace);
                return(ExitCode.ErrorOccured);
            }
        }
        public void Processar()
        {
            using (var driver = new SimpleBrowserDriver())
            {
                driver.Navigate().GoToUrl("https://login.yahoo.com/account/create?lang=pt-BR&done=https%3A%2F%2Fmail.yahoo.com%2F%3F.lang%3Dpt-BR%26guce_referrer%3DaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8%26guce_referrer_sig%3DAQAAAIL9JPUXgS9Z7gg7DPbuV7GdBpIr7a5av0ZzRWU61T-OLQOVNRK1kQlRyW5Gr7pKtctATO1D5r984AvglM5bjqE-UWAgNtEb_CmPmXkozHZcksEynFCuPjuy5RGk9l11YX7DQJ34lZGPS5iB5Ll3Uokc6Qvm4YQEj_NWRtCBXGby&src=ym&specId=yidReg");

                var html = driver.PageSource;

                var firstName = driver.FindElement(By.Id("usernamereg-firstName"));
                firstName.SendKeys("Roberto");

                var lastName = driver.FindElement(By.Id("usernamereg-lastName"));
                lastName.SendKeys("Patente");

                var usuarioID = driver.FindElement(By.Id("usernamereg-yid"));
                usuarioID.SendKeys("Patente2020");

                var senha = driver.FindElement(By.Id("usernamereg-password"));
                senha.SendKeys("46692201!@ASDasd");

                var telefone = driver.FindElement(By.Id("usernamereg-phone"));
                telefone.SendKeys("11958803873");

                var mesNascimento = driver.FindElement(By.Id("usernamereg-month"));
                mesNascimento.SendKeys("3");

                var diaNascimento = driver.FindElement(By.Id("usernamereg-day"));
                diaNascimento.SendKeys("26");

                var anoNascimento = driver.FindElement(By.Id("usernamereg-year"));
                anoNascimento.SendKeys("1993");

                var btnCadastrar = driver.FindElement(By.Id("reg-submit-button"));
                btnCadastrar.Click();

                html = driver.PageSource;
            }
        }