发布新日志

  • 数据表的添加、数据导入、数据导出

    ghx 发布于 2007-03-29 15:54:26

    测试文件名:datasheet   路径为E:\TestInstance\qtp\ForexampleTest\
    要导入的数据保存在C:\NameTickets.xls 内容为
    name tickets
    aa         1
    bb        2
    cc         3
    在导入数据前E:\TestInstance\qtp\ForexampleTest\datasheet\Default.xls有两个缺省的Sheet 分别为Global Action1均无数据
    运行如下程序:

    DataTable.AddSheet("MySheet")  '在缺省的Default.xls添加一个标单MySheet      
    DataTable.ImportSheet "C:\NameTickets.xls", 1, "MySheet"                                               ' 第二行
    DataTable.ExportSheet "E:\TestInstance\qtp\ForexampleTest\datasheet\Default.xls", 3        ' 第三行
      
    '其中第二行中的1参数 是指从文件“"C:\NameTickets.xls"的第一列开始导入数据到新建的MySheet 中
    '其中第二行中的3参数 是指讲运行过程的数据导出到文件"E:\TestInstance\qtp\ForexampleTest\datasheet\Default.xls"第三个Sheet即新建的MySheet中。
    运行完毕,则在下次打开该测试时就能看见添加了表单MySheet,并且数据已经导入。
    也可以手工打开文件 E:\TestInstance\qtp\ForexampleTest\datasheet\Default.xls来查看。
  • [原创]QTP的在txt中写日志的方法

    风过无息 发布于 2007-03-30 18:26:20

    就是为了在脚本中出现特殊情况的时候写到txt文件中方便查找。

    Public Sub WriteLineToFile(message)
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim fileSystemObj, fileSpec
    Dim currentTime
    currentDate = Date
    currentTime = Time
    testName = "log"
    Set fileSystemObj = CreateObject("scrīpting.FileSystemObject")
    fileSpec ="C:\" &testName& ".txt" 'change this according to your directory
    If Not (fileSystemObj.FileExists(filespec)) Then  
    Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)  
    logFile.WriteLine ("#######################################################################")  
    logFile.WriteLine (currentDate & currentTime & " Test: " & environment.Value("TestName") )  
    logFile.WriteLine ("#######################################################################")  
    logFile.Close  
    Set logFile = Nothing
    End If
    Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForAppending, False, True)
    logFile.WriteLine (currentDate & currentTime & " " & message)
    logFile.Close
    Set logFile = Nothing
    Set fileSystemObj = Nothing
    End Sub

我的栏目

我的存档

数据统计

  • 访问量: 3550
  • 日志数: 8
  • 建立时间: 2007-07-23
  • 更新时间: 2007-07-23

RSS订阅

Open Toolbar