Esempio n. 1
0
        public void CanSetAlertHandler()
        {
            var webClient = new WebClient(BrowserVersion.FIREFOX_38);

            List collectedAlerts = new ArrayList();
            var alertHandler = new CollectingAlertHandler(collectedAlerts);
            webClient.AlertHandler = alertHandler;
        }
Esempio n. 2
0
        public void test1()
        {
            NHtmlUnit.WebClient driver = null;
            driver = new NHtmlUnit.WebClient(BrowserVersion.INTERNET_EXPLORER_11);
            driver.Options.JavaScriptEnabled           = true;
            driver.Options.ThrowExceptionOnScriptError = false;
            driver.Options.ActiveXNative = true;
            driver.Options.CssEnabled    = true;
            HtmlPage page = driver.GetHtmlPage("https://www.expedia.com/");

            Assert.AreEqual("Google", page.TitleText);
        }
Esempio n. 3
0
        public void GetFirstByXPath_ReturnsWrappedObject()
        {
            var webClient = new WebClient(BrowserVersion.FIREFOX_38);

            webClient.Options.JavaScriptEnabled = false;
            webClient.Options.ActiveXNative = false;
            webClient.Options.CssEnabled = false;

            var page = webClient.GetHtmlPage("http://wikipedia.org");
            var anchor = page.GetFirstByXPath("//a");

            Assert.That(anchor, Is.TypeOf<HtmlAnchor>());
        }
Esempio n. 4
0
        public void test1()
        {
            NHtmlUnit.WebClient driver = null;
            driver = new NHtmlUnit.WebClient(BrowserVersion.INTERNET_EXPLORER_11);
            driver.Options.JavaScriptEnabled           = true;
            driver.Options.ThrowExceptionOnScriptError = false;
            driver.Options.ActiveXNative = true;
            driver.Options.CssEnabled    = true;
            HtmlPage page = driver.GetHtmlPage("https://www.expedia.com/");

            Thread.Sleep(5000);
            var sp = page.GetFirstByXPath("//*[@id=\"tab - hotel - tab - hp\"]/span[2]");

            Assert.AreEqual("Google", page.TitleText);
        }
Esempio n. 5
0
        public Dictionary <string, string> fetchAnimeList()
        {
            List <string> htmlStringList = new List <string>();

            htmlStringList.Add("http://damedesuyo.com/?page_id=1815");
            htmlStringList.Add("http://damedesuyo.com/?page_id=6757");
            htmlStringList.Add("http://damedesuyo.com/?page_id=2153");
            htmlStringList.Add("http://damedesuyo.com/?page_id=2151");

            List <Tuple <string, string> > tempAnimeList   = new List <Tuple <string, string> >();
            Dictionary <string, string>    animeDictionary = new Dictionary <string, string>();

            Parallel.ForEach(htmlStringList, htmlUrl =>
            {
                WebClient webClient = new WebClient(BrowserVersion.CHROME)
                {
                    JavaScriptEnabled                 = false,
                    ThrowExceptionOnScriptError       = false,
                    ThrowExceptionOnFailingStatusCode = false,
                    CssEnabled = false,
                };

                HtmlPage Page = (HtmlPage)webClient.GetPage(htmlUrl);

                string htmlPage = WebUtility.HtmlDecode(Page.WebResponse.ContentAsString);

                if (!String.IsNullOrEmpty(htmlPage))
                {
                    htmlPage       = htmlPage.Replace(@"\r\n", "");
                    string pattern = "<div id=\"show\">(\\n|\\r|\\r\\n)<div id=\"staff\">(\\n|\\r|\\r\\n)<h2><a href=[\\s\\S].*><img class=[\\s\\S].* /></a><br />(\\n|\\r|\\r\\n)(?<title>.*?)</h2>(\\n|\\r|\\r\\n)<p><strong>Status:</strong> <a href=\".*?\">.*?</a>;(.*?)<a href=\"(?<url>.*?)\" target=\"_blank\">";

                    MatchCollection m = Regex.Matches(htmlPage, pattern, RegexOptions.Multiline);

                    foreach (Match match in m)
                    {
                        animeDictionary.Add(match.Groups["title"].Value, match.Groups["url"].Value);
                    }
                }
            });

            return(animeDictionary);
        }
