针对Silverlight 4的UI自动化测试
针对Silverlight 4的UI自动化测试
目前Visual Studio 2010 SP1也早已发布,我们只需要在此基础上装Feature Pack 2补丁包,便可通过Coded UI Test来录制Silverlight 4的UI界面了,并Playback你的测试用例了。注意,Feature Pack2的用处是在被测试机器(MUT)打的补丁。当然你在所有机器上都装也不会有什么问题。
这里我们有一个DLL文件需要注意:Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll
这个DLL是用来帮助Coded UI Test识别Silverlight 4的UI控件的,注意它是被Silverlight程序引用,而不是Test Project,很多朋友起初容易混淆。
以下为BrowserWindow的录制结果:
[GeneratedCode("Coded UITest Builder", "10.0.40219.1")]
public class UISilverlightApplicatiWindow : BrowserWindow
{
public UISilverlightApplicatiWindow()
{
#region Search Criteria
this.SearchProperties[UITestControl.PropertyNames.Name] = "SilverlightApplication1";
this.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
this.WindowTitles.Add("SilverlightApplication1");
#endregion
}
public void LaunchUrl(System.Uri url)
{
this.CopyFrom(BrowserWindow.Launch(url));
}
#region Properties
public UISilverlightApplicatiDocument UISilverlightApplicatiDocument
{
get
{
if ((this.mUISilverlightApplicatiDocument == null))
{
this.mUISilverlightApplicatiDocument = new UISilverlightApplicatiDocument(this);
}
return this.mUISilverlightApplicatiDocument;
}
}
#endregion
#region Fields
private UISilverlightApplicatiDocument mUISilverlightApplicatiDocument;
#endregion
}
public class UISilverlightApplicatiWindow : BrowserWindow
{
public UISilverlightApplicatiWindow()
{
#region Search Criteria
this.SearchProperties[UITestControl.PropertyNames.Name] = "SilverlightApplication1";
this.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
this.WindowTitles.Add("SilverlightApplication1");
#endregion
}
public void LaunchUrl(System.Uri url)
{
this.CopyFrom(BrowserWindow.Launch(url));
}
#region Properties
public UISilverlightApplicatiDocument UISilverlightApplicatiDocument
{
get
{
if ((this.mUISilverlightApplicatiDocument == null))
{
this.mUISilverlightApplicatiDocument = new UISilverlightApplicatiDocument(this);
}
return this.mUISilverlightApplicatiDocument;
}
}
#endregion
#region Fields
private UISilverlightApplicatiDocument mUISilverlightApplicatiDocument;
#endregion
}
以下为HtmlDocument录制结果:
[GeneratedCode("Coded UITest Builder", "10.0.40219.1")]
public class UISilverlightApplicatiDocument : HtmlDocument
{
public UISilverlightApplicatiDocument(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
this.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
this.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
this.FilterProperties[HtmlDocument.PropertyNames.Title] = "SilverlightApplication1";
this.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/WebSite2/SilverlightApplication1TestPage.html";
this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://localhost:24805/WebSite2/SilverlightApplication1TestPage.html";
this.WindowTitles.Add("SilverlightApplication1");
#endregion
}
#region Properties
public UISilverlightControlHoPane UISilverlightControlHoPane
{
get
{
if ((this.mUISilverlightControlHoPane == null))
{
this.mUISilverlightControlHoPane = new UISilverlightControlHoPane(this);
}
return this.mUISilverlightControlHoPane;
}
}
#endregion
#region Fields
private UISilverlightControlHoPane mUISilverlightControlHoPane;
#endregion
}
public class UISilverlightApplicatiDocument : HtmlDocument
{
public UISilverlightApplicatiDocument(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
this.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
this.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
this.FilterProperties[HtmlDocument.PropertyNames.Title] = "SilverlightApplication1";
this.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/WebSite2/SilverlightApplication1TestPage.html";
this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://localhost:24805/WebSite2/SilverlightApplication1TestPage.html";
this.WindowTitles.Add("SilverlightApplication1");
#endregion
}
#region Properties
public UISilverlightControlHoPane UISilverlightControlHoPane
{
get
{
if ((this.mUISilverlightControlHoPane == null))
{
this.mUISilverlightControlHoPane = new UISilverlightControlHoPane(this);
}
return this.mUISilverlightControlHoPane;
}
}
#endregion
#region Fields
private UISilverlightControlHoPane mUISilverlightControlHoPane;
#endregion
}
Silverlight的MainPage录制结果:
[GeneratedCode("Coded UITest Builder", "10.0.40219.1")]
public class UIMainPageMainPage : SilverlightControl
{
public UIMainPageMainPage(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[UITestControl.PropertyNames.ControlType] = "MainPage";
this.WindowTitles.Add("SilverlightApplication1");
#endregion
}
#region Properties
public SilverlightText UITextBlockText
{
get
{
if ((this.mUITextBlockText == null))
{
this.mUITextBlockText = new SilverlightText(this);
#region Search Criteria
this.mUITextBlockText.SearchProperties[SilverlightText.PropertyNames.AutomationId] = "textBlock1";
this.mUITextBlockText.WindowTitles.Add("SilverlightApplication1");
#endregion
}
return this.mUITextBlockText;
}
}
#endregion
#region Fields
private SilverlightText mUITextBlockText;
#endregion
}
public class UIMainPageMainPage : SilverlightControl
{
public UIMainPageMainPage(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[UITestControl.PropertyNames.ControlType] = "MainPage";
this.WindowTitles.Add("SilverlightApplication1");
#endregion
}
#region Properties
public SilverlightText UITextBlockText
{
get
{
if ((this.mUITextBlockText == null))
{
this.mUITextBlockText = new SilverlightText(this);
#region Search Criteria
this.mUITextBlockText.SearchProperties[SilverlightText.PropertyNames.AutomationId] = "textBlock1";
this.mUITextBlockText.WindowTitles.Add("SilverlightApplication1");
#endregion
}
return this.mUITextBlockText;
}
}
#endregion
#region Fields
private SilverlightText mUITextBlockText;
#endregion
}
另外:
但是这里有一个问题,如果作为数据挖掘的蜘蛛爬虫来说,如果数据源网站用silverlight做,但没有引用Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll ,那么无论是数据抓取还是Coded UI Test,都无能为力了!!!
可有高手解决此问题?
标签:
Silverlight 4
, Coded UI Test
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库