Created
November 12, 2013 08:41
-
-
Save davidalpert/7427586 to your computer and use it in GitHub Desktop.
Enhance the browser object to function like a webdriver.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Given | |
| public class EchoModule : NancyModule | |
| { | |
| public EchoModule() | |
| { | |
| Get["/form"] = ctx => | |
| { | |
| return @" | |
| <html> | |
| <head><title>form</title></head> | |
| <body> | |
| <form id=""theForm"" method=""post"" action=""/""> | |
| <input name=""username"" type=""text""/> | |
| <input type=""submit"" value=""Submit""> | |
| </form> | |
| </body> | |
| </html>"; | |
| Post["/"] = ctx => | |
| { | |
| var body = new StreamReader(this.Context.Request.Body).ReadToEnd(); | |
| return new Response | |
| { | |
| Contents = stream => | |
| { | |
| var writer = new StreamWriter(stream); | |
| writer.Write(body); | |
| writer.Flush(); | |
| } | |
| }; | |
| }; | |
| }; | |
| } | |
| } | |
| [Fact] | |
| public void Should_be_able_to_continue_with_another_request_directly() | |
| { | |
| // When | |
| const string UserName = "root"; | |
| var result = browser.Get("/form") | |
| .Then | |
| .SetValue("#theForm input['text']", UserName) | |
| .Click("#theForm input[type='submit']"); | |
| // Then | |
| result.Body.AsString().ShouldEqual("username=root"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment