console.writeline("moving form"); setformpropertyvalue("location", new system.drawing.point(200,200)); setformpropertyvalue("location", new system.drawing.point(500,500));
console.writeline("resizing form"); setformpropertyvalue("size", new system.drawing.size(600,600)); setformpropertyvalue("size", new system.drawing.size(300,320));
我使用 thread.sleep 方法來暫停測試自動化以確保待測試應用程序已啟動并運行。創建表示應用程序窗體類型的 type 對象之后,我使用 type.getfield 方法檢索 form 對象中指定字段(控件)的信息。然后調用 fieldinfo.gettype 方法獲得表示想要操作的控件的 type 對象。一旦擁有控件對象,我就可以像操作 form 對象那樣操作該控件對象,即獲取控件的 propertyinfo,然后調用 setvalue 方法。對于 setformpropertyvalue,需要確保所有的屬性更改都是在正確的線程中進行的。
請注意,測試自動化并不直接模擬極低水平的用戶操作。例如,自動化并不模擬對 textbox1 控件的各次擊鍵,而是直接設置 text 屬性。同樣,自動化不模擬對 combobox1 控件的點擊,而是設置 selecteditem 屬性。這是我的測試自動化系統的一個設計缺陷。要采取那種方式測試,您可以按照 john robbins 在前面提到的文章中的建議來做。
模擬用戶在文本框和 combobox 控件中鍵入顏色的操作之后,自動化會模擬點擊按鈕控件:
console.writeline("clicking button1"); invokemethod("button1_click", new object[]{null, eventargs.empty} );
console.writeline("/nclicking menu file->exit in 5 seconds . . . "); thread.sleep(3500); invokemethod("menuitem4_click", new object[] {null, new eventargs()} );
james mccaffrey 就職于 volt information sciences, inc.,負責對在 microsoft 工作的軟件工程師進行技術培訓。他參與開發多種 microsoft 產品,包括 internet explorer 和 msn search。您可以通過 [email protected] 或 [email protected] 與 james 取得聯系。