// navigate to url
instance.ActiveTab.Navigate("http://lessons.zennolab.com");
// get list of requests
var traffic = instance.ActiveTab.GetTraffic();
// print count of items, it will be more than 0
project.SendInfoToLog("First count of traffic elements = " + traffic.Count());
// get some data from items and log it
foreach(var t in traffic)
project.SendInfoToLog(string.Format("Url: {0}\r\n Method: {1}\r\n Result: {2}", t.Url, t.Method, t.ResultCode));
// get list of request second time
traffic = instance.ActiveTab.GetTraffic();
// print count of items, it will be 0, because the previous method call removed the old items
project.SendInfoToLog("Second count of traffic elements = " + traffic.Count());
// navigate to url
instance.ActiveTab.Navigate("http://lessons.zennolab.com");
// get reqest by urls filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"}).ToList();
project.SendInfoToLog("Request by urls filter:");
foreach(var t in traffic)
project.SendInfoToLog("Url: " + t.Url);
// result collection must has one item
if (traffic.Count != 1)
throw new Exception("Traffic collection count != 1");
// this item must match the filter collection
if (traffic[0].Url != "http://lessons.zennolab.com/main.css")
throw new Exception("Traffic item url != http://lessons.zennolab.com/main.css");
// RequestHeaders and other additional fields must be null while instance.UseTrafficMonitoring == false
if (!string.IsNullOrWhiteSpace(traffic[0].RequestHeaders))
throw new Exception("Instance.UseTrafficMonitoring (false) is not working, value = " + instance.UseTrafficMonitoring);
// get list of request second time, second result list must be empty
traffic = instance.ActiveTab.GetTraffic().ToList();
if (traffic.Count != 0)
throw new Exception("Second traffic collection count != 0");
// enable additional traffic monitoring
instance.UseTrafficMonitoring = true;
// navigate to url
instance.ActiveTab.Navigate("http://lessons.zennolab.com");
// get list of requests by urls filter collection and headers filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"}, new [] { "image/png" }).ToList();
project.SendInfoToLog("Request by urls filter collection and headers filter collection:");
foreach(var t in traffic)
project.SendInfoToLog("Url: " + t.Url);
// result collection must has two item, first match url regex, second match header regex
if (traffic.Count != 2)
throw new Exception("Traffic collection count != 2");
// all items must contains RequestHeaders and other fields, because instance.UseTrafficMonitoring == true
if (traffic.Any(t => string.IsNullOrWhiteSpace(t.RequestHeaders)))
throw new Exception("Instance.UseTrafficMonitoring (true) is not working, value = " + instance.UseTrafficMonitoring);
// get list of request second time, second result list must be empty
traffic = instance.ActiveTab.GetTraffic().ToList();
if (traffic.Count != 0)
throw new Exception("Second traffic collection count != 0");
// navigate to url
instance.ActiveTab.Navigate("http://lessons.zennolab.com");
// get list of requests by urls, headers and body filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"}, new [] { "image/png" }, new [] { "DOCTYPE HTML PUBLIC" }).ToList();
project.SendInfoToLog("Request by urls filter collection and headers filter collection:");
foreach(var t in traffic)
project.SendInfoToLog("Url: " + t.Url);
// result collection must has three item
if (traffic.Count != 3)
throw new Exception("Traffic collection count != 3");
// all items must contains RequestHeaders and other fields, because instance.UseTrafficMonitoring == true
if (traffic.Any(t => string.IsNullOrWhiteSpace(t.RequestHeaders)))
throw new Exception("Instance.UseTrafficMonitoring (true) is not working, value = " + instance.UseTrafficMonitoring);
// get list of request second time, second result list must be empty
traffic = instance.ActiveTab.GetTraffic().ToList();
if (traffic.Count != 0)
throw new Exception("Second traffic collection count != 0");