Esempio n. 1
0
        public void TestNoProtoclNavigateSubmit()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.Navigate("google.com");
            browser.Navigate("google.com", null);
            browser.Navigate("google.com", null, null);
            browser.Submit("google.com");
            browser.Submit("google.com", null);
            browser.Submit("google.com", null, null);
        }
Esempio n. 2
0
        public void TestBackCache()
        {
            BrowserStandard browser = new BrowserStandard();
            IDocument       firstResponseDocument = browser.Navigate("http://google.com");

            Assert.True(firstResponseDocument == browser.Document);
            Assert.True(browser.History.Count == 1);
            browser.Navigate("https://facebook.com");
            Assert.True(browser.History.Count == 2);
            browser.Back(true);
            Assert.True(browser.History.Count == 1);
            Assert.True(browser.ForwardHistory.Count == 1);
            Assert.True(browser.Document == firstResponseDocument);
        }
Esempio n. 3
0
        public void TestClearForwardHistory()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.Navigate("http://google.com");
            Assert.True(browser.History.Count == 1);
            browser.Navigate("https://facebook.com");
            Assert.True(browser.History.Count == 2);
            browser.Back();
            Assert.True(browser.History.Count == 1);
            Assert.True(browser.ForwardHistory.Count == 1);
            browser.ClearForwardHistory();
            Assert.True(browser.ForwardHistory.Count == 0);
        }
Esempio n. 4
0
        public void TestNavigateHeadersAndData()
        {
            BrowserStandard browser = new BrowserStandard();

            Dictionary <string, string> formData = new Dictionary <string, string>();

            formData.Add("Username", "FakeUserName");
            formData.Add("Password", "FakePassword123");
            formData.Add("SecretMessage", "This is a secret message");

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("x-csrf-token", "axsd82os21");

            var response = browser.Navigate(RequestTesterRouteUri, headers, formData);

            foreach (var data in formData)
            {
                Assert.AreEqual(data.Value, response.HtmlDocument.QuerySelector("#" + data.Key).TextContent);
            }

            foreach (var header in headers)
            {
                Assert.AreEqual(header.Value, response.HtmlDocument.QuerySelector("#" + header.Key).TextContent);
            }
        }
Esempio n. 5
0
        public async Task TestSubmitFormAsync()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.Navigate("https://www.browsesharp.org/testsitesforms.html");
            Form postForm = browser.Document.Forms[0];
            Form getForm  = browser.Document.Forms[1];

            postForm.SetValue("UserName", "TestUser");
            postForm.SetValue("Password", "TestPassword");

            IDocument postResponse = await browser.SubmitFormAsync(postForm);

            dynamic postResponseJson = new JavaScriptSerializer().Deserialize <dynamic>(postResponse.Body.TextContent);

            Assert.True(postResponseJson["formData"]["UserName"] == "TestUser");
            Assert.True(postResponseJson["formData"]["Password"] == "TestPassword");

            getForm.SetValue("Message", "This is the test message");
            getForm.SetValue("Email", "*****@*****.**");
            getForm.SetValue("Rating", "3");
            IDocument getResponse = await browser.SubmitFormAsync(getForm);

            dynamic getResponseJson = new JavaScriptSerializer().Deserialize <dynamic>(getResponse.Body.TextContent);

            Assert.True(getResponseJson["query"]["Message"] == "This is the test message");
            Assert.True(getResponseJson["query"]["Email"] == "*****@*****.**");
            Assert.True(getResponseJson["query"]["Rating"] == "3");
        }
Esempio n. 6
0
        public void TestRefresh()
        {
            BrowserStandard browser           = new BrowserStandard();
            IDocument       document          = browser.Navigate("https://github.com");
            IDocument       documentRefreshed = browser.Refresh();

            Assert.True(documentRefreshed == browser.Document);
            Assert.True(documentRefreshed != document);
            IDocument secondDocument = browser.Navigate(RequestTesterRouteUri);
            IDocument thirdDocument  = browser.Navigate("https://nuget.org");

            browser.Back();
            browser.Refresh();
            Assert.True(browser.Document != secondDocument);
            Assert.True(browser.Document.Response.ResponseUri == secondDocument.Response.ResponseUri);
        }
Esempio n. 7
0
        public async Task TestBackAsync()
        {
            BrowserStandard browser = new BrowserStandard();
            IDocument       firstResponseDocument = browser.Navigate("http://google.com");

            Assert.True(firstResponseDocument == browser.Document);
            Assert.True(browser.History.Count == 1);
            browser.Navigate("https://facebook.com");
            Assert.True(browser.History.Count == 2);
            await browser.BackAsync();

            Assert.True(browser.History.Count == 1);
            Assert.True(browser.ForwardHistory.Count == 1);
            Assert.True(browser.Document != firstResponseDocument);
            Assert.True(browser.Document.Response.ResponseUri == firstResponseDocument.Response.ResponseUri);
        }
