public void TestNavigateHeadersAndData()
        {
            StandardCore browser = new StandardCore();

            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);
            }
        }
        public void TestNavigate()
        {
            StandardCore browser = new StandardCore();

            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);
            }
        }
        public async Task TestSubmitFormAsync()
        {
            StandardCore browser = new StandardCore();

            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");
        }
Example #4
0
 public BrowserThreadFail()
 {
     _restClient     = new RestClient();
     _history        = new HistoryManager();
     _browser        = new StandardCore(new JavascriptEngine(), new StyleEngine(), _restClient, new CookieContainer(), _history, false, false, "http");
     _sleepAmount    = 5000;
     _asyncSemaphore = new SemaphoreSlim(1, 1);
 }
        public async Task TestStyleScrapingDisabledAsync()
        {
            StandardCore browser = new StandardCore();

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

            Assert.True(document.Styles.Count == 0);
        }
        public void TestStyleScrapingEnabled()
        {
            StandardCore browser = new StandardCore();

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

            Assert.True(document.Styles.Count > 0);
        }
        public async Task TestJavascriptScrapingEnabledAsync()
        {
            StandardCore browser = new StandardCore();

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

            Assert.True(document.Scripts.Count > 0);
        }
        public void TestJavascriptScrapingDisabled()
        {
            StandardCore browser = new StandardCore();

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

            Assert.True(document.Scripts.Count == 0);
        }
        public void TestNoProtoclNavigateSubmit()
        {
            StandardCore browser = new StandardCore();

            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);
        }
        public void TestNavigateHeaders()
        {
            StandardCore browser = new StandardCore();

            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);
            }
        }
        public async Task TestNoProtoclNavigateSubmitAsync()
        {
            StandardCore browser = new StandardCore();
            await browser.NavigateAsync("google.com");

            await browser.NavigateAsync("google.com", null);

            await browser.NavigateAsync("google.com", null, null);

            await browser.SubmitAsync("google.com");

            await browser.SubmitAsync("google.com", null);

            await browser.SubmitAsync("google.com", null, null);
        }
        public async Task TestSubmitFormAsyncHeaders()
        {
            StandardCore browser = new StandardCore();

            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"].ToString() == "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");
        }
        public async Task TestSubmitAsync()
        {
            StandardCore browser = new StandardCore();

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

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

            var response = await browser.SubmitAsync("https://www.hashemian.com/tools/form-post-tester.php", formData);

            Assert.True(response.Response.Content.Contains("Username=FakeUserName"));
            Assert.True(response.Response.Content.Contains("Password=FakePassword123"));
            Assert.True(response.Response.Content.Contains("SecretMessage=This%20is%20a%20secret%20message"));

            var response2 = browser.Documents[0];

            Assert.True(response2.Response.Content.Contains("Username=FakeUserName"));
            Assert.True(response2.Response.Content.Contains("Password=FakePassword123"));
            Assert.True(response2.Response.Content.Contains("SecretMessage=This%20is%20a%20secret%20message"));
        }
Example #14
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public Browser() : base()
 {
     _browserStandard = new StandardCore(base.JavascriptEngine, base.StyleEngine, _restClient, _restClient.CookieContainer, _history, base.StyleScrapingEnabled, base.JavascriptScrapingEnabled, DefaultUriProtocol);
     _browserTyped    = new TypedCore(base.JavascriptEngine, base.StyleEngine, _restClient, _restClient.CookieContainer, _history, base.StyleScrapingEnabled, base.JavascriptScrapingEnabled, DefaultUriProtocol);
 }