View .editorconfig
# top-most EditorConfig file
root = true
# Don't use tabs for indentation.
[*]
indent_style = space
end_of_line = crlf
# CSharp code style settings:
[*.cs]
# Prefer "var" everywhere
View CaptureHttpTrafficTests.cs
[Test]
public void TestNoLargeImages_When_NavigateToHomePage()
{
_driver.Navigate().GoToUrl("https://automatetheplanet.com/");
AssertNoLargeImagesRequested();
}
private void AssertNoLargeImagesRequested()
{
View CaptureHttpTrafficTests.cs
[Test]
public void NoErrorCodes_When_NavigateToHomePage()
{
_driver.Navigate().GoToUrl("https://automatetheplanet.com/");
AssertNoErrorCodes();
}
private void AssertNoErrorCodes()
{
View CaptureHttpTrafficTests.cs
[Test]
public void FontRequestMade_When_NavigateToHomePage()
{
_driver.Navigate().GoToUrl("https://automatetheplanet.com/");
AssertRequestMade("fontawesome-webfont.woff2?v=4.7.0");
}
private void AssertRequestMade(string url)
{
View CaptureHttpTrafficTests.cs
private async Task OnResponseModifyTrafficEventHandler(object sender, SessionEventArgs e)
{
if (e.WebSession.Request.Method == "GET" || e.WebSession.Request.Method == "POST")
{
if (e.WebSession.Response.StatusCode == 200)
{
if (e.WebSession.Response.ContentType != null && e.WebSession.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
byte[] bodyBytes = await e.GetResponseBody();
await e.SetResponseBody(bodyBytes);
View CaptureHttpTrafficTests.cs
private async Task OnResponseCaptureTrafficEventHandler(object sender, SessionEventArgs e)
{
await Task.Run(
() =>
{
if (!_responsesHistory.ContainsKey(e.Id))
{
_responsesHistory.Add(e.Id, e.WebSession.Response);
}
});
View CaptureHttpTrafficTests.cs
private async Task OnRequestModifyTrafficEventHandler(object sender, SessionEventArgs e)
{
var method = e.WebSession.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH" || method == "GET"))
{
//Get/Set request body bytes
byte[] bodyBytes = await e.GetRequestBody();
await e.SetRequestBody(bodyBytes);
View CaptureHttpTrafficTests.cs
private async Task OnRequestRedirectTrafficEventHandler(object sender, SessionEventArgs e)
{
if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("logo.svg"))
{
await e.Redirect("https://automatetheplanet.com/wp-content/uploads/2016/12/homepage-img-1.svg");
}
}
View CaptureHttpTrafficTests.cs
private async Task OnRequestBlockResourceEventHandler(object sender, SessionEventArgs e)
{
if (e.WebSession.Request.RequestUri.ToString().Contains("analytics"))
{
string customBody = string.Empty;
await e.Ok(Encoding.UTF8.GetBytes(customBody));
}
}
View CaptureHttpTrafficTests.cs
private async Task OnRequestCaptureTrafficEventHandler(object sender, SessionEventArgs e)
{
await Task.Run(
() =>
{
if (!_requestsHistory.ContainsKey(e.Id))
{
_requestsHistory.Add(e.Id, e.WebSession.Request);
}
});