在这次的修改方案中,还有一点比较重要的是我将窗体的管理使用一个单独的类来处理,由于窗体是所有控件的容器所以处理起来比较特殊,因此不便于跟其他控件一起处理,并且窗体的产生都是在操作控件之前的。我将窗体管理类命名为:WinManager 它主要完成如下工作:
/// <summary>
/// singleton pattern
/// this class can do the jobs
/// 1) Collect the opened window of the application
/// 2) Remove the all of window of the application
/// 3) Get the window by FormAttribute
/// </summary>
并且在这次的修改方案中对整个测试脚本的xml文件格式也进行了比较大的修改,主要是原先的脚本内容和字段命名多比较的含糊。
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
< App >
< ExcludedControls >
< Control id = " MainMenu " />
</ ExcludedControls >
< Case title = " testWordPadSetting " savePath = " . " >
< Script driver = " Monad " />
< Control id = " View " action = " click " owner = " MainMenu " />
< Control id = " Options " action = " click " owner = " MainMenu " waiter = " Options " />
< Control id = " OK " action = " click " waiter = " MainForm " />
< Control id = " RichEdit " action = " sendKeys " value = " Hello World! " />
< Control id = " RichEdit " action = " sendKeys " value = " ^a " />
< Control id = " FontComboBox " action = " SelectedIndex " value = " 16 " owner = " Formatting " />
< UICapture title = " myScreenShot " rootControlId = "" />
</ Case >
</ App >
这是case文件,
< App >
< ExcludedControls >
< Control id = " MainMenu " />
</ ExcludedControls >
< Case title = " testWordPadSetting " savePath = " . " >
< Script driver = " Monad " />
< Control id = " View " action = " click " owner = " MainMenu " />
< Control id = " Options " action = " click " owner = " MainMenu " waiter = " Options " />
< Control id = " OK " action = " click " waiter = " MainForm " />
< Control id = " RichEdit " action = " sendKeys " value = " Hello World! " />
< Control id = " RichEdit " action = " sendKeys " value = " ^a " />
< Control id = " FontComboBox " action = " SelectedIndex " value = " 16 " owner = " Formatting " />
< UICapture title = " myScreenShot " rootControlId = "" />
</ Case >
</ App >
对Controls.xml文件也进行了规范化, 让它只支持三个字段的访问,automationId, className和name
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
< Application name = " WordPad.exe " >
< Form refName = " MainForm " class = " WordPadClass " >
< Control refName = " Formatting " id = " 59396 " controlType = " ToolBar " />
< Control refName = " Standard " id = " 59392 " controlType = " ToolBar " />
< Control refName = " RichEdit " id = " 59648 " controlType = " Document " />
< Control refName = " MainMenu " id = " MenuBar " controlType = " MenuBar " />
< Control refName = " FontComboBox " id = " 165 " controlType = " ComboBox " />
< Control refName = " FontDropDownButton " id = " DropDown " controlType = " Button " />
< Control refName = " FontListBox " id = " ListBox " controlType = " List " />
</ Form >
< Form refName = " Options " class = " #32770 " >
< Control refName = " OK " id = " 1 " controlType = " Button " />
< Control refName = " NoWarp " id = " 1027 " controlType = " RadioButton " />
</ Form >
</ Application >
这样的的设计使得接口更清晰,更具有可维护性和可读性!
< Application name = " WordPad.exe " >
< Form refName = " MainForm " class = " WordPadClass " >
< Control refName = " Formatting " id = " 59396 " controlType = " ToolBar " />
< Control refName = " Standard " id = " 59392 " controlType = " ToolBar " />
< Control refName = " RichEdit " id = " 59648 " controlType = " Document " />
< Control refName = " MainMenu " id = " MenuBar " controlType = " MenuBar " />
< Control refName = " FontComboBox " id = " 165 " controlType = " ComboBox " />
< Control refName = " FontDropDownButton " id = " DropDown " controlType = " Button " />
< Control refName = " FontListBox " id = " ListBox " controlType = " List " />
</ Form >
< Form refName = " Options " class = " #32770 " >
< Control refName = " OK " id = " 1 " controlType = " Button " />
< Control refName = " NoWarp " id = " 1027 " controlType = " RadioButton " />
</ Form >
</ Application >