Zee的LR脚本练习三:比较两个字符串变量

一:

以下脚本,定义两个一样的字符数组,对比后,打印出result的值:

vuser_init()
{

int result;
     char string1[] = "We can see the string:zee";
     char string2[] = "We can see the string:zee";
lr_output_message("the string1 is %s.",string1);
lr_output_message("the string2 is %s.",string2);

result = strcmp(string1,string2); 
   if ( result == 0 )
           {
        lr_output_message("the result is 0.");
        }
   else
   {
     lr_output_message("the result is not 0.");
   }

        return 0;
}

运行结果:

Starting action vuser_init.
Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788          [MsgId: MMSG-27143]
Run-Time Settings file: "C:/Documents and Settings/Zee/Local Settings/Temp/noname26//default.cfg"          [MsgId: MMSG-27141]
vuser_init.c(7): the string1 is We can see the string:zee.
vuser_init.c(8): the string2 is We can see the string:zee.
vuser_init.c(13): the result is 0.
Ending action vuser_init.
Running Vuser...

 

二:

脚本:
vuser_init()
{

int result;
char string1;
char string2;
     lr_save_string( "We can see the string:zee","string1" );
     lr_save_string( "We can see the string:zee","string2" );

lr_output_message("the string1 is %s.",lr_eval_string("{string1}"));
lr_output_message("the string2 is %s.",lr_eval_string("{string2}"));

result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string1}")); 
   if ( result == 0 )
           {
        lr_output_message("the result is 0.");
        }
   else
   {
     lr_output_message("the result is not 0.");
   }

        return 0;
}

结果:

Starting action vuser_init.
Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788          [MsgId: MMSG-27143]
Run-Time Settings file: "C:/Documents and Settings/Zee/Local Settings/Temp/noname26//default.cfg"          [MsgId: MMSG-27141]
vuser_init.c(10): the string1 is We can see the string:zee.
vuser_init.c(11): the string2 is We can see the string:zee.
vuser_init.c(16): the result is 0.
Ending action vuser_init.
Running Vuser... 

你可能感兴趣的:(String,脚本,Build,action,loadrunner,output)