Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Created November 12, 2013 08:41
Show Gist options
  • Select an option

  • Save davidalpert/7427586 to your computer and use it in GitHub Desktop.

Select an option

Save davidalpert/7427586 to your computer and use it in GitHub Desktop.
Enhance the browser object to function like a webdriver.
//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