2012-05-14 125 views
1

如果我記錄要在登錄憑據中輸入對話框的操作,並在UImap1.uitests中調用此Submit()。自動生成的代碼會是這個樣子:WPF CodedUI測試:以編程方式啓動應用程序

public void Launch() 
    { 
     #region Variable Declarations 
     WpfEdit uIUsernameBoxEdit = this.UIOCC600OILoginWindow.UIUsernameBoxEdit; 
     WpfEdit uIPasswordBoxEdit = this.UIOCC600OILoginWindow.UIPasswordBoxEdit; 
     WpfButton uIOKButton = this.UIOCC600OILoginWindow.UIOKButton; 
     #endregion 

     // Type 'username' in 'usernameBox' text box 
     uIUsernameBoxEdit.Text = this.LaunchParams.UIUsernameBoxEditText; 

     // Click 'passwordBox' text box 
     Mouse.Click(uIPasswordBoxEdit, new Point(63, 13)); 

     // Type '********' in 'passwordBox' text box 
     Keyboard.SendKeys(uIPasswordBoxEdit, this.LaunchParams.UIPasswordBoxEditSendKeys, true); 

     // Click 'OK' button 
     Mouse.Click(uIOKButton, new Point(33, 14)); 
    } 

現在,如果我手動啓動在我CodedUI測試類在我的ClassInitialize decorded的方法下的應用程序如下:

 [ClassInitialize()] 
     public static void MyTestInitialize(TestContext context) 
     { 
      Process.Start(@"C:\Program Files (x86)\MyCompany\MyApp.exe"); 
      Playback.Wait(2000); 

      var uimap = new LaunchApplicationMap(); 
      var loginParams = uimap.EnterLoginCredentialsParams; 
      loginParams.UIUsernameBoxEditText = "username"; 
      loginParams.UIPasswordBoxEditSendKeys = Playback.EncryptText("password 
"); 
      uimap.Launch(); 
      Playback.Wait(5000); 
     } 

爲什麼我如下所示得到下面的空例外?

enter image description here

這也是堆棧跟蹤:

System.NullReferenceException was unhandled by user code 
    Message=Object reference not set to an instance of an object. 
    Source=Microsoft.VisualStudio.TestTools.UITest.Framework 
    StackTrace: 
     at Microsoft.VisualStudio.TestTools.UITest.Framework.UITestService.TechnologyManagerByName(String technologyName) 
     at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.ValidateSearchProperties() 
     at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal() 
     at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary() 
     at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(String propertyName, Object value) 
     at Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfEdit.set_Text(String value) 
     at UITests.UIMaps.LaunchApplicationMapClasses.LaunchApplicationMap.Launch() in C:\dev\OCC600\Source - Copy\Tests\UITests\UIMaps\LaunchApplicationMap.Designer.cs:line 44 
     at UITests.LogsViewTests.MyTestInitialize(TestContext context) in C:\dev\OCC600\Source - Copy\Tests\UITests\LogsViewTests.cs:line 70 
    InnerException: 

TIA。

回答

3

您需要初始化播放引擎以在測試方法之外使用CodedUI。該框架會自動初始化testinitalize/cleanup方法中的播放/清理,因此您不會在那裏看到它。

ClassInitialize/AssemblyInitialize發生在任何測試開始之前,因此您必須調用Playback.Initialize()。

+0

非常感謝。在這裏給我節省了一些痛苦。 –

相關問題