Exemple #1
0
        public async Task TestSubmitFormAsync()
        {
            BrowserTyped browser = new BrowserTyped();

            browser.Navigate <dynamic>("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 <Request> postResponse = await browser.SubmitFormAsync <Request>(postForm);

            Request postResponseJson = postResponse.Data;

            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 <Request> getResponse = await browser.SubmitFormAsync <Request>(getForm);

            Request getResponseJson = getResponse.Data;

            Assert.True(getResponseJson.Query["Message"] == "This is the test message");
            Assert.True(getResponseJson.Query["Email"] == "*****@*****.**");
            Assert.True(getResponseJson.Query["Rating"] == "3");
        }
Exemple #2
0
        public async Task TestSubmitFormAsyncHeaders()
        {
            BrowserTyped browser = new BrowserTyped();

            browser.Navigate <dynamic>("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 <Request> postResponse = await browser.SubmitFormAsync <Request>(postForm, postHeaders);

            Request postResponseJson = postResponse.Data;

            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 <Request> getResponse = await browser.SubmitFormAsync <Request>(getForm, getHeaders);

            dynamic getResponseJson = getResponse.Data;

            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"] == "Other header value");
            Assert.True(getResponseJson.Headers["athirdheader"] == "A 3rd header");
        }