Esempio n. 8
0
        public void TestNavigate()
        {
            BrowserStandard browser = new BrowserStandard();

            var response = browser.Navigate("https://jayx239.github.io/BrowseSharpTest/");

            Assert.True(browser.Documents.Count == 1);
            Assert.True(browser.Documents[0].Scripts.Count == 7);
            foreach (var script in browser.Documents[0].Scripts)
            {
                Assert.NotNull(script.SourceUri);
                Assert.NotNull(script.JavascriptString);
            }

            Assert.True(browser.Documents[0].Styles.Count == 2);
            foreach (var style in browser.Documents[0].Styles)
            {
                Assert.True(!string.IsNullOrEmpty(style.Content));
                Assert.NotNull(style.SourceUri);
            }

            Assert.True(response.Scripts.Count == 7);
            foreach (var script in response.Scripts)
            {
                Assert.NotNull(script.SourceUri);
                Assert.NotNull(script.JavascriptString);
            }

            Assert.True(response.Styles.Count == 2);
            foreach (var style in response.Styles)
            {
                Assert.True(!string.IsNullOrEmpty(style.Content));
                Assert.NotNull(style.SourceUri);
            }
        }
Esempio n. 9
0
        public void TestStyleScrapingDisabled()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.StyleScrapingEnabled = false;
            IDocument document = browser.Navigate("https://jayx239.github.io/BrowseSharpTest/");

            Assert.True(document.Styles.Count == 0);
        }
Esempio n. 10
0
        public void TestJavascriptScrapingEnabled()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.JavascriptScrapingEnabled = true;
            IDocument document = browser.Navigate("https://jayx239.github.io/BrowseSharpTest/");

            Assert.True(document.Scripts.Count > 0);
        }
Esempio n. 11
0
        public void TestClearHistory()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.Navigate("http://google.com");
            Assert.True(browser.History.Count == 1);
            browser.ClearHistory();
            Assert.True(browser.History.Count == 0);
        }
Esempio n. 12
0
        public void TestForward()
        {
            BrowserStandard browser = new BrowserStandard();
            IDocument       firstResponseDocument = browser.Navigate("http://google.com");

            Assert.True(firstResponseDocument == browser.Document);
            Assert.True(browser.History.Count == 1);
            IDocument secondDocument = browser.Navigate("https://facebook.com");

            Assert.True(browser.History.Count == 2);
            browser.Back();
            Assert.True(browser.History.Count == 1);
            Assert.True(browser.ForwardHistory.Count == 1);
            Assert.True(browser.Document != firstResponseDocument);
            Assert.True(browser.Document.Response.ResponseUri == firstResponseDocument.Response.ResponseUri);

            browser.Forward();
            Assert.True(browser.ForwardHistory.Count == 0);
            Assert.True(browser.History.Count == 2);
            Assert.True(secondDocument.Response.ResponseUri == browser.Document.Response.ResponseUri);
        }
Esempio n. 13
0
        public async Task TestSubmitFormAsyncHeaders()
        {
            BrowserStandard browser = new BrowserStandard();

            browser.Navigate("https://www.browsesharp.org/testsitesforms.html");
            Form postForm = browser.Document.Forms[0];
            Form getForm  = browser.Document.Forms[1];

            postForm.SetValue("UserName", "TestUser");
            postForm.SetValue("Password", "TestPassword");

            Dictionary <string, string> postHeaders = new Dictionary <string, string>();

            postHeaders.Add("x-my-header", "MyHeaderValue");
            postHeaders.Add("other-header", "this is the other header");

            IDocument postResponse = await browser.SubmitFormAsync(postForm, postHeaders);

            dynamic postResponseJson = new JavaScriptSerializer().Deserialize <dynamic>(postResponse.Body.TextContent);

            Assert.True(postResponseJson["formData"]["UserName"] == "TestUser");
            Assert.True(postResponseJson["formData"]["Password"] == "TestPassword");


            Assert.True(postResponseJson["headers"]["x-my-header"] == "MyHeaderValue");
            Assert.True(postResponseJson["headers"]["other-header"] == "this is the other header");

            getForm.SetValue("Message", "This is the test message");
            getForm.SetValue("Email", "*****@*****.**");
            getForm.SetValue("Rating", "3");

            Dictionary <string, string> getHeaders = new Dictionary <string, string>();

            getHeaders.Add("get-header", "This is a get header");
            getHeaders.Add("other-header", "Other header value");
            getHeaders.Add("athirdheader", "A 3rd header");

            IDocument getResponse = await browser.SubmitFormAsync(getForm, getHeaders);

            dynamic getResponseJson = new JavaScriptSerializer().Deserialize <dynamic>(getResponse.Body.TextContent);

            Assert.True(getResponseJson["query"]["Message"] == "This is the test message");
            Assert.True(getResponseJson["query"]["Email"] == "*****@*****.**");
            Assert.True(getResponseJson["query"]["Rating"] == "3");

            Assert.True(getResponseJson["headers"]["get-header"] == "This is a get header");
            Assert.True(getResponseJson["headers"]["other-header"].ToString() == "Other header value");
            Assert.True(getResponseJson["headers"]["athirdheader"].ToString() == "A 3rd header");
        }
Esempio n. 14
0
        public void TestNavigateHeaders()
        {
            BrowserStandard browser = new BrowserStandard();

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("x-csrf-token", "axsd82os21");

            var response = browser.Navigate(RequestTesterRouteUri, headers);

            foreach (var header in headers)
            {
                Assert.AreEqual(header.Value, response.HtmlDocument.QuerySelector("#" + header.Key).TextContent);
            }
        }