前端性能测试自动化—精通软件性能测试与LoadRunner最佳实战(15)

发表于:2013-7-17 11:00

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:于涌 王磊等    来源:51Testing软件测试网采编

# Close down IE

plugin.CloseBrowser()

puts "\r\nPress Enter to exit";  $stdout.flush

gets

# page_check_watir.rb文件

# Page Check Ruby and WATIR Example

# For more information about this example please refer to the readme.txt file in the

# same directory

#

require 'win32ole'

require 'watir' 

puts "Enter the URL of the page to check (press enter for www.httpwatch.com):\n";  $stdout. flush

url = gets.chomp!

if  url.empty? 

url = "www.httpwatch.com"

end

puts  "\nChecking " + url + "...\r\n\r\n";  $stdout.flush

# Attach HttpWatch

control = WIN32OLE.new('HttpWatch.Controller')

# Open the IE browser

plugin = control.IE.New

# Attach Watir to IE browser containing HttpWatch plugin

Watir::IE::attach_timeout = 30 

ie = Watir::IE.attach(:hwnd, plugin.Container.HWND )

# Start Recording HTTP traffic

plugin.Clear()

plugin.Log.EnableFilter(false)

plugin.Record()

# Goto to the URL and wait for the page to be loaded

ie.goto(url)

# Stop recording HTTP

plugin.Stop()

if plugin.Log.Pages.Count != 0

printf "\nPage Title: '%s'\n", plugin.Log.Pages(0).Title

# Display summary statistics for page

summary = plugin.Log.Pages(0).Entries.Summary

printf "Total time to load page (secs):      %.3f\n", summary.Time

printf "Number of bytes received on network: %d\n", summary.BytesReceived

printf "HTTP compression saving (bytes):     %d\n", summary.CompressionSavedBytes

printf "Number of round trips:               %d\n",  summary.RoundTrips

printf "Number of errors:                    %d\n", summary.Errors.Count

end

# Close down IE

plugin.CloseBrowser();

puts "\r\nPress Enter to exit";  $stdout.flush

gets

  C#源代码(pagechecker.cs文件内容):

// Page Check C# Example

// 

// For more information about this example please refer to the readme.txt file in the

// same directory

//

using System;

using HttpWatch;

namespace page_check

{

class PageChecker

{

[STAThread]

static void Main(string[] args)

{

Console.WriteLine("Enter the URL of the page to check (press enter for 

www.httpwatch.com):\r\n");

string url = Console.ReadLine();

if ( url.Length == 0 )

  url = "www.httpwatch.com";

Console.WriteLine("\r\nChecking " + url + "...\r\n");

// Create a new instance of HttpWatch in IE

Controller control = new Controller();

             Plugin plugin = control.IE.New();

// Start Recording HTTP traffic

plugin.Log.EnableFilter(false);

plugin.Record();

// Goto to the URL and wait for the page to be loaded

plugin.GotoURL(url);

control.Wait(plugin, -1);

// Stop recording HTTP

plugin.Stop();

if (plugin.Log.Pages.Count != 0)

{

Console.WriteLine("\r\nPage Title: '" + plugin.Log.Pages[0].Title + "'");

Console.WriteLine();

// Display summary statistics for page

Summary summary = plugin.Log.Pages[0].Entries.Summary;

Console.WriteLine("Total time to load page (secs):      " + summary.Time);

Console.WriteLine("Number of bytes received on network: " + 

summary.BytesReceived);

Console.WriteLine("HTTP compression saving (bytes):     " +

summary.CompressionSavedBytes);

Console.WriteLine("Number of round trips:               " + 

summary.RoundTrips);

Console.WriteLine("Number of errors:                    " + 

summary.Errors.Count);

}

42/4<1234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号