Esempio n. 6
0
        public Dictionary<string, string> fetchAnimeList()
        {
            List<string> htmlStringList = new List<string>();

            htmlStringList.Add("http://damedesuyo.com/?page_id=1815");
            htmlStringList.Add("http://damedesuyo.com/?page_id=6757");
            htmlStringList.Add("http://damedesuyo.com/?page_id=2153");
            htmlStringList.Add("http://damedesuyo.com/?page_id=2151");

            List<Tuple<string, string>> tempAnimeList = new List<Tuple<string, string>>();
            Dictionary<string, string> animeDictionary = new Dictionary<string, string>();

            Parallel.ForEach(htmlStringList, htmlUrl =>
            {
                WebClient webClient = new WebClient(BrowserVersion.CHROME)
                {
                    JavaScriptEnabled = false,
                    ThrowExceptionOnScriptError = false,
                    ThrowExceptionOnFailingStatusCode = false,
                    CssEnabled = false,
                };

                HtmlPage Page = (HtmlPage)webClient.GetPage(htmlUrl);

                string htmlPage = WebUtility.HtmlDecode(Page.WebResponse.ContentAsString);

                if (!String.IsNullOrEmpty(htmlPage))
                {
                    htmlPage = htmlPage.Replace(@"\r\n", "");
                    string pattern = "<div id=\"show\">(\\n|\\r|\\r\\n)<div id=\"staff\">(\\n|\\r|\\r\\n)<h2><a href=[\\s\\S].*><img class=[\\s\\S].* /></a><br />(\\n|\\r|\\r\\n)(?<title>.*?)</h2>(\\n|\\r|\\r\\n)<p><strong>Status:</strong> <a href=\".*?\">.*?</a>;(.*?)<a href=\"(?<url>.*?)\" target=\"_blank\">";

                    MatchCollection m = Regex.Matches(htmlPage, pattern, RegexOptions.Multiline);

                    foreach (Match match in m)
                    {
                        animeDictionary.Add(match.Groups["title"].Value, match.Groups["url"].Value);
                    }
                }
            });

            return animeDictionary;
        }
        public void DoWikipediaSearch()
        {
            // Note that this test works against live wikipedia.org and requires an active Internet connection
            WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6)
            {
                JavaScriptEnabled = true,
                ActiveXNative = true,
                CssEnabled = true,
            };

            HtmlPage page = webClient.GetHtmlPage("http://wikipedia.org");

            HtmlInput queryInputElement = page.GetElementById<HtmlInput>("searchInput");
            queryInputElement.Type("network");

            HtmlSubmitInput submitButton2 =
                page.HtmlElementDescendants
                    .OfType<HtmlSubmitInput>()
                    .First(e => e.NameAttribute == "go");

            submitButton2.Click();

            HtmlElement submitButton = page.GetElementByName("go");

            HtmlPage nextPage = submitButton.Click<HtmlPage>();

            // Check whether enumeration works (at least that it doesnt crash)
            foreach (var child in nextPage.Body.HtmlElementDescendants)
                Console.WriteLine(child.TreeDepth + ": Child in enumerator is " + child);

            int i = 0;

            // Check whether list wrapper works
            foreach (var child in nextPage.Forms)
            {
                Console.WriteLine(child);
                Assert.AreEqual(child, nextPage.Forms[i]);
                i++;
            }
        }
Esempio n. 8
0
        public void DoWikipediaSearch()
        {
            // Note that this test works against live wikipedia.org and requires an active Internet connection
            var webClient = new WebClient(BrowserVersion.FIREFOX_38);

            webClient.Options.JavaScriptEnabled = false;
            webClient.Options.ActiveXNative = true;
            webClient.Options.CssEnabled = true;

            var page = webClient.GetHtmlPage("http://wikipedia.org");

            page.GetElementById<HtmlInput>("searchInput").Type("network");

            var searchButton = page.HtmlElementDescendants
                .OfType<HtmlButton>()
                .First(b => b.TypeAttribute == "submit");

            searchButton.Click();

            var submitButton = page.GetElementByName("go") as HtmlElement;

            var nextPage = submitButton.Click<HtmlPage>();

            // Check whether enumeration works (at least that it doesnt crash)
            foreach (var child in nextPage.Body.HtmlElementDescendants)
                Console.WriteLine(child.TreeDepth + ": Child in enumerator is " + child);

            var i = 0;

            // Check whether list wrapper works
            foreach (var child in nextPage.Forms)
            {
                Console.WriteLine(child);
                Assert.AreEqual(child, nextPage.Forms[i]);
                i++;
            }
        }
