架构人生

针对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 4UI控件的,注意它是被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
    }
复制代码

以下为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
    }
复制代码

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
    }
复制代码

另外:

但是这里有一个问题,如果作为数据挖掘的蜘蛛爬虫来说,如果数据源网站用silverlight做,但没有引用Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll ,那么无论是数据抓取还是Coded UI Test,都无能为力了!!!

可有高手解决此问题?

posted on   智艾悦  阅读(1691)  评论(1编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
< 2011年5月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11

导航

统计

点击右上角即可分享
微信分享提示