在CI过程中,需要把自动化测试的日志发送到固定邮箱,默认日志目录是存储在工程下,日志名字是时间戳,不易操作,这里介绍下如何把日志设置为自定义目录和名称。

    var WorkDir, FileName, FileList, ArchivePath;
    WorkDir = "c:\\Log\\ExportedResults\\";
    FileName = WorkDir + "MyFile.mht";
    Log.SaveResultsAs(FileName, 2);
    FileList = slPacker.GetFileListFromFolder(WorkDir);
    ArchivePath = WorkDir + "CompressedResults";
    if (slPacker.Pack(FileList, WorkDir, ArchivePath))
        Log.Message("Files compressed successfully.");

查看文档SaveResultsAs方法的参数如下:

Log.SaveResultsAs(FileName, LogFormat, ExportVisualizerImages, LogScope)

FileName [in]    Required    String     
LogFormat [in]    Optional    Integer Default value: 0 (XML format)    
ExportVisualizerImages [in]    Optional    Boolean Default value: True    
LogScope [in]    Optional    Integer Default value: 0 (full test log)    
Result 

LogFormat

The format of the exported log:

Constant Value Description 
lsXML 0 (Default) XML format. The FileName parameter specifies the fully-qualified path of the XML file to be created. Additional data files and images are saved to the same folder as the XML file. Note: The LogScope parameter is ignored. 

lsHTML 1 HTML format – a web page with accompanying images, stylesheets and other data files. The FileName parameter specifies the folder to save the files. The web page name is index.htm.  
lsMHT 2 MHT file – a web page archive (web page with accompanying files packed into one file). MHT files that can be viewed in Internet Explorer, but not Chrome or Firefox. 


这样就满足要求了。

发表评论

电子邮件地址不会被公开。 必填项已用*标注