跨平台自动化测试部署

发表于:2010-8-31 13:20

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:高蒙、张耀东、陈轶群    来源:51Testing软件测试网采编

分享:

  ●文件系统服务:内部服务,利用此服务,可以对文件系统进行操作,比如复制、删除、查看等操作。本框架中利用STAF文件系统服务,将测试用例部署到所有的测试平台,并在执行结束后,将日志文件返还特定机器,以便查阅。例如在 windows 平台下的调用语法为:

STAF local FS COPY DIRECTORY $fromDir TODIRECTORY $toDir TOMACHINE $hostname EXT $ext

  其中 $fromDir 指本地文件夹,$toDir 指远程文件夹,$hostname 指远程测试平台,$ext 指将要进行复制的文件扩展名,此处为 “pl”。

  配置文件

  脚本的执行命令和环境变量在各个平台是不同的,具有很大的差异性。为避免将这种差异硬编码到自动化脚本中,并使自动化脚本具有很好的透明性,我们采用基于 XML的配置文件覆盖多种平台的差异性。例如本框架中的配置文件如下所示。

  代码1 : 配置文件内容示例

<Monitor name="hostname" exeCmd="b:\Scripts\executeCommand.pl"  \
    log="b:\Scripts\ logfile\ " configure="b:\Scripts\configure.xml">
 <host name="turfgrass" os="win" dir="systemDirve\automation">
  <testcase value="testcase0001"/>
  <testcase value="testcase0002"/>
  <testcase value="testcase0003"/>
  <testcase value="testcase0004"/>
  <testcase value="testcase0005"/>
 </host>
 <host name="eagles" os="aix" dir="home/automation">
  <testcase value="testcase0001"/>
  <testcase value="testcase0002"/>
  <testcase value="testcase0003"/>
  <testcase value="testcase0004"/>
  <testcase value="testcase0005"/>
 </host>
<Monitor/>

  在配置文件中,指定了要执行的脚本,日志文件的存放位置,配置文件的存放位置,测试机器的操作系统类型,以及脚本要部署的具体路径。脚本在执行时首先读取 XML 文件中的重要信息,例如测试机器的平台,以便采用相对应的执行命令和查询必须的环境量。示例代码如下。

  代码2 : 读取XML代码示

use XML::Parser;
use XML::SimpleObject;

$file="configure.xml";
$parser = XML::Parser->new(ErrorContext=>2,Style=>"Tree");
$xso = XML::SimpleObject->new($parser->parsefile($file));
$monitor = $xso->child('Monitor');
$exeCmdFile = $monitor->attribute('exeCmd');
$log = $monitor->attribute('log');
$configureFile = $monitor->attribute('configure');
chomp($exeCmdFile);
chomp($log);
chomp($configureFile);

  遍历所有测试平台,查询相关信息,如果平台为 Windows 平台,还将查询 STAF 变量,获取 System Drive 的值,并构造测试平台下的路径,此路径为所要执行测试用例的存放位置。示例代码如下。

  代码3 : 遍历所有测试平台代码示例

foreach $host($monitor->children('host')){
   my $exeCmd;
   my $hostname = $host->attribute('name');
   my $os = $host->attribute('os');
   my $dir = $host->attribute('dir');
   chomp($os);
   chomp($hostname);
   chomp($dir);
   if($os =~ /win/i){
    my @systemDrive = `staf $hostname VAR GET var STAF/Env/SystemDrive`;
    chomp($systemDrive[2]);
    $dir = "$systemDrive[2]\\automation\\";
   }
}

52/5<12345>
重磅发布,2022软件测试行业现状调查报告~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号