HttpWatch自动化尝试(待整理)

HttpWatch 7.0.23 试用 商业工具

Log.Entries.Summary.Time方法,仅能用于单次记录的结果,多次会记录中间的空闲时间。

另外7.0.23版本HttpWatch Studio里TimeChart中的Network图标标注错误

主要参考软件自带的CHM格式文档 或者 http://apihelp.httpwatch.com/

 

效果不是很好,不过可以结合WatiN,另外官方提供Ruby的API,也可以结合Watir;

貌似不太好集成到Webdriver

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HttpWatch;

namespace HttpWatchTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化
            Controller control = new Controller();

            Plugin httpWatchIE = control.IE.New();
            httpWatchIE.Clear();

            httpWatchIE.Log.EnableFilter(false);

            //记录过程,i<1才能使Log.Entries.Summary.Time正确
            //for (int i = 0; i < 1; i++)
            //{
                httpWatchIE.ClearCache();
                httpWatchIE.ClearAllCookies();

                httpWatchIE.Record();
                httpWatchIE.GotoURL("http://my.oschina.net/magonglei/");
                control.WaitEx(httpWatchIE, -1, true, false, -1);
                control.Wait(httpWatchIE, -1);
                httpWatchIE.Stop();
            //}
            httpWatchIE.CloseBrowser();

            var log = httpWatchIE.Log;
            string dataTime = System.DateTime.Now.ToString("s").Replace(":", "_");
            string logPath = "D:\\" + dataTime + ".hwl";
            log.Save(logPath);
            log.ExportCSV("D:\\" + dataTime + ".csv");

            //com组件的原因,不能直接用log进行分析
            log = control.OpenLog(logPath);

            //日志分析部分
            var entries = log.Entries;
            var summary = entries.Summary;
            var TimingSummaries = summary.TimingSummaries;

            //注意Page和Entries的概念
            Console.WriteLine("log.Pages[0].Title:" + log.Pages[0].Title);
            Console.WriteLine("log.Entries[0].URL" + log.Entries[0].URL);
            Console.WriteLine("log.Entries[0].StatusCode:" + log.Entries[0].StatusCode);
            Console.WriteLine("log.Entries[0].ServerAddress" + log.Entries[0].ServerIP + ":" + log.Entries[0].ServerPort);
            Console.WriteLine("summary.BytesReceived:" + summary.BytesReceived + "Bytes");
            Console.WriteLine("summary.BytesSent:" + summary.BytesSent + "Bytes");
            Console.WriteLine("log.Entries[0].Time" + log.Entries[0].Time);

            Console.WriteLine("summary.Time:" + summary.Time);//多次会记录空闲时间,仅能单次动作

            Console.WriteLine("summary.TimingSummaries.Network.Total:" + TimingSummaries.Network.Total);
            Console.WriteLine("TimingSummaries.Receive" + summary.TimingSummaries.Receive.Total);
            Console.WriteLine("Total Time1:" + (TimingSummaries.Blocked.Total + TimingSummaries.DNSLookup.Total + TimingSummaries.Connect.Total + TimingSummaries.CacheRead.Total + TimingSummaries.Receive.Total + TimingSummaries.Send.Total + TimingSummaries.Wait.Total));
            Console.WriteLine("Total Time2:" + (TimingSummaries.Blocked.Total + TimingSummaries.Network.Total));

        }
    }
}

你可能感兴趣的:(HttpWatch自动化尝试(待整理))