|
 |
RSS 源 : |
simonguest.com |
 |
投递时间: |
2007年12月6日星期四 12:15 |
 |
作 者: |
smguest |
 |
主 题: |
请勿打扰! |
|
 |
整篇文章链接:http://simonguest.com/blogs/smguest/archive/2007/12/05/Do-Not-Disturb_2100_.aspx |
|
|
和许多人一样,我在家里也使用VOIP - 我现在的提供商是Vonage。Vonage的其中一个特点是,它是一个国际虚拟号码。它可以分配给我一个英国的本地号码,我的家人可以拨打这个号码,它将自动重定向到我在美国家里的电话号码。这样可以相对便宜一些(每个月4.99美元),而且我的朋友和家人在联系我的时候也相当方便。 |
|
|
拥有这个国际虚拟号码的缺点是,人们有可能会不小心拨错号码 - 一旦他们拨错号码,由于时区不同(太平洋标准时间与格林尼治标准时间相差了8个小时),就可能会比较麻烦了。这周我就接到了3、4个拨错号码的电话,而且都是在凌晨两点钟接到的。如果你想睡个好觉的话,那这可不太妙。 |
|
|
Vonage有一个功能,叫做“请勿打扰”,可以将电话重定向到语音信箱 - 这个功能可以通过他们的网页激活。这个功能非常简单,但是我经常会忘,因此在睡觉前启用这个功能(以及在起床后禁用它)成为了一件烦心事。为了解决这个问题,我决定试试“Web应用程序测试”,看看我能否使用Visual Studio 2008来编写一个自动化的Web测试,来登录到Vonage的网站,并为我激活或取消这个功能。首先,我在VS2008中创建了一个新的测试项目,并从“测试”菜单中添加了一个新的Web测试。然后,我将记录整个启用“请勿打扰”功能的动作: |
|
 |
