未来已来

WinRunner 曾经的记忆

上一篇 / 下一篇  2008-09-01 17:47:49 / 个人分类:自动化测试

    昨天在做Qtp培训发给学员资料的时候无意中找到以前的资料,记得刚参加工作的时候自动化测试就知道Rational robot,感觉工具特别好,也激起了很大的热情和兴趣,对Robot做了很多研究,当时还写了很多关于robot的文章,也曾经憧憬着做中国第一个自动化测试项目,后来加入51testing由于工作需要接触了wr,qtp,silktest等功能自动化测试工具,随着时间的推移wr robot逐渐淡出大家的视线。其实每一个工具都有自己的特点在里面,好比一个人一样有自己的风格,在不同的项目用不同的工具,只有结合起来才能发挥最大的威力,下面是一些代码例子,算是做个纪念:

1.WinRunner如何加载Dll,例子代码如下:

rc1 = reload ( "win32api", 1, 1 );
if ( rc1 != 0 )
 { tl_step ( "Error Message", FAIL, "[reload(\"win32api\")] - FAILED!"); }
else
 { tl_step ( "Status Message", PASS, "[reload(\"win32api\")] - OK"); }

public function phone_num_gen (out phone)
{
 auto x, areacode, prefix, sufix;

 x = int ( rand(GetTickCount())*1000000000000 );
 areacode = substr(x, 1 ,3);
 prefix = substr(x, 4, 3);
 sufix = substr(x, 7, 4);
 phone = "(" & areacode & ") " & prefix & "-" & sufix;
 return ( E_OK );
}

for (i = 1; i < 10; i++)
{
 phone_num_gen(num);
 printf(num);
}

rc1 = unload ( "win32api" );
if ( rc1 != 0 )
 { tl_step ( "Error Message", FAIL, "[unload(\"win32api\")] - FAILED!"); }
else
 { tl_step ( "Status Message", PASS, "[unload(\"win32api\")] - OK"); }

2.在winrunner中如何统计代码行,提供一种解决思路

public function cloc ( in fileX, inout lines_code, inout lines_blank_or_comment, inout total_LOC  )
{
 auto line;

 # Initialize variables ...
 lines_code = 0;

 file_open ( fileX, FO_MODE_READ );

 while ( file_getline( fileX, line ) == 0 )
 {
  # Blank or Coment lines ...
  if ( match( line, "[^#]" ) == 1 )
  {
   lines_blank_or_comment++;
  }
  else
  {
   lines_code++;
  }
 }

 total_LOC = lines_code + lines_blank_or_comment;

 file_close ( fileX );
}


rc1 = cloc( "C:\\Junk1\\scrīpt", LOC, BlankOrComment, TLOC );

printf ( "Total Number of lines of code: %s\r\n", LOC );
printf ( "Total Comment or blank lines in code: %s\r\n", BlankOrComment );
printf ( "Total lines in file: %s\r\n", TLOC );

3.winrunner错误处理函数

 

function CreateErrorMessageArray ( inout ErrorMsgArray[] )
{
 # Location of WinRunner scrīpt which defines the error message codes
 auto ErrorMsgFile = getenv ( "M_ROOT" )  & "\\lib\\wr_gen\\scrīpt";
 auto rc = E_OK;  # Return code for this function
 auto character;  # Store a character
 auto line;   # Store a line from file
 auto tmpline;  # Store a line with no tab or spaces
 auto counter;  # Used to strip tab and spaces out of the line
 static tmpArray[]; # Store split (  )  results

 # Delete everything in the ErrorMsgArray
 for  ( counter in ErrorMsgArray )
  delete ErrorMsgArray[counter];

 rc = file_open ( ErrorMsgFile,FO_MODE_READ );
 if  ( rc != E_OK )
  return  ( rc );

 #Parse the file looking for "public const E_"
 while ( file_getline ( ErrorMsgFile,line ) == 0 )
 {
  if  ( index(line, "public const E_") > 0 )
  {
   # Get rid of spaces and tab characters
   tmpline = "";
   for  ( counter = 1; counter <= length(line); counter++ )
   {
    character = substr ( line, counter, 1 );
    if  ( (character != " ") && (character != "\t") )
     tmpline = tmpline & character;
   }
   split  ( tmpline, tmpArray, "=" );

   # The substr ( tmpArray[2],1, length ( tmpArray[2] ) -1 ) gets rid of the trailing semicolon  ( ; )
   # The substr ( tmpArray[1], 12 ) is the error code minus the public const
   if  ( ErrorMsgArray[substr(tmpArray[2], 1, length(tmpArray[2] - 1 )  ) ] )
   {
     ErrorMsgArray[substr(tmpArray[2], 1, length(tmpArray[2] - 1) ) ] =
     ErrorMsgArray[substr(tmpArray[2], 1, length(tmpArray[2] - 1) ) ]&", "&
     substr(tmpArray[1], 12 );
   }
   else
   {
    ErrorMsgArray[substr(tmpArray[2], 1, length(tmpArray[2]) - 1) ] =
    substr(tmpArray[1], 12);
   }
  }
 }
 file_close ( ErrorMsgFile );
 return  ( E_OK );
}

function GetErrorMessage ( inout ErrorMsgArray[], in ErrorCode )
{
 return ( ErrorMsgArray[ErrorCode] );
}

 


TAG: 自动化测试

 

评分:0

我来说两句

Open Toolbar