• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 用UIAutomation做驗收測試

    發表于:2009-06-17來源:作者:點擊數: 標簽:驗收UIAutomation
    這是被測的應用程序: 應用.NET 3.0提供的UIAutomation,我們可以用以下步驟來進行 測試 : 1. 啟動應用程序 C#代碼 string path=@ "ThePathToTheApplication" ; Processprocess=Process.Start(path); string path = @"The Path To The Application";Process
    這是被測的應用程序:




    應用.NET 3.0提供的UIAutomation,我們可以用以下步驟來進行測試

    1. 啟動應用程序

    C#代碼 復制代碼
    1. string path = @"The Path To The Application";   
    2. Process process = Process.Start(path);  


    2. 獲得主窗口對應的AutomationElement

    C#代碼 復制代碼
    1. Thread.Sleep(1000);   
    2. AutomationElement aeMainWindow = AutomationElement.FromHandle(process.MainWindowHandle);  


    3. 獲得按鈕對應的AutomationElement

    C#代碼 復制代碼
    1. AutomationElement aeHelloButton = aeMainWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));  


    4. 點擊按鈕

    此處的GetCurrentPattern相當于Query Interface,Pattern也是UIAutomation的精髓所在。給不同的UI框架做不同的adapter,實現各種各樣的pattern,也就是建立了一個概念上的大一統UI。

    C#代碼 復制代碼
    1. InvokePattern ipHelloButton = (InvokePattern) aeHelloButton.GetCurrentPattern(InvokePattern.Pattern);   
    2. ipHelloButton.Invoke();  


    5. 獲得文本框對應的AutomationElement

    C#代碼 復制代碼
    1. AutomationElement aeHelloTextBox = aeMainWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));  


    6. 取得文本框中的文本

    C#代碼 復制代碼
    1. TextPattern tpHelloTextBox = (TextPattern) aeHelloTextBox.GetCurrentPattern(TextPattern.Pattern);   
    2. string text = tpHelloTextBox.DocumentRange.GetText(-1);  


    7. 監聽窗口被關閉事件

    C#代碼 復制代碼
    1. Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, aeMainWindow, TreeScope.Element, HandleMainWindowClose);   
    2. private static void HandleMainWindowClose(object sender, AutomationEventArgs e)   
    3. {   
    4.   Console.WriteLine("Main Window Closed");   
    5. }  


    8. 關閉窗口

    C#代碼 復制代碼
    1. process.Kill();  


    此時控制臺上就會打印出"Main Window Closed"

    整個過程演示了三個主要功能:
    1、如何主動去操縱界面(點擊按鈕)
    2、如何取得界面的狀態(獲得文本)
    3、如何監聽界面的事件(關閉窗口事件)

    結論:
    UIAutomation可以給Win32, WindowsForms, WPF編寫的應用程序撰寫驗收測試。

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>