|
|
我可以将整个请求页面简化为三个请求(一个是登录,一个是查询电话号码,还有一个是设置功能),并验证了它在IDE当中也是可用的。然后,我复制这个测试来创建另外一个测试,用来重新启用这个功能。(我觉得还有另外一种向Web测试传递参数的更好的方法,但是还没有想出来)。这个测试按如下的方式运行: |
|
|
第一个请求是一个HTTP POST,它将向网站提交我的Vonage用户名和密码: |
|
|
<Request
Method="POST" Version="1.1" Url="https://secure.vonage.com/vonage-web/public/login.htm"
ThinkTime="6" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True"
Cache="False" ResponseTimeGoal="0"
Encoding="Windows-1252" ExpectedHttpStatusCode="0"
ExpectedResponseUrl="https://secure.vonage.com/vonage-web/dashboard/index.htm">
<FormPostHttpBody>
<FormPostParameter
Name="countryURLs" Value="http://www.vonage.com" RecordedValue="http://www.vonage.com"
CorrelationBinding="" UrlEncode="True"
/>
<FormPostParameter
Name="username" Value="USERNAME" RecordedValue="USERNAME"
CorrelationBinding="" UrlEncode="True"
/>
<FormPostParameter
Name="password" Value="PASSWORD" RecordedValue="PASSWORD"
CorrelationBinding="" UrlEncode="True"
/>
<FormPostParameter
Name="submit.x" Value="30" RecordedValue="30" CorrelationBinding=""
UrlEncode="True" />
<FormPostParameter
Name="submit.y" Value="13" RecordedValue="13" CorrelationBinding=""
UrlEncode="True" />
</FormPostHttpBody>
</Request> |
|
|
第二个请求(这次是一个HTTP GET),将来到“请勿打扰”功能的页面。在这里需要填写一个电话号码作为表单的参数,用来在下一个请求中使用: |
|
|
<Request
Method="GET" Version="1.1" Url="https://secure.vonage.com/vonage-web/features/DoNotDisturb/edit.htm"
ThinkTime="4" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True"
Cache="False" ResponseTimeGoal="0"
Encoding="iso-8859-1" ExpectedHttpStatusCode="0"
ExpectedResponseUrl="">
<ExtractionRules>
<ExtractionRule
Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractHiddenFields,
Microsoft.VisualStudio.QualityTools.WebTestFramework,
Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" VariableName="1"
DisplayName="Extract Hidden Fields"
Description="Extract all hidden fields from the response and place them
into the test context.">
<RuleParameters>
<RuleParameter
Name="Required" Value="True" />
<RuleParameter
Name="HtmlDecode" Value="True"
/>
</RuleParameters>
</ExtractionRule>
</ExtractionRules>
<CorrelationExtractionRules>
<ExtractionRule
Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractFormField,
Microsoft.VisualStudio.QualityTools.WebTestFramework,
Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" VariableName="FormPostParam1.on"
DisplayName=""
Description="">
<RuleParameters>
<RuleParameter
Name="Name" Value="on" />
<RuleParameter
Name="HtmlDecode" Value="True"
/>
<RuleParameter
Name="Required" Value="False" />
</RuleParameters>
</ExtractionRule>
</CorrelationExtractionRules>
<QueryStringParameters>
<QueryStringParameter
Name="did" Value="PHONENUM" RecordedValue="PHONENUM"
CorrelationBinding="" UrlEncode="False"
UseToGroupResults="False" />
<QueryStringParameter
Name="dndButton"
Value="Configure" RecordedValue="Configure"
CorrelationBinding="" UrlEncode="False"
UseToGroupResults="False" />
</QueryStringParameters>
</Request> |
|
|
第三个请求是一个HTTP POST,它将根据“on”参数的值来将“请勿打扰”的功能打开或关闭: |
|
|
<Request
Method="POST" Version="1.1" Url="https://secure.vonage.com/vonage-web/features/DoNotDisturb/edit.htm"
ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True"
Cache="False" ResponseTimeGoal="0"
Encoding="iso-8859-1" ExpectedHttpStatusCode="0"
ExpectedResponseUrl=https://secure.vonage.com/vonage-web/features/DoNotDisturb/edit.htm?did=PHONENUM&success=true&settings=com.vonage.service.feature.DndSettingsDTO+%7BphoneNumber%3DPHONENUM%2C+isOn%3Dtrue%7D>
<FormPostHttpBody>
<FormPostParameter
Name="on" Value="True" RecordedValue="true"
CorrelationBinding="{{FormPostParam1.on}}"
UrlEncode="True" />
<FormPostParameter
Name="phoneNumber"
Value="{{$HIDDEN1.phoneNumber}}" RecordedValue="PHONENUM"
CorrelationBinding="" UrlEncode="True"
/>
</FormPostHttpBody>
</Request> |
|
|
在测试完成后,我写了两个批处理文件(DNDOn.bat和DNDOff.bat),并在里面调用Web测试的命令行工具。使用MSTest.exe,可以在IDE外面运行Web测试: |
|
|
set VSINSTALLDIR=C:\Program
Files\Microsoft Visual Studio 9.0
"%VSINSTALLDIR%\Common7\IDE\MSTest.exe" /noresults
/testcontainer:bin\debug\DNDOn.webtest |
|
|
在测试批处理文件可以正常使用后,我只需要添加一个新的计划任务(在Vista当中,可以从开始菜单中键入“任务计划”来找到它),在晚上10点钟的时候运行DNDOn.bat文件,并在早上7点钟的时候运行DNDOff.bat。 |
|
 |
|
|
(顺便说一下,这也是我第一次使用Vista当中的任务计划功能。有两点让我非常吃惊:1. 它创建一个新任务非常简单(我以前在NT4上创建备份的批处理文件时可吃了不少苦头!)。 2. 在Vista当中可以使用非常多的任务 - 我需要花些时间来学习它们都是干什么用的!) |
|
|
... 这样就可以了!我可以将这个快速的解决方案部署到家里的服务器上,免得以后深更半夜再有打错电话的。 |
|
|
如果你希望试一试,可以从这里下载我的测试文件。当然,你需要将USERNAME、PASSWORD和PHONENUM(10位数字,记住要包括1)替换成你的账户的值。 |
|
|
>> 查看文章 |