发布新日志

  • 使用xml实现Select Case方法

    2008-06-06 16:44:01

    当select case方法写的很大了,而且在今后的维护中还要往里加入新的相似内容,可以考虑把这样的方法准换到xml文件中维护。下面是个小例子。

    1、select case实现的一个小功能,代码如下:

    Dim Color, MyVar
    Function ChangeBackground (Color)
       MyVar = lcase (Color)
       Select Case MyVar
          Case "red"     Call Red()
          Case "green"   Call Green()
          Case "blue"    Call Blue()
       End Select
    End Function

    Function Red()
       msgbox "red"
    End Function

    Function Green()
       msgbox "green"
    End Function

    Function Blue()
       msgbox "blue"
    End Function

    2、xml实现上面的方法
    Dim Color, MyVar
    Function ChangeBackground(Color)
          MyVar = lcase (Color)
          Dim xmlDoc,xmlRoot,xmlColor
          Set xmlDoc = CreateObject("Microsoft.XMLDOM") '创建XML DOM对象
          xmlDoc.async = False '控制加载模式为同步模式(xml树加载完毕后再执行后续代码)
          xmlDoc.load "d:\SelectCase.xml" 'strXmlFilePath'载入xml文件
          Set xmlRoot = xmlDoc.documentElement
          Set xmlColor = xmlRoot.selectNodes(MyVar)  '选择的颜色
          cmd = xmlColor(0).selectSingleNode("CallFunction").text
          Execute cmd
          Set xmlColor = Nothing
          Set xmlRoot = Nothing
          Set xmlDoc = Nothing
    End Function


    Function Red()
       msgbox "red"
    End Function

    Function Green()
       msgbox "green"
    End Function

    Function Blue()
       msgbox "blue"
    End Function

    3、xml文件定义如下
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <Red>
    <CallFunction>Call Red()</CallFunction>
    </Red>
    <Green>
    <CallFunction>Call Green()</CallFunction>
    </Green>
    <Blue>
    <CallFunction>Call Blue()</CallFunction>
    </Blue>
    </root>
  • xp下禁用、启用网卡

    2008-06-05 19:52:59

    使用 DevCon
    下载地址:http://support.microsoft.com/kb/311272/zh-cn
    下载后解压,里面包含2个文件夹,一个是32位,一个是64位,将适合自己操作系统的devcon.exe放入system32系统目录。
    1、查看所有PCI网卡的ID
      devcon find =net pci\*
    2、指定网卡,注意:ID从第1个字符到&字符即可。
      devcon disable =net PCI\ID  禁用网卡
      devcon enable =net  PCI\ID 启用网卡
    3、与qtp结合使用,能够实现自动断网的测试用例。
      Dim wsh
      Set wsh=createobject("wscrīpt.shell")
      wsh.Run "devcon disable =net PCI\VEN_14E4" '禁用网卡
      wsh.Run "devcon enable =net PCI\VEN_14E4"  '启用网卡
      Set wsh=Nothing
    4、所有网卡
      devcon disable =net
      devcon enable =net
  • qtp测试webservice参数化办法

    2008-05-29 16:05:55

    当测试的方法的参数是一个对象时,如何对对象的参数参数化呢。

    sTemplateXML = XMLWarehouse("UT")
    sTemplateXML = Replace(sTemplateXML, "%acount%", "rs000@sogou.com")
    sTemplateXML = Replace(sTemplateXML, "%password%", "22222222")
    logIn = WebService("AgentService").logIn(sTemplateXML)

    msgbox logIn '预期为成功

    其中UT如下:
    <UT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webparam.ws.*.*.com">
      <account>%account%</account>
      <password>%password%</password>
    </UT>
  • qtp取出WinListView中对象及子对象的属性

    2008-04-02 11:07:05

        昨天一位朋友问我如何取到搜狗音乐盒播放列表中歌曲的属性,我做了个小试验,将一些函数组合起来用,能够方便的取出WinListView中元素及子元素的属性。以下代码调试通过。

    ReDim Columns(10)
    Set ōbj = Window("搜狗音乐盒").WinListView("SysListView32")
    cColumns = Obj.ColumnCount()
    For iColumn = 0 To cColumns - 1
     Columns(iColumn) = Obj.GetColumnHeader(iColumn)
    Next
    cItems = Obj.GetItemsCount
    For iItems = 0 To cItems - 1
     str ="第 "&iItems+1&" 首歌曲属性列表"& vbCr
     For iColumn =0 To cColumns - 1
       str = str &Columns(iColumn)&" = "& Obj.GetSubItem(iItems ,Columns(iColumn)) & vbCr
     Next
     Msgbox str
    Next
    Set ōbj = nothing


    重要函数介绍:
    ColumnCount函数:Returns the number of columns in a (report-style) list-view control. -----返回list-view有多少栏位
    GetColumnHeader函数:Returns the text header of the specified (report-style) list-view column.-----返回list-view的栏位名
    GetItemsCount函数:Returns the number of items in the combo box list.-----返回list中元素个数
    GetSubItem函数:Returns the text value of a (report-style) list-view sub-item. -------返回list中子元素的栏位值

我的栏目

数据统计

  • 访问量: 5144
  • 日志数: 7
  • 图片数: 1
  • 建立时间: 2008-04-01
  • 更新时间: 2008-06-06

RSS订阅

Open Toolbar