我有一個簡單的wpf應用程序,它有一個按鈕,可以在單擊時增加一個值。我也有一個返回最新值的函數。默認值是5.我還在testcomplete中有一個UI測試,點擊按鈕3次(所以8)。我需要調用.Net函數來獲取此值並將其斷言。以下是我的測試代碼。在TestComplete中調用UI測試實例的.Net功能
經過一番搜索,我找到了CLRbridge的細節並實現了它。但是,正如你可以在下面看到的,UI測試實例和我在這個函數中實現的實例是不同的。所以,函數返回5.
我的問題是,我如何從testcomplete加載的同一個實例調用該函數。還是我完全錯誤的方式呢?如果我嘗試了腳本和UI測試,那麼沒有任何工作。我已經嘗試了直接實例和調用appdomain,都似乎沒有工作。
注意:我明白我可以在UI控件中顯示值並驗證控件。但是,我特意嘗試了一下我們在項目中需要的更復雜的測試功能。
function Test2()
{
var Increment;
Increment = 0;
//Runs the "TCompTest" tested application.
TestedApps.TCompTest.Run();
//Clicks the 'button1' button.
Aliases.TCompTest.HwndSource_MainWindow.MainWindow.Grid.button1.ClickButton();
//Clicks the 'button1' button.
Aliases.TCompTest.HwndSource_MainWindow.MainWindow.Grid.button1.ClickButton();
//Clicks the 'button1' button.
Aliases.TCompTest.HwndSource_MainWindow.MainWindow.Grid.button1.ClickButton();
//Increment = dotNET.Incrementer.Incr1.zctor().IntValue(true);
Increment = dotNET.Incrementer.Incr1.zctor().IntValue(true);
**OR**
Increment = Sys.Process("TCompTest").AppDomain("TCompTest.exe").dotNET.Incrementer.Incr1.zctor().IntValue(true)
// if(Increment == 8)
// {//Posts an information message to the test log.
Log.Message(Increment);
// }
//Closes the 'HwndSource_MainWindow' window.
Aliases.TCompTest.HwndSource_MainWindow.Close();
}
感謝您的明確解釋。我不敢肯定我正在從一個不同的實例中獲取價值,這個價值將會吸引它自己。 Mianly因爲我無法找到訪問測試創建的實例的方法。然而,您的建議可行,因爲它是wpf,綁定會創建incr1的實例。 _XAML_是這樣的:' '。 ** Incement方法**只包裝**綁定Increment屬性**並返回值。我沒有明確地在這裏創建實例。 –
praskris
2012-02-21 13:36:37
順便說一句,我剛剛使用你的建議,我可以從MainWindow訪問Incr1實例,並可以獲取更新的值。這工作正常。我剛從MainWindow.cs中訪問DataContext對象,並將該值設置爲一個屬性並訪問它。現在它工作正常。謝謝 ! – praskris 2012-02-21 15:14:25