Esempio n. 9
0
        public void CheckWebAuthFlow()
        {
            var url         = Common.FormatAuthorizeUrl(ResponseTypes.Code, _clientId, HttpUtility.UrlEncode(_callbackUrl));
            var expectedUrl = string.Format("https://login.uber.com/oauth/authorize?response_type=code&client_id={0}&redirect_uri={1}", _clientId, HttpUtility.UrlEncode(_callbackUrl));

            Assert.AreEqual(url, expectedUrl);

            var webClient = new WebClient(BrowserVersion.FIREFOX_17);

            webClient.Options.ThrowExceptionOnScriptError = false;

            webClient.Options.JavaScriptEnabled = true;
            webClient.Options.RedirectEnabled   = true;
            webClient.Options.ActiveXNative     = false;
            webClient.Options.CssEnabled        = true;

            // ########################################
            // # Uber login page
            // ########################################

            var loginPage = webClient.GetHtmlPage(url);

            Assert.IsNotNull(loginPage);

            var loginPageText = loginPage.AsText();

            StringAssert.Contains("sign in", loginPageText.toLowerCase());
            StringAssert.Contains("connect with facebook", loginPageText.toLowerCase());
            StringAssert.Contains("don't have an account", loginPageText.toLowerCase());
            StringAssert.Contains("email", loginPageText.toLowerCase());
            StringAssert.Contains("password", loginPageText.toLowerCase());

            var signInSpan = (HtmlSpan)loginPage.GetElementsByTagName("span")[0];

            Assert.AreEqual(signInSpan.AsText(), "Sign In");

            var emailInputElement = (HtmlTextInput)loginPage.GetElementByName("email");

            Assert.IsNotNull(emailInputElement, "email");

            emailInputElement.SetValueAttribute(_userName);
            Assert.AreEqual(emailInputElement.Text, _userName);

            var passwordInputElement = (HtmlPasswordInput)loginPage.GetElementByName("password");

            Assert.IsNotNull(passwordInputElement, "password");

            passwordInputElement.SetValueAttribute(_password);
            Assert.AreEqual(passwordInputElement.Text, _password);

            var loginForm = (HtmlForm)loginPage.GetElementsByTagName("form")[0];

            Assert.IsNotNull(loginForm);

            var loginFormText = loginForm.AsText();

            StringAssert.Contains("sign in", loginFormText.toLowerCase());
            StringAssert.Contains("connect with facebook", loginFormText.toLowerCase());
            StringAssert.Contains("email", loginFormText.toLowerCase());
            StringAssert.Contains("password", loginFormText.toLowerCase());

            var loginFormButtons = loginForm.GetElementsByTagName("button");

            Assert.IsNotNull(loginFormButtons);

            var loginButton = (HtmlButton)loginFormButtons.First();

            Assert.IsNotNull(loginButton);

            var loginButtonText = loginButton.AsText();

            StringAssert.Contains("sign in", loginButtonText.toLowerCase());

            // ########################################
            // # Uber consent page
            // ########################################

            var consentPage = (HtmlPage)loginButton.Click();

            Assert.IsNotNull(consentPage);

            IPage callbackPage;

            // check if previously consented
            if (!consentPage.Url.ToString().contains(string.Format("{0}?code=", _callbackUrl)))
            {
                var consentPageUrl = consentPage.Url.ToString();
                Assert.IsNotNullOrEmpty(consentPageUrl);

                var consentPageText = consentPage.AsText();
                StringAssert.Contains("access to your full name", consentPageText.toLowerCase());

                var consentPageButtons = consentPage.GetElementsByTagName("button");
                Assert.IsNotNull(consentPageButtons);

                var noAllowButton = (HtmlButton)consentPageButtons[0];
                Assert.IsNotNull(noAllowButton);
                Assert.AreEqual("Deny", noAllowButton.AsText());

                var allowButton = (HtmlButton)consentPageButtons[1];
                Assert.IsNotNull(allowButton);
                Assert.AreEqual("Allow", allowButton.AsText());

                callbackPage = allowButton.Click();
                Assert.IsNotNull(callbackPage);
            }
            else
            {
                callbackPage = consentPage;
            }

            // ########################################
            // # Callback page
            // ########################################

            var page3Url = callbackPage.Url.ToString();

            Assert.IsNotNullOrEmpty(page3Url);
            StringAssert.Contains(string.Format("{0}?code=", _callbackUrl), page3Url);

            var queryCollection = HttpUtility.ParseQueryString(page3Url);
            var code            = queryCollection[0];

            var auth = new AuthenticationClient();

            auth.WebServerAsync(_clientId, _clientSecret, _callbackUrl, code).Wait();

            Assert.IsNotNull(auth);
            Assert.IsNotNullOrEmpty(auth.AccessToken);
        }
