GUI Automation真的值得嗎? Part III


A layer below the GUI
http://blogs.msdn.com/alanpa/archive/2008/09/20/a-layer-below-the-gui.aspx

接續上一篇Part II, 作者發憤圖強寫了一些例子來解釋他的本意, 這裡的說明和我在

測試程式架構的重要性: 看Commerical UI automation tool的演進
http://www.wretch.cc/blog/kojenchieh/12819459

中要表達的重點有異曲同工之妙, 大家可以交互參考兩邊的例子.

I wanted to expand on the main point of my last post – specifically on what a “layer below the GUI” means. All I mean is – don’t write automation that interacts with the GUI directly – instead, write automation that tests using an object model, or another method of testing the logic under the UI.

作者認為GUI test automation不是直接操作 GUI上面的東西, 像是button, edit control等等, 比如

button_press("Next");
type_text("My Name");
button_press("Next");

Or this c# code:

Process wordApp = Process.Start("Winword.exe");
if (wordApp.WaitForInputIdle(1000))
{
    SendKeys.SendWait("This is input to WinWord");
    SendKeys.SendWait("^a"); // send ctrl+a (select all text)
    SendKeys.SendWait("^b"); // send ctrl + b (make text bold)
}

他認為像這樣的code就是浪費時間, 因為這樣的東西會一變再變, 而且看不出你要測試的scenario是什麼.

不過有些系統, 它是有所謂object model,  像是Office 就有提供, 可利用VBA or COm的方式來使用. 例如

Object template = Type.Missing;
Object newTemplate = Type.Missing;
Object docType = Type.Missing;
Object visible = Type.Missing;

Word.Application wordApp = new Word.Application();
Word.Document wordDoc = new Word.Document();
wordApp.Visible = true;
// the following line is equivalent to selecting File, and then New
// to create a new document based on Normal.dot.
wordDoc = wordApp.Documents.Add(ref template, ref newTemplate,
                                ref docType, ref visible);

wordDoc.Selection.TypeText(“This is input to WinWord”);
wordDoc.Selection.WholeStory();
wordDoc.Selection.Font.Bold = 1;

這樣就比上一個範例好很多, 因為你可以跑在任何版本的Word, 不會因為Word UI改版, 你的test script就需要全部翻掉, (當然interpret這些script的底層會需要做修改) 而且也看的出你要測試的scenario是什麼

所以作者再次強調
1. 如果能做UI層下的automation, 就先做它
2. 如果有UI的object model, 就先用它
3. 如果都沒有, 可能manual test UI會比較好

否則這些GUI automation要maintain 會是件很辛苦的事. 尤其在不同版本之間, 你會有一堆test script要維護, 或是一堆script languages or tools要學.

不知各位看倌, 同意他的說法嗎?

arrow
arrow
    全站熱搜

    kojenchieh 發表在 痞客邦 留言(1) 人氣()