ZennoLab Assemblies Documentation
GetTraffic Method
Example 
ZennoLab.CommandCenter Namespace > Tab Class : GetTraffic Method

Type: System.Collections.IEnumerable

Collection of regexs to filter traffic by url contents. If traffic item match any of regexs, it will put to result.

Type: System.Collections.IEnumerable

Collection of regexs to filter traffic by request or response header contents. If traffic item match any of regexs, it will put to result.

Type: System.Collections.IEnumerable

Collection of regexs to filter traffic by request or response body contents. If traffic item match any of regexs, it will put to result.

Returns collection of requests for current tab.
Syntax

Parameters

urlFilters

Type: System.Collections.IEnumerable

Collection of regexs to filter traffic by url contents. If traffic item match any of regexs, it will put to result.

headerFilters

Type: System.Collections.IEnumerable

Collection of regexs to filter traffic by request or response header contents. If traffic item match any of regexs, it will put to result.

bodyFilters

Type: System.Collections.IEnumerable

Collection of regexs to filter traffic by request or response body contents. If traffic item match any of regexs, it will put to result.

Return Value

Type: System.Collections.IEnumerable

Collection of requests.

Example
The following code example demonstrates uses of the GetTraffic method.
instance.SetContentPolicy("BlockList", new []{ "mc.yandex.ru" }, null);
instance.UseTrafficMonitoring = false;
Tab tab = instance.ActiveTab;
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// 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.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// get reqest by urls filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"});
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(t => !t.IsBlocked) != 1)
    throw new Exception("Traffic collection count != 1");
// this item must match the filter collection
if (traffic.First().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.First().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(t => !t.IsBlocked) != 0)
	throw new Exception("Second traffic collection count != 0");
            
// enable additional traffic monitoring
instance.UseTrafficMonitoring = true;
            
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// 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" });
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(t => !t.IsBlocked) != 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(t => !t.IsBlocked) != 0)
    throw new Exception("Second traffic collection count != 0");
            
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// 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" });
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(t => !t.IsBlocked) != 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(t => !t.IsBlocked) != 0)
    throw new Exception("Second traffic collection count != 0");
Requirements

Target Platforms: Desktop: Windows XP SP3 and older. Server: Windows Server 2003 and older.

See Also

Reference

Tab Class
Tab Members
UseTrafficMonitoring Method