惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - 黃偉榮

Web Project的檔案共用小技巧 IoC的中繼器:CommonServiceLocator UTF8Encoding與BOM Temporary Post Used For Theme Detection (d4b0aefa-c88e-4957-bba7-b367d1bfa042 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 寫CodedUI時如何尋找控制項的小技巧 Moles - Isolation framework for .NET(假.Net)介紹 [小技巧]Entity Framework強型別Include C#仿Oracle Decode,將ValueType對應成String - 黃偉榮 - 博客园 Visual Studio 單元測試的3種Initialize與Cleanup jQuery套件-檢查頁面的欄位是否有變更 用EventLogReader查詢特殊EventLog jQuery自製Plugin-Bind事件函式時檢查有沒有Bind過 ASP.NET MVC TempData使用心得 Visual Stuiod 自訂檔案比較合并工具 [小技巧]自動化測試時NLog的訊息輸出到測試結果中 小技巧:專案切換32與64位元組件 Linq小技巧:日期處理 Unit Test小技巧 : DateTime的Stub 解決TFS Build Asp.Net Mvc開啟MvcBuildViews後無法載入組件問題
Visual Studio 2010 Feature Packs 2之Silverlight自動化測試
黃偉榮 · 2010-11-26 · via 博客园 - 黃偉榮

在Visual Studio 2010上市沒多久後,很高興它推出了Coded UI的自動化測試,那時我的專案是跑Silverlight,要錄制時出現不支援的錯誤,只好又乖乖的自己當人工測試機,不過前幾天看到微軟推出Visual Studio 2010 Feature Packs 2套件,其中有一項功能是Create coded UI tests for Silverlight 4 applications,就興高彩烈安裝玩一翻。

NOTE:

在2010/11/23日,截筆前Visual Studio 2010 Feature Packs 2必需要MSDN Subscribers才能下載,什麼沒有MSDN Subscribers,這我也辦法,只能期待微軟把這功能加到Visual Studio 2010 SP1中,或看沒有沒人分享吧。

Visual Studio 2010 Feature Packs 2的新功能(僅介紹測試)

  • Coded UI與Test Manager的動作錄制與執行支援Silverlight。
  • Coded UI與Test Manager的動作錄制與執行支援Firefox 3.5、3.6。
  • Coded UI編輯器。

Silverlight自動化測試

要Silverlight可以自動化測試還有點麻煩,有三個條件。

  • Host只支援IE。
  • 必需要Silverlight 4.0以上。
  • 必需要加入參考Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll組件。

Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll

安裝好Visual Studio 2010 Feature Packs 2後組件的位址預設在:

C:\Program Files (x86)\Common Files\microsoft shared\VSTT\10.0\UITestExtensionPackages\SilverlightUIAutomationHelper\Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll

但專案不可以一直都掛載組件,組件的下載的流量與或安全性問題,每次要上線前都要刪除組件,或每次要測試時都加入這個組件,會很煩吧,所以可以從MSBuild下手,打開Project檔如*.csproj,打開後找到

<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper, Version=10.0.30319.381, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

加上Condition=" '$(Configuration)' == 'Debug' ",讓組件只有在Debug的模式下才被參考,Release時不會,加入後的結果如下。

<Reference Condition=" '$(Configuration)' == 'Debug' " Include="Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper, Version=10.0.30319.381, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

NOTE:

其實有點不懂為什麼MSDN中的文件How to: Set Up Your Silverlight Application for Testing,MSBuild要寫的那麼麻煩,要自訂Property,每一次切換還要打開專案檔,切換Property。

範例

下載

<Grid x:Name="LayoutRoot">
    <RadioButton Content="紅色" Height="16" Margin="12,14,22,270" Name="RBRed" Background="Red" Click="OnColorButtomClick" />
    <RadioButton Content="綠色" Height="16" Margin="12,51,22,233" Name="RBGreen" Background="Green"  Click="OnColorButtomClick" />
    <RadioButton Content="藍色" Height="16" Margin="12,32,22,252" Name="RBBlue" Background="Blue"  Click="OnColorButtomClick" />
</Grid>
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void OnColorButtomClick(object sender, RoutedEventArgs e)
    {
        this.LayoutRoot.Background = (sender as Control).Background;
    }       
}

範例很簡單只是三個RadioButton,被Click時切換背景色,錄制RadioButton的切換,選擇Silverlight中綠色的RadioButton,驗證Selected是否為真,工具的可驗證的屬性有點少,不過事實上是工具尚未支援,用Code寫幾乎所有的屬性都可以取得,可參考手工製Coded UI Test(Visual Studio 2010新的UI自動化測試)

image

圖一 選取Silverlight的Control並加入Assertion

如果沒有加入組件會出現圖二的錯誤訊息,所以改用Release模式Build,組件是沒加入的。

image

圖二 沒有加入組件的錯誤訊息

終於有編輯器了,以前錄好了想改不是改XML(誰會改阿),就是重錄,現在小變動下,可以用編輯器微調。

image

圖三 Coded UI Editor

參考

Visual Studio 2010 Feature Packs 2