Esempio n. 10
0
        public void CheckWebAuthFlow()
        {
            var url = Common.FormatAuthorizeUrl(ResponseTypes.Code, _clientId, HttpUtility.UrlEncode(_callbackUrl));
            var expectedUrl = string.Format("https://login.uber.com/oauth/authorize?response_type=code&client_id={0}&redirect_uri={1}", _clientId, HttpUtility.UrlEncode(_callbackUrl));

            Assert.AreEqual(url, expectedUrl);

            var webClient = new WebClient(BrowserVersion.FIREFOX_17);

            webClient.Options.ThrowExceptionOnScriptError = false;

            webClient.Options.JavaScriptEnabled = true;
            webClient.Options.RedirectEnabled = true;
            webClient.Options.ActiveXNative = false;
            webClient.Options.CssEnabled = true; 

            // ########################################
            // # Uber login page
            // ########################################

            var loginPage = webClient.GetHtmlPage(url);
            Assert.IsNotNull(loginPage);

            var loginPageText = loginPage.AsText();

            StringAssert.Contains("sign in", loginPageText.toLowerCase());
            StringAssert.Contains("connect with facebook", loginPageText.toLowerCase());
            StringAssert.Contains("don't have an account", loginPageText.toLowerCase());
            StringAssert.Contains("email", loginPageText.toLowerCase());
            StringAssert.Contains("password", loginPageText.toLowerCase());

            var signInSpan = (HtmlSpan)loginPage.GetElementsByTagName("span")[0];
            Assert.AreEqual(signInSpan.AsText(), "Sign In");

            var emailInputElement = (HtmlTextInput)loginPage.GetElementByName("email");
            Assert.IsNotNull(emailInputElement, "email");

            emailInputElement.SetValueAttribute(_userName);
            Assert.AreEqual(emailInputElement.Text, _userName);

            var passwordInputElement = (HtmlPasswordInput)loginPage.GetElementByName("password");
            Assert.IsNotNull(passwordInputElement, "password");

            passwordInputElement.SetValueAttribute(_password);
            Assert.AreEqual(passwordInputElement.Text, _password);

            var loginForm = (HtmlForm)loginPage.GetElementsByTagName("form")[0];
            Assert.IsNotNull(loginForm);

            var loginFormText = loginForm.AsText();

            StringAssert.Contains("sign in", loginFormText.toLowerCase());
            StringAssert.Contains("connect with facebook", loginFormText.toLowerCase());
            StringAssert.Contains("email", loginFormText.toLowerCase());
            StringAssert.Contains("password", loginFormText.toLowerCase());

            var loginFormButtons = loginForm.GetElementsByTagName("button");
            Assert.IsNotNull(loginFormButtons);

            var loginButton = (HtmlButton)loginFormButtons.First();
            Assert.IsNotNull(loginButton);

            var loginButtonText = loginButton.AsText();
            StringAssert.Contains("sign in", loginButtonText.toLowerCase());

            // ########################################
            // # Uber consent page
            // ########################################

            var consentPage = (HtmlPage)loginButton.Click();
            Assert.IsNotNull(consentPage);

            IPage callbackPage;

            // check if previously consented
            if (!consentPage.Url.ToString().contains(string.Format("{0}?code=", _callbackUrl)))
            {
                var consentPageUrl = consentPage.Url.ToString();
                Assert.IsNotNullOrEmpty(consentPageUrl);

                var consentPageText = consentPage.AsText();
                StringAssert.Contains("access to your full name", consentPageText.toLowerCase());

                var consentPageButtons = consentPage.GetElementsByTagName("button");
                Assert.IsNotNull(consentPageButtons);

                var noAllowButton = (HtmlButton)consentPageButtons[0];
                Assert.IsNotNull(noAllowButton);
                Assert.AreEqual("Deny", noAllowButton.AsText());

                var allowButton = (HtmlButton)consentPageButtons[1];
                Assert.IsNotNull(allowButton);
                Assert.AreEqual("Allow", allowButton.AsText());

                callbackPage = allowButton.Click();
                Assert.IsNotNull(callbackPage);
            }
            else
            {
                callbackPage = consentPage;
            }

            // ########################################
            // # Callback page
            // ########################################
            
            var page3Url = callbackPage.Url.ToString();
            Assert.IsNotNullOrEmpty(page3Url);
            StringAssert.Contains(string.Format("{0}?code=", _callbackUrl), page3Url);

            var queryCollection = HttpUtility.ParseQueryString(page3Url);
            var code = queryCollection[0];

            var auth = new AuthenticationClient();
            auth.WebServerAsync(_clientId, _clientSecret, _callbackUrl, code).Wait();

            Assert.IsNotNull(auth);
            Assert.IsNotNullOrEmpty(auth.AccessToken);
        }