上次发的基于脚本驱动的自动化测试方案,在这几天的思考之后终于得到了比较满意的方案。在原来的factory模式和bridge模式的基础上又引入了singleton模式。之所以要引入singleton模式的主要原因是问了解决全局数据访问的问题。原先的方案在controlObject级别的对象竟然要跨层次的去访问AppEveriment的数据,这样导致了强耦合。这也是原来方案的最大不足。引入了singleton模式后将读取xml配置文件的工作交给了两个集合:class ControlsCollection 和 class CasesCollection。这两个对象作为全局数据存在提供各个对象对数据的查询操作。在修改方案钟,我有引入了类别属性概念,ControlAttribute  和 StepAttribute这两个基类对象,用于接口的统一访问,这样在使得有新类别加入的时候不用修改已有的接口。
在这次的修改方案中,还有一点比较重要的是我将窗体的管理使用一个单独的类来处理,由于窗体是所有控件的容器所以处理起来比较特殊,因此不便于跟其他控件一起处理,并且窗体的产生都是在操作控件之前的。我将窗体管理类命名为: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文件,
对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>
这样的的设计使得接口更清晰,更具有可维护性和可读性!

相关文章:

  • 2021-08-30
  • 2022-01-05
  • 2021-05-18
  • 2022-12-23
  • 2021-11-18
  • 2022-01-02
  • 2022-12-23
  • 2022-01-17
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案