Example #1
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");
        }
Example #2
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");
        }