私はテストチームにおり、Wordプラグインのテストを行っています。私たちはあなたのテストの前に再開するスタート・ワード・メソッドを持っています。個々のテストでうまく動作しますが、順序付けられたテストでそれらを配置すると、例外がスローされます。繰り返すUIテストのためにWordを起動する方法?
if (!Playback.IsInitialized)
{
Playback.Initialize();
}
// Launch '%ProgramFiles%\Microsoft Office\Office12\WINWORD.EXE'
ApplicationUnderTest wINWORDApplication = ApplicationUnderTest.Launch(exePath, altPath);
if (killAllPreviousWordProcesses == true)
{
wINWORDApplication.Maximized = true;
}
周りを探した後、我々はProcess.Startを(使うことを提案ポストをfoudn代わりApplicationUnderTestの):これは前に私たちが持っていたものです。これは彼らが提案したコードでした。
Process np = Process.Start(@"C:\Windows\System32\Notepad.exe");
while (np.MainWindowHandle == IntPtr.Zero)
{
System.Threading.Thread.Sleep(100);
}
//This line throws the error
WinWindow npWindow = UITestControlFactory.FromWindowHandle(np.MainWindowHandle) as WinWindow;
MessageBox.Show(npWindow.Name);
ApplicationUnderTest aut = ApplicationUnderTest.FromProcess(np);
MessageBox.Show(aut.Title);
私たちは、Wordを使用するように変更(「WINWORD」との文字列を置換し、我々はまた、パスを試してみた)が、今、我々はメソッドを実行するとNullReferenceException毎回を取得します。私はnullのすべてをチェックして、np.MainWindowHandleがゼロではないことを確認しましたが、それでもエラーが表示されます。この提案や代替提案を修正するためのアイデアはありますか?
のStackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindFromWindowHandle(IntPtr windowHandle)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl..ctor(IntPtr windowHandle)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FromWindowHandle(IntPtr windowHandle)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControlFactory.FromWindowHandle(IntPtr windowHandle)
at Common.BaseUIMapClasses.BaseUIMap.startWord(Boolean killAllPreviousWordProcesses, Boolean maximizeWord, String exePath, String altPath) in C:\Source1\Common\BaseUIMap.cs:line 170
nullreference例外をスローしますか?関連する例外行を貼り付けることができます。 – NotMe
おっと、私の悪いです。更新しました! – woolcock66
私は完全にはっきりしていませんでした。爆発すると、null参照例外が何であるかを正確に記述するスタックトレースを受け取ります。それを投稿する。 ;) – NotMe